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