]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/traits.rs
Generalized AtomicRmwBinOp for BuilderMethods
[rust.git] / src / librustc_codegen_llvm / traits.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use llvm::{AtomicOrdering, SynchronizationScope, AsmDialect};
12 use common::*;
13 use type_::Type;
14 use libc::c_char;
15 use rustc::ty::TyCtxt;
16 use rustc::ty::layout::{Align, Size};
17 use rustc::session::Session;
18 use builder::MemFlags;
19 use value::Value;
20
21 use std::borrow::Cow;
22 use std::ops::Range;
23
24 pub struct OperandBundleDef<'a, Value : 'a> {
25     pub name: &'a str,
26     pub val: Value
27 }
28
29 impl OperandBundleDef<'ll, &'ll Value> {
30     pub fn new(name: &'ll str, val: &'ll Value) -> Self {
31         OperandBundleDef {
32             name,
33             val
34         }
35     }
36 }
37
38 pub enum IntPredicate {
39     IntEQ,
40     IntNE,
41     IntUGT,
42     IntUGE,
43     IntULT,
44     IntULE,
45     IntSGT,
46     IntSGE,
47     IntSLT,
48     IntSLE
49 }
50
51 #[allow(dead_code)]
52 pub enum RealPredicate {
53     RealPredicateFalse,
54     RealOEQ,
55     RealOGT,
56     RealOGE,
57     RealOLT,
58     RealOLE,
59     RealONE,
60     RealORD,
61     RealUNO,
62     RealUEQ,
63     RealUGT,
64     RealUGE,
65     RealULT,
66     RealULE,
67     RealUNE,
68     RealPredicateTrue
69 }
70
71 pub enum AtomicRmwBinOp {
72     AtomicXchg,
73     AtomicAdd,
74     AtomicSub,
75     AtomicAnd,
76     AtomicNand,
77     AtomicOr,
78     AtomicXor,
79     AtomicMax,
80     AtomicMin,
81     AtomicUMax,
82     AtomicUMin
83 }
84
85 pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll,
86     Value : ?Sized,
87     BasicBlock: ?Sized
88     > {
89
90     fn new_block<'b>(
91         cx: &'a CodegenCx<'ll, 'tcx, &'ll Value>,
92         llfn: &'ll Value,
93         name: &'b str
94     ) -> Self;
95     fn with_cx(cx: &'a CodegenCx<'ll, 'tcx, &'ll Value>) -> Self;
96     fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
97     fn sess(&self) -> &Session;
98     fn cx(&self) -> &'a CodegenCx<'ll, 'tcx, &'ll Value>;
99     fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
100     fn llfn(&self) -> &'ll Value;
101     fn llbb(&self) -> &'ll BasicBlock;
102     fn count_insn(&self, category: &str);
103
104     fn set_value_name(&self, value: &'ll Value, name: &str);
105     fn position_at_end(&self, llbb: &'ll BasicBlock);
106     fn position_at_start(&self, llbb: &'ll BasicBlock);
107     fn ret_void(&self);
108     fn ret(&self, v: &'ll Value);
109     fn br(&self, dest: &'ll BasicBlock);
110     fn cond_br(
111         &self,
112         cond: &'ll Value,
113         then_llbb: &'ll BasicBlock,
114         else_llbb: &'ll BasicBlock,
115     );
116     fn switch(
117         &self,
118         v: &'ll Value,
119         else_llbb: &'ll BasicBlock,
120         num_cases: usize,
121     ) -> &'ll Value;
122     fn invoke(
123         &self,
124         llfn: &'ll Value,
125         args: &[&'ll Value],
126         then: &'ll BasicBlock,
127         catch: &'ll BasicBlock,
128         bundle: Option<&OperandBundleDef<'ll, &'ll Value>>
129     ) -> &'ll Value;
130     fn unreachable(&self);
131     fn add(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
132     fn fadd(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
133     fn fadd_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
134     fn sub(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
135     fn fsub(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
136     fn fsub_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
137     fn mul(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
138     fn fmul(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
139     fn fmul_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
140     fn udiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
141     fn exactudiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
142     fn sdiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
143     fn exactsdiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
144     fn fdiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
145     fn fdiv_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
146     fn urem(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
147     fn srem(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
148     fn frem(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
149     fn frem_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
150     fn shl(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
151     fn lshr(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
152     fn ashr(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
153     fn and(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
154     fn or(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
155     fn xor(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
156     fn neg(&self, v: &'ll Value) -> &'ll Value;
157     fn fneg(&self, v: &'ll Value) -> &'ll Value;
158     fn not(&self, v: &'ll Value) -> &'ll Value;
159
160     fn alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value;
161     fn dynamic_alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value;
162     fn array_alloca(
163         &self,
164         ty: &'ll Type,
165         len: &'ll Value,
166         name: &str,
167         align: Align
168     ) -> &'ll Value;
169
170     fn load(&self, ptr: &'ll Value, align: Align) -> &'ll Value;
171     fn volatile_load(&self, ptr: &'ll Value) -> &'ll Value;
172     fn atomic_load(&self, ptr: &'ll Value, order: AtomicOrdering, size: Size) -> &'ll Value;
173
174     fn range_metadata(&self, load: &'ll Value, range: Range<u128>);
175     fn nonnull_metadata(&self, load: &'ll Value);
176
177     fn store(&self, val: &'ll Value, ptr: &'ll Value, align: Align) -> &'ll Value;
178     fn store_with_flags(
179         &self,
180         val: &'ll Value,
181         ptr: &'ll Value,
182         align: Align,
183         flags: MemFlags,
184     ) -> &'ll Value;
185     fn atomic_store(
186         &self,
187         val: &'ll Value,
188         ptr: &'ll Value,
189         order: AtomicOrdering,
190         size: Size
191     );
192
193     fn gep(&self, ptr: &'ll Value, indices: &[&'ll Value]) -> &'ll Value;
194     fn inbounds_gep(&self, ptr: &'ll Value, indices: &[&'ll Value]) -> &'ll Value;
195     fn struct_gep(&self, ptr: &'ll Value, idx: u64) -> &'ll Value;
196
197     fn trunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
198     fn sext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
199     fn fptoui(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
200     fn fptosi(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
201     fn uitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
202     fn sitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
203     fn fptrunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
204     fn fpext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
205     fn ptrtoint(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
206     fn inttoptr(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
207     fn bitcast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
208     fn intcast(&self, val: &'ll Value, dest_ty: &'ll Type, is_signed: bool) -> &'ll Value;
209     fn pointercast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
210
211     fn icmp(&self, op: IntPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
212     fn fcmp(&self, op: RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
213
214     fn empty_phi(&self, ty: &'ll Type) -> &'ll Value;
215     fn phi(&self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value;
216     fn inline_asm_call(
217         &self,
218         asm: *const c_char,
219         cons: *const c_char,
220         inputs: &[&'ll Value],
221         output: &'ll Type,
222         volatile: bool,
223         alignstack: bool,
224         dia: AsmDialect
225     ) -> Option<&'ll Value>;
226
227
228     fn memcpy(&self, dst: &'ll Value, dst_align: u64,
229                   src: &'ll Value, src_align: u64,
230                   size: &'ll Value, is_volatile: bool) -> &'ll Value;
231     fn memmove(&self, dst: &'ll Value, dst_align: u64,
232                   src: &'ll Value, src_align: u64,
233                   size: &'ll Value, is_volatile: bool) -> &'ll Value;
234
235     fn minnum(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
236     fn maxnum(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
237     fn select(
238         &self, cond: &'ll Value,
239         then_val: &'ll Value,
240         else_val: &'ll Value,
241     ) -> &'ll Value;
242
243     fn va_arg(&self, list: &'ll Value, ty: &'ll Type) -> &'ll Value;
244     fn extract_element(&self, vec: &'ll Value, idx: &'ll Value) -> &'ll Value;
245     fn insert_element(
246         &self, vec: &'ll Value,
247         elt: &'ll Value,
248         idx: &'ll Value,
249     ) -> &'ll Value;
250     fn shuffle_vector(&self, v1: &'ll Value, v2: &'ll Value, mask: &'ll Value) -> &'ll Value;
251     fn vector_splat(&self, num_elts: usize, elt: &'ll Value) -> &'ll Value;
252     fn vector_reduce_fadd_fast(&self, acc: &'ll Value, src: &'ll Value) -> &'ll Value;
253     fn vector_reduce_fmul_fast(&self, acc: &'ll Value, src: &'ll Value) -> &'ll Value;
254     fn vector_reduce_add(&self, src: &'ll Value) -> &'ll Value;
255     fn vector_reduce_mul(&self, src: &'ll Value) -> &'ll Value;
256     fn vector_reduce_and(&self, src: &'ll Value) -> &'ll Value;
257     fn vector_reduce_or(&self, src: &'ll Value) -> &'ll Value;
258     fn vector_reduce_xor(&self, src: &'ll Value) -> &'ll Value;
259     fn vector_reduce_fmin(&self, src: &'ll Value) -> &'ll Value;
260     fn vector_reduce_fmax(&self, src: &'ll Value) -> &'ll Value;
261     fn vector_reduce_fmin_fast(&self, src: &'ll Value) -> &'ll Value;
262     fn vector_reduce_fmax_fast(&self, src: &'ll Value) -> &'ll Value;
263     fn vector_reduce_min(&self, src: &'ll Value, is_signed: bool) -> &'ll Value;
264     fn vector_reduce_max(&self, src: &'ll Value, is_signed: bool) -> &'ll Value;
265     fn extract_value(&self, agg_val: &'ll Value, idx: u64) -> &'ll Value;
266     fn insert_value(
267         &self,
268         agg_val: &'ll Value,
269         elt: &'ll Value,
270         idx: u64
271     ) -> &'ll Value;
272
273     fn landing_pad(
274         &self,
275         ty: &'ll Type,
276         pers_fn: &'ll Value,
277         num_clauses: usize
278     ) -> &'ll Value;
279     fn add_clause(&self, landing_pad: &'ll Value, clause: &'ll Value);
280     fn set_cleanup(&self, landing_pad: &'ll Value);
281     fn resume(&self, exn: &'ll Value) -> &'ll Value;
282     fn cleanup_pad(
283         &self,
284         parent: Option<&'ll Value>,
285         args: &[&'ll Value]
286     ) -> &'ll Value;
287     fn cleanup_ret(
288         &self, cleanup: &'ll Value,
289         unwind: Option<&'ll BasicBlock>,
290     ) -> &'ll Value;
291     fn catch_pad(
292         &self,
293         parent: &'ll Value,
294         args: &[&'ll Value]
295     ) -> &'ll Value;
296     fn catch_ret(&self, pad: &'ll Value, unwind: &'ll BasicBlock) -> &'ll Value;
297     fn catch_switch(
298         &self,
299         parent: Option<&'ll Value>,
300         unwind: Option<&'ll BasicBlock>,
301         num_handlers: usize,
302     ) -> &'ll Value;
303     fn add_handler(&self, catch_switch: &'ll Value, handler: &'ll BasicBlock);
304     fn set_personality_fn(&self, personality: &'ll Value);
305
306     fn atomic_cmpxchg(
307         &self,
308         dst: &'ll Value,
309         cmp: &'ll Value,
310         src: &'ll Value,
311         order: AtomicOrdering,
312         failure_order: AtomicOrdering,
313         weak: bool,
314     ) -> &'ll Value;
315     fn atomic_rmw(
316         &self,
317         op: AtomicRmwBinOp,
318         dst: &'ll Value,
319         src: &'ll Value,
320         order: AtomicOrdering,
321     ) -> &'ll Value;
322     fn atomic_fence(&self, order: AtomicOrdering, scope: SynchronizationScope);
323     fn add_case(&self, s: &'ll Value, on_val: &'ll Value, dest: &'ll BasicBlock);
324     fn add_incoming_to_phi(&self, phi: &'ll Value, val: &'ll Value, bb: &'ll BasicBlock);
325     fn set_invariant_load(&self, load: &'ll Value);
326
327     fn check_store(
328         &self,
329         val: &'ll Value,
330         ptr: &'ll Value
331     ) -> &'ll Value;
332     fn check_call<'b>(
333         &self,
334         typ: &str,
335         llfn: &'ll Value,
336         args: &'b [&'ll Value]
337     ) -> Cow<'b, [&'ll Value]>;
338     fn lifetime_start(&self, ptr: &'ll Value, size: Size);
339     fn lifetime_end(&self, ptr: &'ll Value, size: Size);
340
341     fn call_lifetime_intrinsic(&self, intrinsic: &str, ptr: &'ll Value, size: Size);
342
343     fn call(&self, llfn: &'ll Value, args: &[&'ll Value],
344                 bundle: Option<&OperandBundleDef<'ll, &'ll Value>>) -> &'ll Value;
345     fn zext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
346 }