]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/builder.rs
rustc_codegen_ssa: move debuginfo-related things to a new mir::debuginfo module.
[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 crate::common::{AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate,
8     SynchronizationScope};
9 use crate::mir::operand::OperandRef;
10 use crate::mir::place::PlaceRef;
11 use crate::MemFlags;
12 use rustc::ty::Ty;
13 use rustc::ty::layout::{Align, Size, HasParamEnv};
14 use rustc_target::spec::{HasTargetSpec};
15 use std::ops::Range;
16 use std::iter::TrustedLen;
17
18 #[derive(Copy, Clone)]
19 pub enum OverflowOp {
20     Add,
21     Sub,
22     Mul,
23 }
24
25 pub trait BuilderMethods<'a, 'tcx>:
26     HasCodegen<'tcx>
27     + DebugInfoBuilderMethods<'tcx>
28     + ArgTypeMethods<'tcx>
29     + AbiBuilderMethods<'tcx>
30     + IntrinsicCallMethods<'tcx>
31     + AsmBuilderMethods<'tcx>
32     + StaticBuilderMethods
33     + HasParamEnv<'tcx>
34     + HasTargetSpec
35
36 {
37     fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Function, name: &'b str) -> Self;
38     fn with_cx(cx: &'a Self::CodegenCx) -> Self;
39     fn build_sibling_block(&self, name: &str) -> Self;
40     fn cx(&self) -> &Self::CodegenCx;
41     fn llbb(&self) -> Self::BasicBlock;
42
43     fn position_at_end(&mut self, llbb: Self::BasicBlock);
44     fn ret_void(&mut self);
45     fn ret(&mut self, v: Self::Value);
46     fn br(&mut self, dest: Self::BasicBlock);
47     fn cond_br(
48         &mut self,
49         cond: Self::Value,
50         then_llbb: Self::BasicBlock,
51         else_llbb: Self::BasicBlock,
52     );
53     fn switch(
54         &mut self,
55         v: Self::Value,
56         else_llbb: Self::BasicBlock,
57         cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)> + TrustedLen,
58     );
59     fn invoke(
60         &mut self,
61         llfn: Self::Value,
62         args: &[Self::Value],
63         then: Self::BasicBlock,
64         catch: Self::BasicBlock,
65         funclet: Option<&Self::Funclet>,
66     ) -> Self::Value;
67     fn unreachable(&mut self);
68
69     fn add(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
70     fn fadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
71     fn fadd_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
72     fn sub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
73     fn fsub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
74     fn fsub_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
75     fn mul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
76     fn fmul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
77     fn fmul_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
78     fn udiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
79     fn exactudiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
80     fn sdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
81     fn exactsdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
82     fn fdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
83     fn fdiv_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
84     fn urem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
85     fn srem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
86     fn frem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
87     fn frem_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
88     fn shl(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
89     fn lshr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
90     fn ashr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
91     fn unchecked_sadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
92     fn unchecked_uadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
93     fn unchecked_ssub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
94     fn unchecked_usub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
95     fn unchecked_smul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
96     fn unchecked_umul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
97     fn and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
98     fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
99     fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
100     fn neg(&mut self, v: Self::Value) -> Self::Value;
101     fn fneg(&mut self, v: Self::Value) -> Self::Value;
102     fn not(&mut self, v: Self::Value) -> Self::Value;
103
104     fn checked_binop(
105         &mut self,
106         oop: OverflowOp,
107         ty: Ty<'_>,
108         lhs: Self::Value,
109         rhs: Self::Value,
110     ) -> (Self::Value, Self::Value);
111
112     fn alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value;
113     fn dynamic_alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value;
114     fn array_alloca(
115         &mut self,
116         ty: Self::Type,
117         len: Self::Value,
118         align: Align,
119     ) -> Self::Value;
120
121     fn load(&mut self, ptr: Self::Value, align: Align) -> Self::Value;
122     fn volatile_load(&mut self, ptr: Self::Value) -> Self::Value;
123     fn atomic_load(&mut self, ptr: Self::Value, order: AtomicOrdering, size: Size) -> Self::Value;
124     fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
125         -> OperandRef<'tcx, Self::Value>;
126
127         /// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset.
128     fn write_operand_repeatedly(
129         self,
130         elem: OperandRef<'tcx, Self::Value>,
131         count: u64,
132         dest: PlaceRef<'tcx, Self::Value>,
133     ) -> Self;
134
135     fn range_metadata(&mut self, load: Self::Value, range: Range<u128>);
136     fn nonnull_metadata(&mut self, load: Self::Value);
137
138     fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
139     fn store_with_flags(
140         &mut self,
141         val: Self::Value,
142         ptr: Self::Value,
143         align: Align,
144         flags: MemFlags,
145     ) -> Self::Value;
146     fn atomic_store(
147         &mut self,
148         val: Self::Value,
149         ptr: Self::Value,
150         order: AtomicOrdering,
151         size: Size,
152     );
153
154     fn gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
155     fn inbounds_gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
156     fn struct_gep(&mut self, ptr: Self::Value, idx: u64) -> Self::Value;
157
158     fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
159     fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
160     fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
161     fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
162     fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
163     fn sitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
164     fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
165     fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
166     fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
167     fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
168     fn bitcast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
169     fn intcast(&mut self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
170     fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
171
172     fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
173     fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
174
175     fn memcpy(
176         &mut self,
177         dst: Self::Value,
178         dst_align: Align,
179         src: Self::Value,
180         src_align: Align,
181         size: Self::Value,
182         flags: MemFlags,
183     );
184     fn memmove(
185         &mut self,
186         dst: Self::Value,
187         dst_align: Align,
188         src: Self::Value,
189         src_align: Align,
190         size: Self::Value,
191         flags: MemFlags,
192     );
193     fn memset(
194         &mut self,
195         ptr: Self::Value,
196         fill_byte: Self::Value,
197         size: Self::Value,
198         align: Align,
199         flags: MemFlags,
200     );
201
202     fn select(
203         &mut self,
204         cond: Self::Value,
205         then_val: Self::Value,
206         else_val: Self::Value,
207     ) -> Self::Value;
208
209     fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
210     fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
211     fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
212     fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
213     fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
214
215     fn landing_pad(
216         &mut self,
217         ty: Self::Type,
218         pers_fn: Self::Value,
219         num_clauses: usize,
220     ) -> Self::Value;
221     fn set_cleanup(&mut self, landing_pad: Self::Value);
222     fn resume(&mut self, exn: Self::Value) -> Self::Value;
223     fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
224     fn cleanup_ret(
225         &mut self,
226         funclet: &Self::Funclet,
227         unwind: Option<Self::BasicBlock>,
228     ) -> Self::Value;
229     fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
230     fn catch_switch(
231         &mut self,
232         parent: Option<Self::Value>,
233         unwind: Option<Self::BasicBlock>,
234         num_handlers: usize,
235     ) -> Self::Value;
236     fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
237     fn set_personality_fn(&mut self, personality: Self::Value);
238
239     fn atomic_cmpxchg(
240         &mut self,
241         dst: Self::Value,
242         cmp: Self::Value,
243         src: Self::Value,
244         order: AtomicOrdering,
245         failure_order: AtomicOrdering,
246         weak: bool,
247     ) -> Self::Value;
248     fn atomic_rmw(
249         &mut self,
250         op: AtomicRmwBinOp,
251         dst: Self::Value,
252         src: Self::Value,
253         order: AtomicOrdering,
254     ) -> Self::Value;
255     fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
256     fn set_invariant_load(&mut self, load: Self::Value);
257
258     /// Called for `StorageLive`
259     fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
260
261     /// Called for `StorageDead`
262     fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
263
264     fn call(
265         &mut self,
266         llfn: Self::Value,
267         args: &[Self::Value],
268         funclet: Option<&Self::Funclet>,
269     ) -> Self::Value;
270     fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
271
272     unsafe fn delete_basic_block(&mut self, bb: Self::BasicBlock);
273     fn do_not_inline(&mut self, llret: Self::Value);
274 }