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