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};
10 AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope,
12 use crate::mir::operand::OperandRef;
13 use crate::mir::place::PlaceRef;
16 use rustc_middle::ty::layout::{HasParamEnv, TyAndLayout};
17 use rustc_middle::ty::Ty;
19 use rustc_target::abi::{Abi, Align, Scalar, Size, WrappingRange};
20 use rustc_target::spec::HasTargetSpec;
22 #[derive(Copy, Clone)]
29 pub trait BuilderMethods<'a, 'tcx>:
31 + CoverageInfoBuilderMethods<'tcx>
32 + DebugInfoBuilderMethods
34 + AbiBuilderMethods<'tcx>
35 + IntrinsicCallMethods<'tcx>
36 + AsmBuilderMethods<'tcx>
37 + StaticBuilderMethods
41 fn build(cx: &'a Self::CodegenCx, llbb: Self::BasicBlock) -> Self;
43 fn cx(&self) -> &Self::CodegenCx;
44 fn llbb(&self) -> Self::BasicBlock;
46 fn set_span(&mut self, span: Span);
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;
51 fn append_sibling_block(&mut self, name: &str) -> Self::BasicBlock;
53 // FIXME(eddyb) replace with callers using `append_sibling_block`.
54 fn build_sibling_block(&mut self, name: &str) -> Self;
56 fn ret_void(&mut self);
57 fn ret(&mut self, v: Self::Value);
58 fn br(&mut self, dest: Self::BasicBlock);
62 then_llbb: Self::BasicBlock,
63 else_llbb: Self::BasicBlock,
68 else_llbb: Self::BasicBlock,
69 cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)>,
76 then: Self::BasicBlock,
77 catch: Self::BasicBlock,
78 funclet: Option<&Self::Funclet>,
80 fn unreachable(&mut self);
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;
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;
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;
123 ) -> (Self::Value, Self::Value);
125 fn from_immediate(&mut self, val: Self::Value) -> Self::Value;
126 fn to_immediate(&mut self, val: Self::Value, layout: TyAndLayout<'_>) -> Self::Value {
127 if let Abi::Scalar(scalar) = layout.abi {
128 self.to_immediate_scalar(val, scalar)
133 fn to_immediate_scalar(&mut self, val: Self::Value, scalar: Scalar) -> Self::Value;
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;
137 fn array_alloca(&mut self, ty: Self::Type, len: Self::Value, align: Align) -> Self::Value;
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;
145 order: AtomicOrdering,
148 fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
149 -> OperandRef<'tcx, Self::Value>;
151 /// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset.
152 fn write_operand_repeatedly(
154 elem: OperandRef<'tcx, Self::Value>,
156 dest: PlaceRef<'tcx, Self::Value>,
159 fn range_metadata(&mut self, load: Self::Value, range: WrappingRange);
160 fn nonnull_metadata(&mut self, load: Self::Value);
162 fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
174 order: AtomicOrdering,
178 fn gep(&mut self, ty: Self::Type, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
183 indices: &[Self::Value],
185 fn struct_gep(&mut self, ty: Self::Type, ptr: Self::Value, idx: u64) -> Self::Value;
187 fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
188 fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
189 fn fptoui_sat(&mut self, val: Self::Value, dest_ty: Self::Type) -> Option<Self::Value>;
190 fn fptosi_sat(&mut self, val: Self::Value, dest_ty: Self::Type) -> Option<Self::Value>;
191 fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
192 fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
193 fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
194 fn sitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
195 fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
196 fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
197 fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
198 fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
199 fn bitcast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
200 fn intcast(&mut self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
201 fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
203 fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
204 fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
227 fill_byte: Self::Value,
236 then_val: Self::Value,
237 else_val: Self::Value,
240 fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
241 fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
242 fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
243 fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
244 fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
249 pers_fn: Self::Value,
252 fn set_cleanup(&mut self, landing_pad: Self::Value);
253 fn resume(&mut self, exn: Self::Value) -> Self::Value;
254 fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
257 funclet: &Self::Funclet,
258 unwind: Option<Self::BasicBlock>,
260 fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
263 parent: Option<Self::Value>,
264 unwind: Option<Self::BasicBlock>,
267 fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
268 fn set_personality_fn(&mut self, personality: Self::Value);
275 order: AtomicOrdering,
276 failure_order: AtomicOrdering,
284 order: AtomicOrdering,
286 fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
287 fn set_invariant_load(&mut self, load: Self::Value);
289 /// Called for `StorageLive`
290 fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
292 /// Called for `StorageDead`
293 fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
295 fn instrprof_increment(
297 fn_name: Self::Value,
299 num_counters: Self::Value,
307 args: &[Self::Value],
308 funclet: Option<&Self::Funclet>,
310 fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
312 fn do_not_inline(&mut self, llret: Self::Value);