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