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