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.
13 use rustc::ty::TyCtxt;
14 use rustc::ty::layout::{Align, Size};
15 use rustc::session::Session;
16 use builder::MemFlags;
17 use super::backend::Backend;
21 use syntax::ast::AsmDialect;
25 pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll> : Backend {
28 cx: &'a CodegenCx<'ll, 'tcx, Self::Value>,
32 fn with_cx(cx: &'a CodegenCx<'ll, 'tcx, Self::Value>) -> Self;
33 fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
34 fn sess(&self) -> &Session;
35 fn cx(&self) -> &'a CodegenCx<'ll, 'tcx, Self::Value>;
36 fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
37 fn llfn(&self) -> Self::Value;
38 fn llbb(&self) -> Self::BasicBlock;
39 fn count_insn(&self, category: &str);
41 fn set_value_name(&self, value: Self::Value, name: &str);
42 fn position_at_end(&self, llbb: Self::BasicBlock);
43 fn position_at_start(&self, llbb: Self::BasicBlock);
45 fn ret(&self, v: Self::Value);
46 fn br(&self, dest: Self::BasicBlock);
50 then_llbb: Self::BasicBlock,
51 else_llbb: Self::BasicBlock,
56 else_llbb: Self::BasicBlock,
63 then: Self::BasicBlock,
64 catch: Self::BasicBlock,
65 bundle: Option<&OperandBundleDef<'ll, Self::Value>>
67 fn unreachable(&self);
68 fn add(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
69 fn fadd(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
70 fn fadd_fast(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
71 fn sub(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
72 fn fsub(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
73 fn fsub_fast(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
74 fn mul(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
75 fn fmul(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
76 fn fmul_fast(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
77 fn udiv(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
78 fn exactudiv(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
79 fn sdiv(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
80 fn exactsdiv(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
81 fn fdiv(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
82 fn fdiv_fast(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
83 fn urem(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
84 fn srem(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
85 fn frem(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
86 fn frem_fast(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
87 fn shl(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
88 fn lshr(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
89 fn ashr(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
90 fn and(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
91 fn or(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
92 fn xor(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
93 fn neg(&self, v: Self::Value) -> Self::Value;
94 fn fneg(&self, v: Self::Value) -> Self::Value;
95 fn not(&self, v: Self::Value) -> Self::Value;
97 fn alloca(&self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
98 fn dynamic_alloca(&self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
107 fn load(&self, ptr: Self::Value, align: Align) -> Self::Value;
108 fn volatile_load(&self, ptr: Self::Value) -> Self::Value;
109 fn atomic_load(&self, ptr: Self::Value, order: AtomicOrdering, size: Size) -> Self::Value;
111 fn range_metadata(&self, load: Self::Value, range: Range<u128>);
112 fn nonnull_metadata(&self, load: Self::Value);
114 fn store(&self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
126 order: AtomicOrdering,
130 fn gep(&self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
131 fn inbounds_gep(&self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
132 fn struct_gep(&self, ptr: Self::Value, idx: u64) -> Self::Value;
134 fn trunc(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
135 fn sext(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
136 fn fptoui(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
137 fn fptosi(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
138 fn uitofp(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
139 fn sitofp(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
140 fn fptrunc(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
141 fn fpext(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
142 fn ptrtoint(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
143 fn inttoptr(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
144 fn bitcast(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
145 fn intcast(&self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
146 fn pointercast(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
148 fn icmp(&self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
149 fn fcmp(&self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
151 fn empty_phi(&self, ty: Self::Type) -> Self::Value;
152 fn phi(&self, ty: Self::Type, vals: &[Self::Value], bbs: &[Self::BasicBlock]) -> Self::Value;
157 inputs: &[Self::Value],
162 ) -> Option<Self::Value>;
165 fn memcpy(&self, dst: Self::Value, dst_align: u64,
166 src: Self::Value, src_align: u64,
167 size: Self::Value, is_volatile: bool) -> Self::Value;
168 fn memmove(&self, dst: Self::Value, dst_align: u64,
169 src: Self::Value, src_align: u64,
170 size: Self::Value, is_volatile: bool) -> Self::Value;
172 fn minnum(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
173 fn maxnum(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
175 &self, cond: Self::Value,
176 then_val: Self::Value,
177 else_val: Self::Value,
180 fn va_arg(&self, list: Self::Value, ty: Self::Type) -> Self::Value;
181 fn extract_element(&self, vec: Self::Value, idx: Self::Value) -> Self::Value;
183 &self, vec: Self::Value,
187 fn shuffle_vector(&self, v1: Self::Value, v2: Self::Value, mask: Self::Value) -> Self::Value;
188 fn vector_splat(&self, num_elts: usize, elt: Self::Value) -> Self::Value;
189 fn vector_reduce_fadd_fast(&self, acc: Self::Value, src: Self::Value) -> Self::Value;
190 fn vector_reduce_fmul_fast(&self, acc: Self::Value, src: Self::Value) -> Self::Value;
191 fn vector_reduce_add(&self, src: Self::Value) -> Self::Value;
192 fn vector_reduce_mul(&self, src: Self::Value) -> Self::Value;
193 fn vector_reduce_and(&self, src: Self::Value) -> Self::Value;
194 fn vector_reduce_or(&self, src: Self::Value) -> Self::Value;
195 fn vector_reduce_xor(&self, src: Self::Value) -> Self::Value;
196 fn vector_reduce_fmin(&self, src: Self::Value) -> Self::Value;
197 fn vector_reduce_fmax(&self, src: Self::Value) -> Self::Value;
198 fn vector_reduce_fmin_fast(&self, src: Self::Value) -> Self::Value;
199 fn vector_reduce_fmax_fast(&self, src: Self::Value) -> Self::Value;
200 fn vector_reduce_min(&self, src: Self::Value, is_signed: bool) -> Self::Value;
201 fn vector_reduce_max(&self, src: Self::Value, is_signed: bool) -> Self::Value;
202 fn extract_value(&self, agg_val: Self::Value, idx: u64) -> Self::Value;
205 agg_val: Self::Value,
213 pers_fn: Self::Value,
216 fn add_clause(&self, landing_pad: Self::Value, clause: Self::Value);
217 fn set_cleanup(&self, landing_pad: Self::Value);
218 fn resume(&self, exn: Self::Value) -> Self::Value;
221 parent: Option<Self::Value>,
225 &self, cleanup: Self::Value,
226 unwind: Option<Self::BasicBlock>,
233 fn catch_ret(&self, pad: Self::Value, unwind: Self::BasicBlock) -> Self::Value;
236 parent: Option<Self::Value>,
237 unwind: Option<Self::BasicBlock>,
240 fn add_handler(&self, catch_switch: Self::Value, handler: Self::BasicBlock);
241 fn set_personality_fn(&self, personality: Self::Value);
248 order: AtomicOrdering,
249 failure_order: AtomicOrdering,
257 order: AtomicOrdering,
259 fn atomic_fence(&self, order: AtomicOrdering, scope: SynchronizationScope);
260 fn add_case(&self, s: Self::Value, on_val: Self::Value, dest: Self::BasicBlock);
261 fn add_incoming_to_phi(&self, phi: Self::Value, val: Self::Value, bb: Self::BasicBlock);
262 fn set_invariant_load(&self, load: Self::Value);
273 args: &'b [Self::Value]
274 ) -> Cow<'b, [Self::Value]> where [Self::Value] : ToOwned;
275 fn lifetime_start(&self, ptr: Self::Value, size: Size);
276 fn lifetime_end(&self, ptr: Self::Value, size: Size);
278 fn call_lifetime_intrinsic(&self, intrinsic: &str, ptr: Self::Value, size: Size);
280 fn call(&self, llfn: Self::Value, args: &[Self::Value],
281 bundle: Option<&OperandBundleDef<'ll, Self::Value>>) -> Self::Value;
282 fn zext(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;