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::misc::MiscMethods;
7 use super::type_::{ArgAbiMethods, BaseTypeMethods};
8 use super::{HasCodegen, StaticBuilderMethods};
11 AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
13 use crate::mir::operand::OperandRef;
14 use crate::mir::place::PlaceRef;
17 use rustc_middle::ty::layout::{HasParamEnv, TyAndLayout};
18 use rustc_middle::ty::Ty;
20 use rustc_target::abi::call::FnAbi;
21 use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
22 use rustc_target::spec::HasTargetSpec;
24 #[derive(Copy, Clone)]
31 pub trait BuilderMethods<'a, 'tcx>:
33 + CoverageInfoBuilderMethods<'tcx>
34 + DebugInfoBuilderMethods
36 + AbiBuilderMethods<'tcx>
37 + IntrinsicCallMethods<'tcx>
38 + AsmBuilderMethods<'tcx>
39 + StaticBuilderMethods
43 fn build(cx: &'a Self::CodegenCx, llbb: Self::BasicBlock) -> Self;
45 fn cx(&self) -> &Self::CodegenCx;
46 fn llbb(&self) -> Self::BasicBlock;
48 fn set_span(&mut self, span: Span);
50 // FIXME(eddyb) replace uses of this with `append_sibling_block`.
51 fn append_block(cx: &'a Self::CodegenCx, llfn: Self::Function, name: &str) -> Self::BasicBlock;
53 fn append_sibling_block(&mut self, name: &str) -> Self::BasicBlock;
55 fn switch_to_block(&mut self, llbb: Self::BasicBlock);
57 fn ret_void(&mut self);
58 fn ret(&mut self, v: Self::Value);
59 fn br(&mut self, dest: Self::BasicBlock);
63 then_llbb: Self::BasicBlock,
64 else_llbb: Self::BasicBlock,
69 else_llbb: Self::BasicBlock,
70 cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)>,
75 fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
78 then: Self::BasicBlock,
79 catch: Self::BasicBlock,
80 funclet: Option<&Self::Funclet>,
82 fn unreachable(&mut self);
84 fn add(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
85 fn fadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
86 fn fadd_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
87 fn sub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
88 fn fsub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
89 fn fsub_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
90 fn mul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
91 fn fmul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
92 fn fmul_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
93 fn udiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
94 fn exactudiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
95 fn sdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
96 fn exactsdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
97 fn fdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
98 fn fdiv_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
99 fn urem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
100 fn srem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
101 fn frem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
102 fn frem_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
103 fn shl(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
104 fn lshr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
105 fn ashr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
106 fn unchecked_sadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
107 fn unchecked_uadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
108 fn unchecked_ssub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
109 fn unchecked_usub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
110 fn unchecked_smul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
111 fn unchecked_umul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
112 fn and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
113 fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
114 fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
115 fn neg(&mut self, v: Self::Value) -> Self::Value;
116 fn fneg(&mut self, v: Self::Value) -> Self::Value;
117 fn not(&mut self, v: Self::Value) -> Self::Value;
125 ) -> (Self::Value, Self::Value);
127 fn from_immediate(&mut self, val: Self::Value) -> Self::Value;
128 fn to_immediate(&mut self, val: Self::Value, layout: TyAndLayout<'_>) -> Self::Value {
129 if let Abi::Scalar(scalar) = layout.abi {
130 self.to_immediate_scalar(val, scalar)
135 fn to_immediate_scalar(&mut self, val: Self::Value, scalar: Scalar) -> Self::Value;
137 fn alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value;
138 fn byte_array_alloca(&mut self, len: Self::Value, align: Align) -> Self::Value;
140 fn load(&mut self, ty: Self::Type, ptr: Self::Value, align: Align) -> Self::Value;
141 fn volatile_load(&mut self, ty: Self::Type, ptr: Self::Value) -> Self::Value;
146 order: AtomicOrdering,
149 fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
150 -> OperandRef<'tcx, Self::Value>;
152 /// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset.
153 fn write_operand_repeatedly(
155 elem: OperandRef<'tcx, Self::Value>,
157 dest: PlaceRef<'tcx, Self::Value>,
160 fn range_metadata(&mut self, load: Self::Value, range: WrappingRange);
161 fn nonnull_metadata(&mut self, load: Self::Value);
163 fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
175 order: AtomicOrdering,
179 fn gep(&mut self, ty: Self::Type, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
184 indices: &[Self::Value],
186 fn struct_gep(&mut self, ty: Self::Type, ptr: Self::Value, idx: u64) -> Self::Value;
188 fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
189 fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
190 fn fptoui_sat(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
191 fn fptosi_sat(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
192 fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
193 fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
194 fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
195 fn sitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
196 fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
197 fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
198 fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
199 fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
200 fn bitcast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
201 fn intcast(&mut self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
202 fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
204 fn cast_float_to_int(
210 let in_ty = self.cx().val_ty(x);
211 let (float_ty, int_ty) = if self.cx().type_kind(dest_ty) == TypeKind::Vector
212 && self.cx().type_kind(in_ty) == TypeKind::Vector
214 (self.cx().element_type(in_ty), self.cx().element_type(dest_ty))
218 assert!(matches!(self.cx().type_kind(float_ty), TypeKind::Float | TypeKind::Double));
219 assert_eq!(self.cx().type_kind(int_ty), TypeKind::Integer);
221 if let Some(false) = self.cx().sess().opts.unstable_opts.saturating_float_casts {
222 return if signed { self.fptosi(x, dest_ty) } else { self.fptoui(x, dest_ty) };
225 if signed { self.fptosi_sat(x, dest_ty) } else { self.fptoui_sat(x, dest_ty) }
228 fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
229 fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
252 fill_byte: Self::Value,
261 then_val: Self::Value,
262 else_val: Self::Value,
265 fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
266 fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
267 fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
268 fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
269 fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
271 fn set_personality_fn(&mut self, personality: Self::Value);
273 // These are used by everyone except msvc
274 fn cleanup_landing_pad(&mut self, ty: Self::Type, pers_fn: Self::Value) -> Self::Value;
275 fn resume(&mut self, exn: Self::Value);
277 // These are used only by msvc
278 fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
279 fn cleanup_ret(&mut self, funclet: &Self::Funclet, unwind: Option<Self::BasicBlock>);
280 fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
283 parent: Option<Self::Value>,
284 unwind: Option<Self::BasicBlock>,
285 handlers: &[Self::BasicBlock],
293 order: AtomicOrdering,
294 failure_order: AtomicOrdering,
302 order: AtomicOrdering,
304 fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
305 fn set_invariant_load(&mut self, load: Self::Value);
307 /// Called for `StorageLive`
308 fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
310 /// Called for `StorageDead`
311 fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
313 fn instrprof_increment(
315 fn_name: Self::Value,
317 num_counters: Self::Value,
324 fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
326 args: &[Self::Value],
327 funclet: Option<&Self::Funclet>,
329 fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
331 fn do_not_inline(&mut self, llret: Self::Value);