1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use super::abi::AbiBuilderMethods;
12 use super::asm::AsmBuilderMethods;
13 use super::debuginfo::DebugInfoBuilderMethods;
14 use super::intrinsic::IntrinsicCallMethods;
15 use super::type_::ArgTypeMethods;
16 use super::HasCodegen;
17 use common::{AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope};
19 use mir::operand::OperandRef;
20 use mir::place::PlaceRef;
21 use rustc::ty::layout::{Align, Size};
26 use syntax::ast::AsmDialect;
28 pub trait BuilderMethods<'a, 'tcx: 'a>:
30 + DebugInfoBuilderMethods<'tcx>
31 + ArgTypeMethods<'tcx>
32 + AbiBuilderMethods<'tcx>
33 + IntrinsicCallMethods<'tcx>
34 + AsmBuilderMethods<'tcx>
36 fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Value, name: &'b str) -> Self;
37 fn with_cx(cx: &'a Self::CodegenCx) -> Self;
38 fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
39 fn cx(&self) -> &Self::CodegenCx;
40 fn llfn(&self) -> Self::Value;
41 fn llbb(&self) -> Self::BasicBlock;
42 fn count_insn(&self, category: &str);
44 fn set_value_name(&mut self, value: Self::Value, name: &str);
45 fn position_at_end(&mut self, llbb: Self::BasicBlock);
46 fn position_at_start(&mut self, llbb: Self::BasicBlock);
47 fn ret_void(&mut self);
48 fn ret(&mut self, v: Self::Value);
49 fn br(&mut self, dest: Self::BasicBlock);
53 then_llbb: Self::BasicBlock,
54 else_llbb: Self::BasicBlock,
59 else_llbb: Self::BasicBlock,
66 then: Self::BasicBlock,
67 catch: Self::BasicBlock,
68 funclet: Option<&Self::Funclet>,
70 fn unreachable(&mut self);
71 fn add(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
72 fn fadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
73 fn fadd_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
74 fn sub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
75 fn fsub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
76 fn fsub_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
77 fn mul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
78 fn fmul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
79 fn fmul_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
80 fn udiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
81 fn exactudiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
82 fn sdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
83 fn exactsdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
84 fn fdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
85 fn fdiv_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
86 fn urem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
87 fn srem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
88 fn frem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
89 fn frem_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
90 fn shl(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
91 fn lshr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
92 fn ashr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
93 fn and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
94 fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
95 fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
96 fn neg(&mut self, v: Self::Value) -> Self::Value;
97 fn fneg(&mut self, v: Self::Value) -> Self::Value;
98 fn not(&mut self, v: Self::Value) -> Self::Value;
100 fn alloca(&mut self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
101 fn dynamic_alloca(&mut self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
110 fn load(&mut self, ptr: Self::Value, align: Align) -> Self::Value;
111 fn volatile_load(&mut self, ptr: Self::Value) -> Self::Value;
112 fn atomic_load(&mut self, ptr: Self::Value, order: AtomicOrdering, size: Size) -> Self::Value;
113 fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
114 -> OperandRef<'tcx, Self::Value>;
116 fn range_metadata(&mut self, load: Self::Value, range: Range<u128>);
117 fn nonnull_metadata(&mut self, load: Self::Value);
119 fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
131 order: AtomicOrdering,
135 fn gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
136 fn inbounds_gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
137 fn struct_gep(&mut self, ptr: Self::Value, idx: u64) -> Self::Value;
139 fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
140 fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
141 fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
142 fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
143 fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
144 fn sitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
145 fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
146 fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
147 fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
148 fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
149 fn bitcast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
150 fn intcast(&mut self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
151 fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
153 fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
154 fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
156 fn empty_phi(&mut self, ty: Self::Type) -> Self::Value;
160 vals: &[Self::Value],
161 bbs: &[Self::BasicBlock],
167 inputs: &[Self::Value],
172 ) -> Option<Self::Value>;
195 fill_byte: Self::Value,
201 fn minnum(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
202 fn maxnum(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
206 then_val: Self::Value,
207 else_val: Self::Value,
210 fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
211 fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
224 fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
225 fn vector_reduce_fadd_fast(&mut self, acc: Self::Value, src: Self::Value) -> Self::Value;
226 fn vector_reduce_fmul_fast(&mut self, acc: Self::Value, src: Self::Value) -> Self::Value;
227 fn vector_reduce_add(&mut self, src: Self::Value) -> Self::Value;
228 fn vector_reduce_mul(&mut self, src: Self::Value) -> Self::Value;
229 fn vector_reduce_and(&mut self, src: Self::Value) -> Self::Value;
230 fn vector_reduce_or(&mut self, src: Self::Value) -> Self::Value;
231 fn vector_reduce_xor(&mut self, src: Self::Value) -> Self::Value;
232 fn vector_reduce_fmin(&mut self, src: Self::Value) -> Self::Value;
233 fn vector_reduce_fmax(&mut self, src: Self::Value) -> Self::Value;
234 fn vector_reduce_fmin_fast(&mut self, src: Self::Value) -> Self::Value;
235 fn vector_reduce_fmax_fast(&mut self, src: Self::Value) -> Self::Value;
236 fn vector_reduce_min(&mut self, src: Self::Value, is_signed: bool) -> Self::Value;
237 fn vector_reduce_max(&mut self, src: Self::Value, is_signed: bool) -> Self::Value;
238 fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
239 fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
244 pers_fn: Self::Value,
247 fn add_clause(&mut self, landing_pad: Self::Value, clause: Self::Value);
248 fn set_cleanup(&mut self, landing_pad: Self::Value);
249 fn resume(&mut self, exn: Self::Value) -> Self::Value;
250 fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
253 funclet: &Self::Funclet,
254 unwind: Option<Self::BasicBlock>,
256 fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
257 fn catch_ret(&mut self, funclet: &Self::Funclet, unwind: Self::BasicBlock) -> Self::Value;
260 parent: Option<Self::Value>,
261 unwind: Option<Self::BasicBlock>,
264 fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
265 fn set_personality_fn(&mut self, personality: Self::Value);
272 order: AtomicOrdering,
273 failure_order: AtomicOrdering,
281 order: AtomicOrdering,
283 fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
284 fn add_case(&mut self, s: Self::Value, on_val: Self::Value, dest: Self::BasicBlock);
285 fn add_incoming_to_phi(&mut self, phi: Self::Value, val: Self::Value, bb: Self::BasicBlock);
286 fn set_invariant_load(&mut self, load: Self::Value);
288 /// Returns the ptr value that should be used for storing `val`.
289 fn check_store(&mut self, val: Self::Value, ptr: Self::Value) -> Self::Value;
291 /// Returns the args that should be used for a call to `llfn`.
296 args: &'b [Self::Value],
297 ) -> Cow<'b, [Self::Value]>
299 [Self::Value]: ToOwned;
300 fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
301 fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
303 /// If LLVM lifetime intrinsic support is enabled (i.e. optimizations
304 /// on), and `ptr` is nonzero-sized, then extracts the size of `ptr`
305 /// and the intrinsic for `lt` and passes them to `emit`, which is in
306 /// charge of generating code to call the passed intrinsic on whatever
307 /// block of generated code is targeted for the intrinsic.
309 /// If LLVM lifetime intrinsic support is disabled (i.e. optimizations
310 /// off) or `ptr` is zero-sized, then no-op (does not call `emit`).
311 fn call_lifetime_intrinsic(&mut self, intrinsic: &str, ptr: Self::Value, size: Size);
316 args: &[Self::Value],
317 funclet: Option<&Self::Funclet>,
319 fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
321 fn delete_basic_block(&mut self, bb: Self::BasicBlock);
322 fn do_not_inline(&mut self, llret: Self::Value);