]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/builder.rs
bc66087d3ce70161e28c2fbe560eca86b29ea6c7
[rust.git] / src / librustc_codegen_ssa / traits / builder.rs
1 use super::abi::AbiBuilderMethods;
2 use super::asm::AsmBuilderMethods;
3 use super::debuginfo::DebugInfoBuilderMethods;
4 use super::intrinsic::IntrinsicCallMethods;
5 use super::type_::ArgTypeMethods;
6 use super::{HasCodegen, StaticBuilderMethods};
7 use common::{AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope};
8 use mir::operand::OperandRef;
9 use mir::place::PlaceRef;
10 use rustc::ty::Ty;
11 use rustc::ty::layout::{Align, Size};
12 use std::ffi::CStr;
13 use MemFlags;
14
15 use std::borrow::Cow;
16 use std::ops::Range;
17 use syntax::ast::AsmDialect;
18
19 #[derive(Copy, Clone)]
20 pub enum OverflowOp {
21     Add,
22     Sub,
23     Mul,
24 }
25
26 pub trait BuilderMethods<'a, 'tcx: 'a>:
27     HasCodegen<'tcx>
28     + DebugInfoBuilderMethods<'tcx>
29     + ArgTypeMethods<'tcx>
30     + AbiBuilderMethods<'tcx>
31     + IntrinsicCallMethods<'tcx>
32     + AsmBuilderMethods<'tcx>
33     + StaticBuilderMethods<'tcx>
34 {
35     fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Value, name: &'b str) -> Self;
36     fn with_cx(cx: &'a Self::CodegenCx) -> Self;
37     fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
38     fn cx(&self) -> &Self::CodegenCx;
39     fn llfn(&self) -> Self::Value;
40     fn llbb(&self) -> Self::BasicBlock;
41     fn count_insn(&self, category: &str);
42
43     fn set_value_name(&mut self, value: Self::Value, name: &str);
44     fn position_at_end(&mut self, llbb: Self::BasicBlock);
45     fn position_at_start(&mut self, llbb: Self::BasicBlock);
46     fn ret_void(&mut self);
47     fn ret(&mut self, v: Self::Value);
48     fn br(&mut self, dest: Self::BasicBlock);
49     fn cond_br(
50         &mut self,
51         cond: Self::Value,
52         then_llbb: Self::BasicBlock,
53         else_llbb: Self::BasicBlock,
54     );
55     fn switch(
56         &mut self,
57         v: Self::Value,
58         else_llbb: Self::BasicBlock,
59         num_cases: usize,
60     ) -> Self::Value;
61     fn invoke(
62         &mut self,
63         llfn: Self::Value,
64         args: &[Self::Value],
65         then: Self::BasicBlock,
66         catch: Self::BasicBlock,
67         funclet: Option<&Self::Funclet>,
68     ) -> Self::Value;
69     fn unreachable(&mut self);
70     fn add(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
71     fn fadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
72     fn fadd_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
73     fn sub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
74     fn fsub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
75     fn fsub_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
76     fn mul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
77     fn fmul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
78     fn fmul_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
79     fn udiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
80     fn exactudiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
81     fn sdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
82     fn exactsdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
83     fn fdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
84     fn fdiv_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
85     fn urem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
86     fn srem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
87     fn frem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
88     fn frem_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
89     fn shl(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
90     fn lshr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
91     fn ashr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
92     fn and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
93     fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
94     fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
95     fn neg(&mut self, v: Self::Value) -> Self::Value;
96     fn fneg(&mut self, v: Self::Value) -> Self::Value;
97     fn not(&mut self, v: Self::Value) -> Self::Value;
98
99     fn checked_binop(
100         &mut self,
101         oop: OverflowOp,
102         ty: Ty,
103         lhs: Self::Value,
104         rhs: Self::Value,
105     ) -> (Self::Value, Self::Value);
106
107     fn alloca(&mut self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
108     fn dynamic_alloca(&mut self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
109     fn array_alloca(
110         &mut self,
111         ty: Self::Type,
112         len: Self::Value,
113         name: &str,
114         align: Align,
115     ) -> Self::Value;
116
117     fn load(&mut self, ptr: Self::Value, align: Align) -> Self::Value;
118     fn volatile_load(&mut self, ptr: Self::Value) -> Self::Value;
119     fn atomic_load(&mut self, ptr: Self::Value, order: AtomicOrdering, size: Size) -> Self::Value;
120     fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
121         -> OperandRef<'tcx, Self::Value>;
122
123     fn range_metadata(&mut self, load: Self::Value, range: Range<u128>);
124     fn nonnull_metadata(&mut self, load: Self::Value);
125
126     fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
127     fn store_with_flags(
128         &mut self,
129         val: Self::Value,
130         ptr: Self::Value,
131         align: Align,
132         flags: MemFlags,
133     ) -> Self::Value;
134     fn atomic_store(
135         &mut self,
136         val: Self::Value,
137         ptr: Self::Value,
138         order: AtomicOrdering,
139         size: Size,
140     );
141
142     fn gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
143     fn inbounds_gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
144     fn struct_gep(&mut self, ptr: Self::Value, idx: u64) -> Self::Value;
145
146     fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
147     fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
148     fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
149     fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
150     fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
151     fn sitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
152     fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
153     fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
154     fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
155     fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
156     fn bitcast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
157     fn intcast(&mut self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
158     fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
159
160     fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
161     fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
162
163     fn empty_phi(&mut self, ty: Self::Type) -> Self::Value;
164     fn phi(
165         &mut self,
166         ty: Self::Type,
167         vals: &[Self::Value],
168         bbs: &[Self::BasicBlock],
169     ) -> Self::Value;
170     fn inline_asm_call(
171         &mut self,
172         asm: &CStr,
173         cons: &CStr,
174         inputs: &[Self::Value],
175         output: Self::Type,
176         volatile: bool,
177         alignstack: bool,
178         dia: AsmDialect,
179     ) -> Option<Self::Value>;
180
181     fn memcpy(
182         &mut self,
183         dst: Self::Value,
184         dst_align: Align,
185         src: Self::Value,
186         src_align: Align,
187         size: Self::Value,
188         flags: MemFlags,
189     );
190     fn memmove(
191         &mut self,
192         dst: Self::Value,
193         dst_align: Align,
194         src: Self::Value,
195         src_align: Align,
196         size: Self::Value,
197         flags: MemFlags,
198     );
199     fn memset(
200         &mut self,
201         ptr: Self::Value,
202         fill_byte: Self::Value,
203         size: Self::Value,
204         align: Align,
205         flags: MemFlags,
206     );
207
208     fn minnum(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
209     fn maxnum(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
210     fn select(
211         &mut self,
212         cond: Self::Value,
213         then_val: Self::Value,
214         else_val: Self::Value,
215     ) -> Self::Value;
216
217     fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
218     fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
219     fn insert_element(
220         &mut self,
221         vec: Self::Value,
222         elt: Self::Value,
223         idx: Self::Value,
224     ) -> Self::Value;
225     fn shuffle_vector(
226         &mut self,
227         v1: Self::Value,
228         v2: Self::Value,
229         mask: Self::Value,
230     ) -> Self::Value;
231     fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
232     fn vector_reduce_fadd_fast(&mut self, acc: Self::Value, src: Self::Value) -> Self::Value;
233     fn vector_reduce_fmul_fast(&mut self, acc: Self::Value, src: Self::Value) -> Self::Value;
234     fn vector_reduce_add(&mut self, src: Self::Value) -> Self::Value;
235     fn vector_reduce_mul(&mut self, src: Self::Value) -> Self::Value;
236     fn vector_reduce_and(&mut self, src: Self::Value) -> Self::Value;
237     fn vector_reduce_or(&mut self, src: Self::Value) -> Self::Value;
238     fn vector_reduce_xor(&mut self, src: Self::Value) -> Self::Value;
239     fn vector_reduce_fmin(&mut self, src: Self::Value) -> Self::Value;
240     fn vector_reduce_fmax(&mut self, src: Self::Value) -> Self::Value;
241     fn vector_reduce_fmin_fast(&mut self, src: Self::Value) -> Self::Value;
242     fn vector_reduce_fmax_fast(&mut self, src: Self::Value) -> Self::Value;
243     fn vector_reduce_min(&mut self, src: Self::Value, is_signed: bool) -> Self::Value;
244     fn vector_reduce_max(&mut self, src: Self::Value, is_signed: bool) -> Self::Value;
245     fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
246     fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
247
248     fn landing_pad(
249         &mut self,
250         ty: Self::Type,
251         pers_fn: Self::Value,
252         num_clauses: usize,
253     ) -> Self::Value;
254     fn add_clause(&mut self, landing_pad: Self::Value, clause: Self::Value);
255     fn set_cleanup(&mut self, landing_pad: Self::Value);
256     fn resume(&mut self, exn: Self::Value) -> Self::Value;
257     fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
258     fn cleanup_ret(
259         &mut self,
260         funclet: &Self::Funclet,
261         unwind: Option<Self::BasicBlock>,
262     ) -> Self::Value;
263     fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
264     fn catch_ret(&mut self, funclet: &Self::Funclet, unwind: Self::BasicBlock) -> Self::Value;
265     fn catch_switch(
266         &mut self,
267         parent: Option<Self::Value>,
268         unwind: Option<Self::BasicBlock>,
269         num_handlers: usize,
270     ) -> Self::Value;
271     fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
272     fn set_personality_fn(&mut self, personality: Self::Value);
273
274     fn atomic_cmpxchg(
275         &mut self,
276         dst: Self::Value,
277         cmp: Self::Value,
278         src: Self::Value,
279         order: AtomicOrdering,
280         failure_order: AtomicOrdering,
281         weak: bool,
282     ) -> Self::Value;
283     fn atomic_rmw(
284         &mut self,
285         op: AtomicRmwBinOp,
286         dst: Self::Value,
287         src: Self::Value,
288         order: AtomicOrdering,
289     ) -> Self::Value;
290     fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
291     fn add_case(&mut self, s: Self::Value, on_val: Self::Value, dest: Self::BasicBlock);
292     fn add_incoming_to_phi(&mut self, phi: Self::Value, val: Self::Value, bb: Self::BasicBlock);
293     fn set_invariant_load(&mut self, load: Self::Value);
294
295     /// Returns the ptr value that should be used for storing `val`.
296     fn check_store(&mut self, val: Self::Value, ptr: Self::Value) -> Self::Value;
297
298     /// Returns the args that should be used for a call to `llfn`.
299     fn check_call<'b>(
300         &mut self,
301         typ: &str,
302         llfn: Self::Value,
303         args: &'b [Self::Value],
304     ) -> Cow<'b, [Self::Value]>
305     where
306         [Self::Value]: ToOwned;
307
308     /// Called for `StorageLive`
309     fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
310
311     /// Called for `StorageDead`
312     fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
313
314     fn call(
315         &mut self,
316         llfn: Self::Value,
317         args: &[Self::Value],
318         funclet: Option<&Self::Funclet>,
319     ) -> Self::Value;
320     fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
321
322     unsafe fn delete_basic_block(&mut self, bb: Self::BasicBlock);
323     fn do_not_inline(&mut self, llret: Self::Value);
324 }