]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_ssa/traits/builder.rs
typeck: remove redundant diverges code
[rust.git] / src / librustc_codegen_ssa / traits / builder.rs
1 use super::abi::AbiBuilderMethods;
2 use super::asm::AsmBuilderMethods;
3 use super::debuginfo::DebugInfoBuilderMethods;
4 use super::intrinsic::IntrinsicCallMethods;
5 use super::type_::ArgAbiMethods;
6 use super::{HasCodegen, StaticBuilderMethods};
7
8 use crate::common::{
9     AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope,
10 };
11 use crate::mir::operand::OperandRef;
12 use crate::mir::place::PlaceRef;
13 use crate::MemFlags;
14
15 use rustc::ty::layout::{Align, HasParamEnv, Size};
16 use rustc::ty::Ty;
17 use rustc_target::spec::HasTargetSpec;
18
19 use std::iter::TrustedLen;
20 use std::ops::Range;
21
22 #[derive(Copy, Clone)]
23 pub enum OverflowOp {
24     Add,
25     Sub,
26     Mul,
27 }
28
29 pub trait BuilderMethods<'a, 'tcx>:
30     HasCodegen<'tcx>
31     + DebugInfoBuilderMethods<'tcx>
32     + ArgAbiMethods<'tcx>
33     + AbiBuilderMethods<'tcx>
34     + IntrinsicCallMethods<'tcx>
35     + AsmBuilderMethods<'tcx>
36     + StaticBuilderMethods
37     + HasParamEnv<'tcx>
38     + HasTargetSpec
39 {
40     fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Function, name: &'b str) -> Self;
41     fn with_cx(cx: &'a Self::CodegenCx) -> Self;
42     fn build_sibling_block(&self, name: &str) -> Self;
43     fn cx(&self) -> &Self::CodegenCx;
44     fn llbb(&self) -> Self::BasicBlock;
45
46     fn position_at_end(&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         cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)> + TrustedLen,
61     );
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
72     fn add(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
73     fn fadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
74     fn fadd_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
75     fn sub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
76     fn fsub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
77     fn fsub_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
78     fn mul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
79     fn fmul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
80     fn fmul_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
81     fn udiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
82     fn exactudiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
83     fn sdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
84     fn exactsdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
85     fn fdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
86     fn fdiv_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
87     fn urem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
88     fn srem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
89     fn frem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
90     fn frem_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
91     fn shl(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
92     fn lshr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
93     fn ashr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
94     fn unchecked_sadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
95     fn unchecked_uadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
96     fn unchecked_ssub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
97     fn unchecked_usub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
98     fn unchecked_smul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
99     fn unchecked_umul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
100     fn and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
101     fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
102     fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
103     fn neg(&mut self, v: Self::Value) -> Self::Value;
104     fn fneg(&mut self, v: Self::Value) -> Self::Value;
105     fn not(&mut self, v: Self::Value) -> Self::Value;
106
107     fn checked_binop(
108         &mut self,
109         oop: OverflowOp,
110         ty: Ty<'_>,
111         lhs: Self::Value,
112         rhs: Self::Value,
113     ) -> (Self::Value, Self::Value);
114
115     fn alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value;
116     fn dynamic_alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value;
117     fn array_alloca(&mut self, ty: Self::Type, len: Self::Value, align: Align) -> Self::Value;
118
119     fn load(&mut self, ptr: Self::Value, align: Align) -> Self::Value;
120     fn volatile_load(&mut self, ptr: Self::Value) -> Self::Value;
121     fn atomic_load(&mut self, ptr: Self::Value, order: AtomicOrdering, size: Size) -> Self::Value;
122     fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
123     -> OperandRef<'tcx, Self::Value>;
124
125     /// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset.
126     fn write_operand_repeatedly(
127         self,
128         elem: OperandRef<'tcx, Self::Value>,
129         count: u64,
130         dest: PlaceRef<'tcx, Self::Value>,
131     ) -> Self;
132
133     fn range_metadata(&mut self, load: Self::Value, range: Range<u128>);
134     fn nonnull_metadata(&mut self, load: Self::Value);
135
136     fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
137     fn store_with_flags(
138         &mut self,
139         val: Self::Value,
140         ptr: Self::Value,
141         align: Align,
142         flags: MemFlags,
143     ) -> Self::Value;
144     fn atomic_store(
145         &mut self,
146         val: Self::Value,
147         ptr: Self::Value,
148         order: AtomicOrdering,
149         size: Size,
150     );
151
152     fn gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
153     fn inbounds_gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
154     fn struct_gep(&mut self, ptr: Self::Value, idx: u64) -> Self::Value;
155
156     fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
157     fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
158     fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
159     fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
160     fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
161     fn sitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
162     fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
163     fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
164     fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
165     fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
166     fn bitcast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
167     fn intcast(&mut self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
168     fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
169
170     fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
171     fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
172
173     fn memcpy(
174         &mut self,
175         dst: Self::Value,
176         dst_align: Align,
177         src: Self::Value,
178         src_align: Align,
179         size: Self::Value,
180         flags: MemFlags,
181     );
182     fn memmove(
183         &mut self,
184         dst: Self::Value,
185         dst_align: Align,
186         src: Self::Value,
187         src_align: Align,
188         size: Self::Value,
189         flags: MemFlags,
190     );
191     fn memset(
192         &mut self,
193         ptr: Self::Value,
194         fill_byte: Self::Value,
195         size: Self::Value,
196         align: Align,
197         flags: MemFlags,
198     );
199
200     fn select(
201         &mut self,
202         cond: Self::Value,
203         then_val: Self::Value,
204         else_val: Self::Value,
205     ) -> Self::Value;
206
207     fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
208     fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
209     fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
210     fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
211     fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
212
213     fn landing_pad(
214         &mut self,
215         ty: Self::Type,
216         pers_fn: Self::Value,
217         num_clauses: usize,
218     ) -> Self::Value;
219     fn set_cleanup(&mut self, landing_pad: Self::Value);
220     fn resume(&mut self, exn: Self::Value) -> Self::Value;
221     fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
222     fn cleanup_ret(
223         &mut self,
224         funclet: &Self::Funclet,
225         unwind: Option<Self::BasicBlock>,
226     ) -> Self::Value;
227     fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
228     fn catch_switch(
229         &mut self,
230         parent: Option<Self::Value>,
231         unwind: Option<Self::BasicBlock>,
232         num_handlers: usize,
233     ) -> Self::Value;
234     fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
235     fn set_personality_fn(&mut self, personality: Self::Value);
236
237     fn atomic_cmpxchg(
238         &mut self,
239         dst: Self::Value,
240         cmp: Self::Value,
241         src: Self::Value,
242         order: AtomicOrdering,
243         failure_order: AtomicOrdering,
244         weak: bool,
245     ) -> Self::Value;
246     fn atomic_rmw(
247         &mut self,
248         op: AtomicRmwBinOp,
249         dst: Self::Value,
250         src: Self::Value,
251         order: AtomicOrdering,
252     ) -> Self::Value;
253     fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
254     fn set_invariant_load(&mut self, load: Self::Value);
255
256     /// Called for `StorageLive`
257     fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
258
259     /// Called for `StorageDead`
260     fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
261
262     fn call(
263         &mut self,
264         llfn: Self::Value,
265         args: &[Self::Value],
266         funclet: Option<&Self::Funclet>,
267     ) -> Self::Value;
268     fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
269
270     unsafe fn delete_basic_block(&mut self, bb: Self::BasicBlock);
271     fn do_not_inline(&mut self, llret: Self::Value);
272 }