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