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