]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_codegen_ssa/src/traits/builder.rs
New upstream version 1.58.1+dfsg1
[rustc.git] / compiler / rustc_codegen_ssa / src / traits / builder.rs
CommitLineData
a1dfa0c6
XL
1use super::abi::AbiBuilderMethods;
2use super::asm::AsmBuilderMethods;
f035d41b 3use super::coverageinfo::CoverageInfoBuilderMethods;
a1dfa0c6
XL
4use super::debuginfo::DebugInfoBuilderMethods;
5use super::intrinsic::IntrinsicCallMethods;
60c5eb7d 6use super::type_::ArgAbiMethods;
a1dfa0c6 7use super::{HasCodegen, StaticBuilderMethods};
60c5eb7d 8
dfeec247
XL
9use crate::common::{
10 AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope,
11};
9fa01778
XL
12use crate::mir::operand::OperandRef;
13use crate::mir::place::PlaceRef;
14use crate::MemFlags;
60c5eb7d 15
1b1a35ee 16use rustc_middle::ty::layout::{HasParamEnv, TyAndLayout};
ba9703b0 17use rustc_middle::ty::Ty;
29967ef6 18use rustc_span::Span;
c295e0f8 19use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
60c5eb7d
XL
20use rustc_target::spec::HasTargetSpec;
21
a1dfa0c6
XL
22#[derive(Copy, Clone)]
23pub enum OverflowOp {
24 Add,
25 Sub,
26 Mul,
27}
28
dc9dc135 29pub trait BuilderMethods<'a, 'tcx>:
a1dfa0c6 30 HasCodegen<'tcx>
f035d41b 31 + CoverageInfoBuilderMethods<'tcx>
74b04a01 32 + DebugInfoBuilderMethods
60c5eb7d 33 + ArgAbiMethods<'tcx>
a1dfa0c6
XL
34 + AbiBuilderMethods<'tcx>
35 + IntrinsicCallMethods<'tcx>
36 + AsmBuilderMethods<'tcx>
dc9dc135 37 + StaticBuilderMethods
48663c56
XL
38 + HasParamEnv<'tcx>
39 + HasTargetSpec
a1dfa0c6 40{
17df50a5
XL
41 fn build(cx: &'a Self::CodegenCx, llbb: Self::BasicBlock) -> Self;
42
a1dfa0c6 43 fn cx(&self) -> &Self::CodegenCx;
a1dfa0c6 44 fn llbb(&self) -> Self::BasicBlock;
17df50a5 45
29967ef6 46 fn set_span(&mut self, span: Span);
a1dfa0c6 47
17df50a5
XL
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
a1dfa0c6
XL
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,
1b1a35ee 69 cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)>,
532ac7d7 70 );
a1dfa0c6
XL
71 fn invoke(
72 &mut self,
94222f64 73 llty: Self::Type,
a1dfa0c6
XL
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);
532ac7d7 81
a1dfa0c6
XL
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;
dc9dc135
XL
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;
a1dfa0c6
XL
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,
9fa01778 120 ty: Ty<'_>,
a1dfa0c6
XL
121 lhs: Self::Value,
122 rhs: Self::Value,
123 ) -> (Self::Value, Self::Value);
124
1b1a35ee
XL
125 fn from_immediate(&mut self, val: Self::Value) -> Self::Value;
126 fn to_immediate(&mut self, val: Self::Value, layout: TyAndLayout<'_>) -> Self::Value {
c295e0f8 127 if let Abi::Scalar(scalar) = layout.abi {
1b1a35ee
XL
128 self.to_immediate_scalar(val, scalar)
129 } else {
130 val
131 }
132 }
c295e0f8 133 fn to_immediate_scalar(&mut self, val: Self::Value, scalar: Scalar) -> Self::Value;
1b1a35ee 134
e1599b0c
XL
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;
dfeec247 137 fn array_alloca(&mut self, ty: Self::Type, len: Self::Value, align: Align) -> Self::Value;
a1dfa0c6 138
136023e0
XL
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;
a1dfa0c6 148 fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
dfeec247 149 -> OperandRef<'tcx, Self::Value>;
a1dfa0c6 150
dfeec247 151 /// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset.
532ac7d7
XL
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
c295e0f8 159 fn range_metadata(&mut self, load: Self::Value, range: WrappingRange);
a1dfa0c6 160 fn nonnull_metadata(&mut self, load: Self::Value);
3c0e092e
XL
161 fn type_metadata(&mut self, function: Self::Function, typeid: String);
162 fn typeid_metadata(&mut self, typeid: String) -> Self::Value;
a1dfa0c6
XL
163
164 fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
165 fn store_with_flags(
166 &mut self,
167 val: Self::Value,
168 ptr: Self::Value,
169 align: Align,
170 flags: MemFlags,
171 ) -> Self::Value;
172 fn atomic_store(
173 &mut self,
174 val: Self::Value,
175 ptr: Self::Value,
176 order: AtomicOrdering,
177 size: Size,
178 );
179
94222f64
XL
180 fn gep(&mut self, ty: Self::Type, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
181 fn inbounds_gep(
182 &mut self,
183 ty: Self::Type,
184 ptr: Self::Value,
185 indices: &[Self::Value],
186 ) -> Self::Value;
187 fn struct_gep(&mut self, ty: Self::Type, ptr: Self::Value, idx: u64) -> Self::Value;
a1dfa0c6
XL
188
189 fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
190 fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
f035d41b
XL
191 fn fptoui_sat(&mut self, val: Self::Value, dest_ty: Self::Type) -> Option<Self::Value>;
192 fn fptosi_sat(&mut self, val: Self::Value, dest_ty: Self::Type) -> Option<Self::Value>;
a1dfa0c6
XL
193 fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
194 fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
195 fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
196 fn sitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
197 fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
198 fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
199 fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
200 fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
201 fn bitcast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
202 fn intcast(&mut self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
203 fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
204
205 fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
206 fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
207
a1dfa0c6
XL
208 fn memcpy(
209 &mut self,
210 dst: Self::Value,
211 dst_align: Align,
212 src: Self::Value,
213 src_align: Align,
214 size: Self::Value,
215 flags: MemFlags,
216 );
217 fn memmove(
218 &mut self,
219 dst: Self::Value,
220 dst_align: Align,
221 src: Self::Value,
222 src_align: Align,
223 size: Self::Value,
224 flags: MemFlags,
225 );
226 fn memset(
227 &mut self,
228 ptr: Self::Value,
229 fill_byte: Self::Value,
230 size: Self::Value,
231 align: Align,
232 flags: MemFlags,
233 );
234
a1dfa0c6
XL
235 fn select(
236 &mut self,
237 cond: Self::Value,
238 then_val: Self::Value,
239 else_val: Self::Value,
240 ) -> Self::Value;
241
242 fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
243 fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
a1dfa0c6 244 fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
a1dfa0c6
XL
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;
a1dfa0c6
XL
254 fn set_cleanup(&mut self, landing_pad: Self::Value);
255 fn resume(&mut self, exn: Self::Value) -> Self::Value;
256 fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
257 fn cleanup_ret(
258 &mut self,
259 funclet: &Self::Funclet,
260 unwind: Option<Self::BasicBlock>,
261 ) -> Self::Value;
262 fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
a1dfa0c6
XL
263 fn catch_switch(
264 &mut self,
265 parent: Option<Self::Value>,
266 unwind: Option<Self::BasicBlock>,
267 num_handlers: usize,
268 ) -> Self::Value;
269 fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
270 fn set_personality_fn(&mut self, personality: Self::Value);
271
272 fn atomic_cmpxchg(
273 &mut self,
274 dst: Self::Value,
275 cmp: Self::Value,
276 src: Self::Value,
277 order: AtomicOrdering,
278 failure_order: AtomicOrdering,
279 weak: bool,
280 ) -> Self::Value;
281 fn atomic_rmw(
282 &mut self,
283 op: AtomicRmwBinOp,
284 dst: Self::Value,
285 src: Self::Value,
286 order: AtomicOrdering,
287 ) -> Self::Value;
288 fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
a1dfa0c6
XL
289 fn set_invariant_load(&mut self, load: Self::Value);
290
a1dfa0c6
XL
291 /// Called for `StorageLive`
292 fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
293
294 /// Called for `StorageDead`
295 fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
296
f035d41b
XL
297 fn instrprof_increment(
298 &mut self,
299 fn_name: Self::Value,
300 hash: Self::Value,
301 num_counters: Self::Value,
302 index: Self::Value,
3dfed10e 303 );
f035d41b 304
a1dfa0c6
XL
305 fn call(
306 &mut self,
94222f64 307 llty: Self::Type,
a1dfa0c6
XL
308 llfn: Self::Value,
309 args: &[Self::Value],
310 funclet: Option<&Self::Funclet>,
311 ) -> Self::Value;
312 fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
313
a1dfa0c6
XL
314 fn do_not_inline(&mut self, llret: Self::Value);
315}