]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/traits.rs
Generalized SynchronisationScope for BuilderMethods
[rust.git] / src / librustc_codegen_llvm / traits.rs
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.
4 //
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.
10
11 use llvm::AsmDialect;
12 use common::*;
13 use type_::Type;
14 use libc::c_char;
15 use rustc::ty::TyCtxt;
16 use rustc::ty::layout::{Align, Size};
17 use rustc::session::Session;
18 use builder::MemFlags;
19 use value::Value;
20
21 use std::borrow::Cow;
22 use std::ops::Range;
23
24 pub struct OperandBundleDef<'a, Value : 'a> {
25     pub name: &'a str,
26     pub val: Value
27 }
28
29 impl OperandBundleDef<'ll, &'ll Value> {
30     pub fn new(name: &'ll str, val: &'ll Value) -> Self {
31         OperandBundleDef {
32             name,
33             val
34         }
35     }
36 }
37
38 pub enum IntPredicate {
39     IntEQ,
40     IntNE,
41     IntUGT,
42     IntUGE,
43     IntULT,
44     IntULE,
45     IntSGT,
46     IntSGE,
47     IntSLT,
48     IntSLE
49 }
50
51 #[allow(dead_code)]
52 pub enum RealPredicate {
53     RealPredicateFalse,
54     RealOEQ,
55     RealOGT,
56     RealOGE,
57     RealOLT,
58     RealOLE,
59     RealONE,
60     RealORD,
61     RealUNO,
62     RealUEQ,
63     RealUGT,
64     RealUGE,
65     RealULT,
66     RealULE,
67     RealUNE,
68     RealPredicateTrue
69 }
70
71 pub enum AtomicRmwBinOp {
72     AtomicXchg,
73     AtomicAdd,
74     AtomicSub,
75     AtomicAnd,
76     AtomicNand,
77     AtomicOr,
78     AtomicXor,
79     AtomicMax,
80     AtomicMin,
81     AtomicUMax,
82     AtomicUMin
83 }
84
85 pub enum AtomicOrdering {
86     #[allow(dead_code)]
87     NotAtomic,
88     Unordered,
89     Monotonic,
90     // Consume,  // Not specified yet.
91     Acquire,
92     Release,
93     AcquireRelease,
94     SequentiallyConsistent,
95 }
96
97 pub enum SynchronizationScope {
98     // FIXME: figure out if this variant is needed at all.
99     #[allow(dead_code)]
100     Other,
101     SingleThread,
102     CrossThread,
103 }
104
105
106 pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll,
107     Value : ?Sized,
108     BasicBlock: ?Sized
109     > {
110
111     fn new_block<'b>(
112         cx: &'a CodegenCx<'ll, 'tcx, &'ll Value>,
113         llfn: &'ll Value,
114         name: &'b str
115     ) -> Self;
116     fn with_cx(cx: &'a CodegenCx<'ll, 'tcx, &'ll Value>) -> Self;
117     fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
118     fn sess(&self) -> &Session;
119     fn cx(&self) -> &'a CodegenCx<'ll, 'tcx, &'ll Value>;
120     fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
121     fn llfn(&self) -> &'ll Value;
122     fn llbb(&self) -> &'ll BasicBlock;
123     fn count_insn(&self, category: &str);
124
125     fn set_value_name(&self, value: &'ll Value, name: &str);
126     fn position_at_end(&self, llbb: &'ll BasicBlock);
127     fn position_at_start(&self, llbb: &'ll BasicBlock);
128     fn ret_void(&self);
129     fn ret(&self, v: &'ll Value);
130     fn br(&self, dest: &'ll BasicBlock);
131     fn cond_br(
132         &self,
133         cond: &'ll Value,
134         then_llbb: &'ll BasicBlock,
135         else_llbb: &'ll BasicBlock,
136     );
137     fn switch(
138         &self,
139         v: &'ll Value,
140         else_llbb: &'ll BasicBlock,
141         num_cases: usize,
142     ) -> &'ll Value;
143     fn invoke(
144         &self,
145         llfn: &'ll Value,
146         args: &[&'ll Value],
147         then: &'ll BasicBlock,
148         catch: &'ll BasicBlock,
149         bundle: Option<&OperandBundleDef<'ll, &'ll Value>>
150     ) -> &'ll Value;
151     fn unreachable(&self);
152     fn add(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
153     fn fadd(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
154     fn fadd_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
155     fn sub(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
156     fn fsub(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
157     fn fsub_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
158     fn mul(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
159     fn fmul(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
160     fn fmul_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
161     fn udiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
162     fn exactudiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
163     fn sdiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
164     fn exactsdiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
165     fn fdiv(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
166     fn fdiv_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
167     fn urem(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
168     fn srem(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
169     fn frem(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
170     fn frem_fast(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
171     fn shl(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
172     fn lshr(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
173     fn ashr(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
174     fn and(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
175     fn or(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
176     fn xor(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
177     fn neg(&self, v: &'ll Value) -> &'ll Value;
178     fn fneg(&self, v: &'ll Value) -> &'ll Value;
179     fn not(&self, v: &'ll Value) -> &'ll Value;
180
181     fn alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value;
182     fn dynamic_alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value;
183     fn array_alloca(
184         &self,
185         ty: &'ll Type,
186         len: &'ll Value,
187         name: &str,
188         align: Align
189     ) -> &'ll Value;
190
191     fn load(&self, ptr: &'ll Value, align: Align) -> &'ll Value;
192     fn volatile_load(&self, ptr: &'ll Value) -> &'ll Value;
193     fn atomic_load(&self, ptr: &'ll Value, order: AtomicOrdering, size: Size) -> &'ll Value;
194
195     fn range_metadata(&self, load: &'ll Value, range: Range<u128>);
196     fn nonnull_metadata(&self, load: &'ll Value);
197
198     fn store(&self, val: &'ll Value, ptr: &'ll Value, align: Align) -> &'ll Value;
199     fn store_with_flags(
200         &self,
201         val: &'ll Value,
202         ptr: &'ll Value,
203         align: Align,
204         flags: MemFlags,
205     ) -> &'ll Value;
206     fn atomic_store(
207         &self,
208         val: &'ll Value,
209         ptr: &'ll Value,
210         order: AtomicOrdering,
211         size: Size
212     );
213
214     fn gep(&self, ptr: &'ll Value, indices: &[&'ll Value]) -> &'ll Value;
215     fn inbounds_gep(&self, ptr: &'ll Value, indices: &[&'ll Value]) -> &'ll Value;
216     fn struct_gep(&self, ptr: &'ll Value, idx: u64) -> &'ll Value;
217
218     fn trunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
219     fn sext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
220     fn fptoui(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
221     fn fptosi(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
222     fn uitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
223     fn sitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
224     fn fptrunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
225     fn fpext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
226     fn ptrtoint(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
227     fn inttoptr(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
228     fn bitcast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
229     fn intcast(&self, val: &'ll Value, dest_ty: &'ll Type, is_signed: bool) -> &'ll Value;
230     fn pointercast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
231
232     fn icmp(&self, op: IntPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
233     fn fcmp(&self, op: RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
234
235     fn empty_phi(&self, ty: &'ll Type) -> &'ll Value;
236     fn phi(&self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value;
237     fn inline_asm_call(
238         &self,
239         asm: *const c_char,
240         cons: *const c_char,
241         inputs: &[&'ll Value],
242         output: &'ll Type,
243         volatile: bool,
244         alignstack: bool,
245         dia: AsmDialect
246     ) -> Option<&'ll Value>;
247
248
249     fn memcpy(&self, dst: &'ll Value, dst_align: u64,
250                   src: &'ll Value, src_align: u64,
251                   size: &'ll Value, is_volatile: bool) -> &'ll Value;
252     fn memmove(&self, dst: &'ll Value, dst_align: u64,
253                   src: &'ll Value, src_align: u64,
254                   size: &'ll Value, is_volatile: bool) -> &'ll Value;
255
256     fn minnum(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
257     fn maxnum(&self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value;
258     fn select(
259         &self, cond: &'ll Value,
260         then_val: &'ll Value,
261         else_val: &'ll Value,
262     ) -> &'ll Value;
263
264     fn va_arg(&self, list: &'ll Value, ty: &'ll Type) -> &'ll Value;
265     fn extract_element(&self, vec: &'ll Value, idx: &'ll Value) -> &'ll Value;
266     fn insert_element(
267         &self, vec: &'ll Value,
268         elt: &'ll Value,
269         idx: &'ll Value,
270     ) -> &'ll Value;
271     fn shuffle_vector(&self, v1: &'ll Value, v2: &'ll Value, mask: &'ll Value) -> &'ll Value;
272     fn vector_splat(&self, num_elts: usize, elt: &'ll Value) -> &'ll Value;
273     fn vector_reduce_fadd_fast(&self, acc: &'ll Value, src: &'ll Value) -> &'ll Value;
274     fn vector_reduce_fmul_fast(&self, acc: &'ll Value, src: &'ll Value) -> &'ll Value;
275     fn vector_reduce_add(&self, src: &'ll Value) -> &'ll Value;
276     fn vector_reduce_mul(&self, src: &'ll Value) -> &'ll Value;
277     fn vector_reduce_and(&self, src: &'ll Value) -> &'ll Value;
278     fn vector_reduce_or(&self, src: &'ll Value) -> &'ll Value;
279     fn vector_reduce_xor(&self, src: &'ll Value) -> &'ll Value;
280     fn vector_reduce_fmin(&self, src: &'ll Value) -> &'ll Value;
281     fn vector_reduce_fmax(&self, src: &'ll Value) -> &'ll Value;
282     fn vector_reduce_fmin_fast(&self, src: &'ll Value) -> &'ll Value;
283     fn vector_reduce_fmax_fast(&self, src: &'ll Value) -> &'ll Value;
284     fn vector_reduce_min(&self, src: &'ll Value, is_signed: bool) -> &'ll Value;
285     fn vector_reduce_max(&self, src: &'ll Value, is_signed: bool) -> &'ll Value;
286     fn extract_value(&self, agg_val: &'ll Value, idx: u64) -> &'ll Value;
287     fn insert_value(
288         &self,
289         agg_val: &'ll Value,
290         elt: &'ll Value,
291         idx: u64
292     ) -> &'ll Value;
293
294     fn landing_pad(
295         &self,
296         ty: &'ll Type,
297         pers_fn: &'ll Value,
298         num_clauses: usize
299     ) -> &'ll Value;
300     fn add_clause(&self, landing_pad: &'ll Value, clause: &'ll Value);
301     fn set_cleanup(&self, landing_pad: &'ll Value);
302     fn resume(&self, exn: &'ll Value) -> &'ll Value;
303     fn cleanup_pad(
304         &self,
305         parent: Option<&'ll Value>,
306         args: &[&'ll Value]
307     ) -> &'ll Value;
308     fn cleanup_ret(
309         &self, cleanup: &'ll Value,
310         unwind: Option<&'ll BasicBlock>,
311     ) -> &'ll Value;
312     fn catch_pad(
313         &self,
314         parent: &'ll Value,
315         args: &[&'ll Value]
316     ) -> &'ll Value;
317     fn catch_ret(&self, pad: &'ll Value, unwind: &'ll BasicBlock) -> &'ll Value;
318     fn catch_switch(
319         &self,
320         parent: Option<&'ll Value>,
321         unwind: Option<&'ll BasicBlock>,
322         num_handlers: usize,
323     ) -> &'ll Value;
324     fn add_handler(&self, catch_switch: &'ll Value, handler: &'ll BasicBlock);
325     fn set_personality_fn(&self, personality: &'ll Value);
326
327     fn atomic_cmpxchg(
328         &self,
329         dst: &'ll Value,
330         cmp: &'ll Value,
331         src: &'ll Value,
332         order: AtomicOrdering,
333         failure_order: AtomicOrdering,
334         weak: bool,
335     ) -> &'ll Value;
336     fn atomic_rmw(
337         &self,
338         op: AtomicRmwBinOp,
339         dst: &'ll Value,
340         src: &'ll Value,
341         order: AtomicOrdering,
342     ) -> &'ll Value;
343     fn atomic_fence(&self, order: AtomicOrdering, scope: SynchronizationScope);
344     fn add_case(&self, s: &'ll Value, on_val: &'ll Value, dest: &'ll BasicBlock);
345     fn add_incoming_to_phi(&self, phi: &'ll Value, val: &'ll Value, bb: &'ll BasicBlock);
346     fn set_invariant_load(&self, load: &'ll Value);
347
348     fn check_store(
349         &self,
350         val: &'ll Value,
351         ptr: &'ll Value
352     ) -> &'ll Value;
353     fn check_call<'b>(
354         &self,
355         typ: &str,
356         llfn: &'ll Value,
357         args: &'b [&'ll Value]
358     ) -> Cow<'b, [&'ll Value]>;
359     fn lifetime_start(&self, ptr: &'ll Value, size: Size);
360     fn lifetime_end(&self, ptr: &'ll Value, size: Size);
361
362     fn call_lifetime_intrinsic(&self, intrinsic: &str, ptr: &'ll Value, size: Size);
363
364     fn call(&self, llfn: &'ll Value, args: &[&'ll Value],
365                 bundle: Option<&OperandBundleDef<'ll, &'ll Value>>) -> &'ll Value;
366     fn zext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value;
367 }