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 llvm::{SynchronizationScope, AsmDialect};
15 use rustc::ty::TyCtxt;
16 use rustc::ty::layout::{Align, Size};
17 use rustc::session::Session;
18 use builder::MemFlags;
24 pub struct OperandBundleDef<'a, Value : 'a> {
29 impl OperandBundleDef<'ll, &'ll Value> {
30 pub fn new(name: &'ll str, val: &'ll Value) -> Self {
38 pub enum IntPredicate {
52 pub enum RealPredicate {
71 pub enum AtomicRmwBinOp {
85 pub enum AtomicOrdering {
90 // Consume, // Not specified yet.
94 SequentiallyConsistent,
98 pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll,
104 cx: &'a CodegenCx<'ll, 'tcx, &'ll Value>,
108 fn with_cx(cx: &'a CodegenCx<'ll, 'tcx, &'ll Value>) -> Self;
109 fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
110 fn sess(&self) -> &Session;
111 fn cx(&self) -> &'a CodegenCx<'ll, 'tcx, &'ll Value>;
112 fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
113 fn llfn(&self) -> &'ll Value;
114 fn llbb(&self) -> &'ll BasicBlock;
115 fn count_insn(&self, category: &str);
117 fn set_value_name(&self, value: &'ll Value, name: &str);
118 fn position_at_end(&self, llbb: &'ll BasicBlock);
119 fn position_at_start(&self, llbb: &'ll BasicBlock);
121 fn ret(&self, v: &'ll Value);
122 fn br(&self, dest: &'ll BasicBlock);
126 then_llbb: &'ll BasicBlock,
127 else_llbb: &'ll BasicBlock,
132 else_llbb: &'ll BasicBlock,
139 then: &'ll BasicBlock,
140 catch: &'ll BasicBlock,
141 bundle: Option<&OperandBundleDef<'ll, &'ll Value>>
143 fn unreachable(&self);
144 fn add(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
145 fn fadd(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
146 fn fadd_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
147 fn sub(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
148 fn fsub(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
149 fn fsub_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
150 fn mul(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
151 fn fmul(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
152 fn fmul_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
153 fn udiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
154 fn exactudiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
155 fn sdiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
156 fn exactsdiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
157 fn fdiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
158 fn fdiv_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
159 fn urem(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
160 fn srem(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
161 fn frem(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
162 fn frem_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
163 fn shl(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
164 fn lshr(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
165 fn ashr(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
166 fn and(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
167 fn or(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
168 fn xor(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
169 fn neg(&self, v: &'ll Value) -> &'ll Value;
170 fn fneg(&self, v: &'ll Value) -> &'ll Value;
171 fn not(&self, v: &'ll Value) -> &'ll Value;
173 fn alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value;
174 fn dynamic_alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value;
183 fn load(&self, ptr: &'ll Value, align: Align) -> &'ll Value;
184 fn volatile_load(&self, ptr: &'ll Value) -> &'ll Value;
185 fn atomic_load(&self, ptr: &'ll Value, order: AtomicOrdering, size: Size) -> &'ll Value;
187 fn range_metadata(&self, load: &'ll Value, range: Range<u128>);
188 fn nonnull_metadata(&self, load: &'ll Value);
190 fn store(&self, val: &'ll Value, ptr: &'ll Value, align: Align) -> &'ll Value;
202 order: AtomicOrdering,
206 fn gep(&self, ptr: &'ll Value, indices: &[&'ll Value]) -> &'ll Value;
207 fn inbounds_gep(&self, ptr: &'ll Value, indices: &[&'ll Value]) -> &'ll Value;
208 fn struct_gep(&self, ptr: &'ll Value, idx: u64) -> &'ll Value;
210 fn trunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
211 fn sext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
212 fn fptoui(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
213 fn fptosi(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
214 fn uitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
215 fn sitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
216 fn fptrunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
217 fn fpext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
218 fn ptrtoint(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
219 fn inttoptr(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
220 fn bitcast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
221 fn intcast(&self, val: &'ll Value, dest_ty: &'ll Type, is_signed: bool) -> &'ll Value;
222 fn pointercast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
224 fn icmp(&self, op: IntPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
225 fn fcmp(&self, op: RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
227 fn empty_phi(&self, ty: &'ll Type) -> &'ll Value;
228 fn phi(&self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value;
233 inputs: &[&'ll Value],
238 ) -> Option<&'ll Value>;
241 fn memcpy(&self, dst: &'ll Value, dst_align: u64,
242 src: &'ll Value, src_align: u64,
243 size: &'ll Value, is_volatile: bool) -> &'ll Value;
244 fn memmove(&self, dst: &'ll Value, dst_align: u64,
245 src: &'ll Value, src_align: u64,
246 size: &'ll Value, is_volatile: bool) -> &'ll Value;
248 fn minnum(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
249 fn maxnum(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
251 &self, cond: &'ll Value,
252 then_val: &'ll Value,
253 else_val: &'ll Value,
256 fn va_arg(&self, list: &'ll Value, ty: &'ll Type) -> &'ll Value;
257 fn extract_element(&self, vec: &'ll Value, idx: &'ll Value) -> &'ll Value;
259 &self, vec: &'ll Value,
263 fn shuffle_vector(&self, v1: &'ll Value, v2: &'ll Value, mask: &'ll Value) -> &'ll Value;
264 fn vector_splat(&self, num_elts: usize, elt: &'ll Value) -> &'ll Value;
265 fn vector_reduce_fadd_fast(&self, acc: &'ll Value, src: &'ll Value) -> &'ll Value;
266 fn vector_reduce_fmul_fast(&self, acc: &'ll Value, src: &'ll Value) -> &'ll Value;
267 fn vector_reduce_add(&self, src: &'ll Value) -> &'ll Value;
268 fn vector_reduce_mul(&self, src: &'ll Value) -> &'ll Value;
269 fn vector_reduce_and(&self, src: &'ll Value) -> &'ll Value;
270 fn vector_reduce_or(&self, src: &'ll Value) -> &'ll Value;
271 fn vector_reduce_xor(&self, src: &'ll Value) -> &'ll Value;
272 fn vector_reduce_fmin(&self, src: &'ll Value) -> &'ll Value;
273 fn vector_reduce_fmax(&self, src: &'ll Value) -> &'ll Value;
274 fn vector_reduce_fmin_fast(&self, src: &'ll Value) -> &'ll Value;
275 fn vector_reduce_fmax_fast(&self, src: &'ll Value) -> &'ll Value;
276 fn vector_reduce_min(&self, src: &'ll Value, is_signed: bool) -> &'ll Value;
277 fn vector_reduce_max(&self, src: &'ll Value, is_signed: bool) -> &'ll Value;
278 fn extract_value(&self, agg_val: &'ll Value, idx: u64) -> &'ll Value;
292 fn add_clause(&self, landing_pad: &'ll Value, clause: &'ll Value);
293 fn set_cleanup(&self, landing_pad: &'ll Value);
294 fn resume(&self, exn: &'ll Value) -> &'ll Value;
297 parent: Option<&'ll Value>,
301 &self, cleanup: &'ll Value,
302 unwind: Option<&'ll BasicBlock>,
309 fn catch_ret(&self, pad: &'ll Value, unwind: &'ll BasicBlock) -> &'ll Value;
312 parent: Option<&'ll Value>,
313 unwind: Option<&'ll BasicBlock>,
316 fn add_handler(&self, catch_switch: &'ll Value, handler: &'ll BasicBlock);
317 fn set_personality_fn(&self, personality: &'ll Value);
324 order: AtomicOrdering,
325 failure_order: AtomicOrdering,
333 order: AtomicOrdering,
335 fn atomic_fence(&self, order: AtomicOrdering, scope: SynchronizationScope);
336 fn add_case(&self, s: &'ll Value, on_val: &'ll Value, dest: &'ll BasicBlock);
337 fn add_incoming_to_phi(&self, phi: &'ll Value, val: &'ll Value, bb: &'ll BasicBlock);
338 fn set_invariant_load(&self, load: &'ll Value);
349 args: &'b [&'ll Value]
350 ) -> Cow<'b, [&'ll Value]>;
351 fn lifetime_start(&self, ptr: &'ll Value, size: Size);
352 fn lifetime_end(&self, ptr: &'ll Value, size: Size);
354 fn call_lifetime_intrinsic(&self, intrinsic: &str, ptr: &'ll Value, size: Size);
356 fn call(&self, llfn: &'ll Value, args: &[&'ll Value],
357 bundle: Option<&OperandBundleDef<'ll, &'ll Value>>) -> &'ll Value;
358 fn zext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;