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