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