]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/builder.rs
Rollup merge of #61273 - RalfJung:maybe-uninit, r=Centril
[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: 'a>:
26     HasCodegen<'tcx>
27     + DebugInfoBuilderMethods<'tcx>
28     + ArgTypeMethods<'tcx>
29     + AbiBuilderMethods<'tcx>
30     + IntrinsicCallMethods<'tcx>
31     + AsmBuilderMethods<'tcx>
32     + StaticBuilderMethods<'tcx>
33     + HasParamEnv<'tcx>
34     + HasTargetSpec
35
36 {
37     fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Value, name: &'b str) -> Self;
38     fn with_cx(cx: &'a Self::CodegenCx) -> Self;
39     fn build_sibling_block<'b>(&self, name: &'b 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 and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
92     fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
93     fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
94     fn neg(&mut self, v: Self::Value) -> Self::Value;
95     fn fneg(&mut self, v: Self::Value) -> Self::Value;
96     fn not(&mut self, v: Self::Value) -> Self::Value;
97
98     fn checked_binop(
99         &mut self,
100         oop: OverflowOp,
101         ty: Ty<'_>,
102         lhs: Self::Value,
103         rhs: Self::Value,
104     ) -> (Self::Value, Self::Value);
105
106     fn alloca(&mut self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
107     fn dynamic_alloca(&mut self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
108     fn array_alloca(
109         &mut self,
110         ty: Self::Type,
111         len: Self::Value,
112         name: &str,
113         align: Align,
114     ) -> Self::Value;
115
116     fn load(&mut self, ptr: Self::Value, align: Align) -> Self::Value;
117     fn volatile_load(&mut self, ptr: Self::Value) -> Self::Value;
118     fn atomic_load(&mut self, ptr: Self::Value, order: AtomicOrdering, size: Size) -> Self::Value;
119     fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
120         -> OperandRef<'tcx, Self::Value>;
121
122         /// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset.
123     fn write_operand_repeatedly(
124         self,
125         elem: OperandRef<'tcx, Self::Value>,
126         count: u64,
127         dest: PlaceRef<'tcx, Self::Value>,
128     ) -> Self;
129
130     fn range_metadata(&mut self, load: Self::Value, range: Range<u128>);
131     fn nonnull_metadata(&mut self, load: Self::Value);
132
133     fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
134     fn store_with_flags(
135         &mut self,
136         val: Self::Value,
137         ptr: Self::Value,
138         align: Align,
139         flags: MemFlags,
140     ) -> Self::Value;
141     fn atomic_store(
142         &mut self,
143         val: Self::Value,
144         ptr: Self::Value,
145         order: AtomicOrdering,
146         size: Size,
147     );
148
149     fn gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
150     fn inbounds_gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
151     fn struct_gep(&mut self, ptr: Self::Value, idx: u64) -> Self::Value;
152
153     fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
154     fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
155     fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
156     fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
157     fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
158     fn sitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
159     fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
160     fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
161     fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
162     fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
163     fn bitcast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
164     fn intcast(&mut self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
165     fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
166
167     fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
168     fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
169
170     fn memcpy(
171         &mut self,
172         dst: Self::Value,
173         dst_align: Align,
174         src: Self::Value,
175         src_align: Align,
176         size: Self::Value,
177         flags: MemFlags,
178     );
179     fn memmove(
180         &mut self,
181         dst: Self::Value,
182         dst_align: Align,
183         src: Self::Value,
184         src_align: Align,
185         size: Self::Value,
186         flags: MemFlags,
187     );
188     fn memset(
189         &mut self,
190         ptr: Self::Value,
191         fill_byte: Self::Value,
192         size: Self::Value,
193         align: Align,
194         flags: MemFlags,
195     );
196
197     fn select(
198         &mut self,
199         cond: Self::Value,
200         then_val: Self::Value,
201         else_val: Self::Value,
202     ) -> Self::Value;
203
204     fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
205     fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
206     fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
207     fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
208     fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
209
210     fn landing_pad(
211         &mut self,
212         ty: Self::Type,
213         pers_fn: Self::Value,
214         num_clauses: usize,
215     ) -> Self::Value;
216     fn set_cleanup(&mut self, landing_pad: Self::Value);
217     fn resume(&mut self, exn: Self::Value) -> Self::Value;
218     fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
219     fn cleanup_ret(
220         &mut self,
221         funclet: &Self::Funclet,
222         unwind: Option<Self::BasicBlock>,
223     ) -> Self::Value;
224     fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
225     fn catch_switch(
226         &mut self,
227         parent: Option<Self::Value>,
228         unwind: Option<Self::BasicBlock>,
229         num_handlers: usize,
230     ) -> Self::Value;
231     fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
232     fn set_personality_fn(&mut self, personality: Self::Value);
233
234     fn atomic_cmpxchg(
235         &mut self,
236         dst: Self::Value,
237         cmp: Self::Value,
238         src: Self::Value,
239         order: AtomicOrdering,
240         failure_order: AtomicOrdering,
241         weak: bool,
242     ) -> Self::Value;
243     fn atomic_rmw(
244         &mut self,
245         op: AtomicRmwBinOp,
246         dst: Self::Value,
247         src: Self::Value,
248         order: AtomicOrdering,
249     ) -> Self::Value;
250     fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
251     fn set_invariant_load(&mut self, load: Self::Value);
252
253     /// Called for `StorageLive`
254     fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
255
256     /// Called for `StorageDead`
257     fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
258
259     fn call(
260         &mut self,
261         llfn: Self::Value,
262         args: &[Self::Value],
263         funclet: Option<&Self::Funclet>,
264     ) -> Self::Value;
265     fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
266
267     unsafe fn delete_basic_block(&mut self, bb: Self::BasicBlock);
268     fn do_not_inline(&mut self, llret: Self::Value);
269 }