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