2018-09-20 13:47:22 +00:00
|
|
|
use super::abi::AbiBuilderMethods;
|
|
|
|
use super::asm::AsmBuilderMethods;
|
|
|
|
use super::debuginfo::DebugInfoBuilderMethods;
|
|
|
|
use super::intrinsic::IntrinsicCallMethods;
|
|
|
|
use super::type_::ArgTypeMethods;
|
2018-11-26 17:36:58 +00:00
|
|
|
use super::{HasCodegen, StaticBuilderMethods};
|
2019-02-09 14:31:47 +00:00
|
|
|
use crate::common::{AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate,
|
|
|
|
SynchronizationScope};
|
|
|
|
use crate::mir::operand::OperandRef;
|
|
|
|
use crate::mir::place::PlaceRef;
|
|
|
|
use crate::MemFlags;
|
2018-11-24 15:44:17 +00:00
|
|
|
use rustc::ty::Ty;
|
2019-05-04 09:32:22 +00:00
|
|
|
use rustc::ty::layout::{Align, Size, HasParamEnv};
|
2019-05-14 15:53:01 +00:00
|
|
|
use rustc_target::spec::{HasTargetSpec};
|
2018-08-07 15:14:40 +00:00
|
|
|
use std::ops::Range;
|
2019-03-29 16:23:52 +00:00
|
|
|
use std::iter::TrustedLen;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-11-24 15:44:17 +00:00
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub enum OverflowOp {
|
|
|
|
Add,
|
|
|
|
Sub,
|
|
|
|
Mul,
|
|
|
|
}
|
|
|
|
|
2019-06-14 16:39:39 +00:00
|
|
|
pub trait BuilderMethods<'a, 'tcx>:
|
2018-09-20 13:47:22 +00:00
|
|
|
HasCodegen<'tcx>
|
|
|
|
+ DebugInfoBuilderMethods<'tcx>
|
|
|
|
+ ArgTypeMethods<'tcx>
|
|
|
|
+ AbiBuilderMethods<'tcx>
|
|
|
|
+ IntrinsicCallMethods<'tcx>
|
|
|
|
+ AsmBuilderMethods<'tcx>
|
2019-06-11 09:49:10 +00:00
|
|
|
+ StaticBuilderMethods
|
2019-05-04 09:32:22 +00:00
|
|
|
+ HasParamEnv<'tcx>
|
2019-05-14 15:53:01 +00:00
|
|
|
+ HasTargetSpec
|
2019-05-04 09:32:22 +00:00
|
|
|
|
2018-09-20 13:47:22 +00:00
|
|
|
{
|
2019-10-13 09:28:19 +00:00
|
|
|
fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Function, name: &'b str) -> Self;
|
2018-09-07 01:31:42 +00:00
|
|
|
fn with_cx(cx: &'a Self::CodegenCx) -> Self;
|
2019-06-21 16:12:39 +00:00
|
|
|
fn build_sibling_block(&self, name: &str) -> Self;
|
2018-09-20 13:47:22 +00:00
|
|
|
fn cx(&self) -> &Self::CodegenCx;
|
2018-08-22 16:57:31 +00:00
|
|
|
fn llbb(&self) -> Self::BasicBlock;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-10-04 13:23:10 +00:00
|
|
|
fn position_at_end(&mut self, llbb: Self::BasicBlock);
|
|
|
|
fn ret_void(&mut self);
|
|
|
|
fn ret(&mut self, v: Self::Value);
|
|
|
|
fn br(&mut self, dest: Self::BasicBlock);
|
|
|
|
fn cond_br(
|
|
|
|
&mut self,
|
|
|
|
cond: Self::Value,
|
|
|
|
then_llbb: Self::BasicBlock,
|
|
|
|
else_llbb: Self::BasicBlock,
|
|
|
|
);
|
2018-10-05 13:08:49 +00:00
|
|
|
fn switch(
|
|
|
|
&mut self,
|
|
|
|
v: Self::Value,
|
|
|
|
else_llbb: Self::BasicBlock,
|
2019-03-29 16:23:52 +00:00
|
|
|
cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)> + TrustedLen,
|
2018-12-08 17:42:31 +00:00
|
|
|
);
|
2018-08-07 15:14:40 +00:00
|
|
|
fn invoke(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-08-22 16:57:31 +00:00
|
|
|
llfn: Self::Value,
|
|
|
|
args: &[Self::Value],
|
|
|
|
then: Self::BasicBlock,
|
|
|
|
catch: Self::BasicBlock,
|
2018-11-13 10:51:42 +00:00
|
|
|
funclet: Option<&Self::Funclet>,
|
2018-08-22 16:57:31 +00:00
|
|
|
) -> Self::Value;
|
2018-10-05 13:08:49 +00:00
|
|
|
fn unreachable(&mut self);
|
2018-12-08 17:42:31 +00:00
|
|
|
|
2018-10-05 13:08:49 +00:00
|
|
|
fn add(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn fadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn fadd_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn sub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn fsub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn fsub_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn mul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn fmul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn fmul_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn udiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn exactudiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn sdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn exactsdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn fdiv(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn fdiv_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn urem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn srem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn frem(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn frem_fast(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn shl(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn lshr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn ashr(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
2019-06-03 10:59:17 +00:00
|
|
|
fn unchecked_sadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn unchecked_uadd(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn unchecked_ssub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn unchecked_usub(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn unchecked_smul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn unchecked_umul(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
2018-10-05 13:08:49 +00:00
|
|
|
fn and(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn or(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn xor(&mut self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn neg(&mut self, v: Self::Value) -> Self::Value;
|
|
|
|
fn fneg(&mut self, v: Self::Value) -> Self::Value;
|
|
|
|
fn not(&mut self, v: Self::Value) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-11-24 15:44:17 +00:00
|
|
|
fn checked_binop(
|
|
|
|
&mut self,
|
|
|
|
oop: OverflowOp,
|
2019-02-25 07:52:46 +00:00
|
|
|
ty: Ty<'_>,
|
2018-11-24 15:44:17 +00:00
|
|
|
lhs: Self::Value,
|
|
|
|
rhs: Self::Value,
|
|
|
|
) -> (Self::Value, Self::Value);
|
|
|
|
|
2019-09-12 16:04:30 +00:00
|
|
|
fn alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value;
|
|
|
|
fn dynamic_alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
fn array_alloca(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-08-22 16:57:31 +00:00
|
|
|
ty: Self::Type,
|
|
|
|
len: Self::Value,
|
2018-09-08 22:16:45 +00:00
|
|
|
align: Align,
|
2018-08-22 16:57:31 +00:00
|
|
|
) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-09-08 22:16:45 +00:00
|
|
|
fn load(&mut self, ptr: Self::Value, align: Align) -> Self::Value;
|
2018-10-05 13:08:49 +00:00
|
|
|
fn volatile_load(&mut self, ptr: Self::Value) -> Self::Value;
|
|
|
|
fn atomic_load(&mut self, ptr: Self::Value, order: AtomicOrdering, size: Size) -> Self::Value;
|
|
|
|
fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
|
|
|
|
-> OperandRef<'tcx, Self::Value>;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-12-08 10:48:43 +00:00
|
|
|
/// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset.
|
|
|
|
fn write_operand_repeatedly(
|
|
|
|
self,
|
|
|
|
elem: OperandRef<'tcx, Self::Value>,
|
|
|
|
count: u64,
|
|
|
|
dest: PlaceRef<'tcx, Self::Value>,
|
|
|
|
) -> Self;
|
|
|
|
|
2018-10-05 13:08:49 +00:00
|
|
|
fn range_metadata(&mut self, load: Self::Value, range: Range<u128>);
|
|
|
|
fn nonnull_metadata(&mut self, load: Self::Value);
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-09-08 22:16:45 +00:00
|
|
|
fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
fn store_with_flags(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-08-22 16:57:31 +00:00
|
|
|
val: Self::Value,
|
|
|
|
ptr: Self::Value,
|
2018-09-08 22:16:45 +00:00
|
|
|
align: Align,
|
2018-08-07 15:14:40 +00:00
|
|
|
flags: MemFlags,
|
2018-08-22 16:57:31 +00:00
|
|
|
) -> Self::Value;
|
2018-10-05 13:08:49 +00:00
|
|
|
fn atomic_store(
|
|
|
|
&mut self,
|
|
|
|
val: Self::Value,
|
|
|
|
ptr: Self::Value,
|
|
|
|
order: AtomicOrdering,
|
|
|
|
size: Size,
|
|
|
|
);
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-10-05 13:08:49 +00:00
|
|
|
fn gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
|
|
|
|
fn inbounds_gep(&mut self, ptr: Self::Value, indices: &[Self::Value]) -> Self::Value;
|
|
|
|
fn struct_gep(&mut self, ptr: Self::Value, idx: u64) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-10-05 13:08:49 +00:00
|
|
|
fn trunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn sext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn fptoui(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn fptosi(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn uitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn sitofp(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn fptrunc(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn fpext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn ptrtoint(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn inttoptr(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn bitcast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
|
|
|
fn intcast(&mut self, val: Self::Value, dest_ty: Self::Type, is_signed: bool) -> Self::Value;
|
|
|
|
fn pointercast(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-10-05 13:08:49 +00:00
|
|
|
fn icmp(&mut self, op: IntPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
|
|
|
fn fcmp(&mut self, op: RealPredicate, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-09-13 12:58:19 +00:00
|
|
|
fn memcpy(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-09-13 12:58:19 +00:00
|
|
|
dst: Self::Value,
|
2018-09-08 22:16:45 +00:00
|
|
|
dst_align: Align,
|
2018-09-13 12:58:19 +00:00
|
|
|
src: Self::Value,
|
2018-09-08 22:16:45 +00:00
|
|
|
src_align: Align,
|
2018-09-13 12:58:19 +00:00
|
|
|
size: Self::Value,
|
|
|
|
flags: MemFlags,
|
|
|
|
);
|
|
|
|
fn memmove(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-09-13 12:58:19 +00:00
|
|
|
dst: Self::Value,
|
2018-09-08 22:16:45 +00:00
|
|
|
dst_align: Align,
|
2018-09-13 12:58:19 +00:00
|
|
|
src: Self::Value,
|
2018-09-08 22:16:45 +00:00
|
|
|
src_align: Align,
|
2018-09-13 12:58:19 +00:00
|
|
|
size: Self::Value,
|
|
|
|
flags: MemFlags,
|
|
|
|
);
|
2018-09-10 15:59:20 +00:00
|
|
|
fn memset(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-09-10 15:59:20 +00:00
|
|
|
ptr: Self::Value,
|
|
|
|
fill_byte: Self::Value,
|
|
|
|
size: Self::Value,
|
2018-09-08 22:16:45 +00:00
|
|
|
align: Align,
|
2018-09-10 15:59:20 +00:00
|
|
|
flags: MemFlags,
|
|
|
|
);
|
2018-08-07 15:14:40 +00:00
|
|
|
|
|
|
|
fn select(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-09-13 12:58:19 +00:00
|
|
|
cond: Self::Value,
|
2018-08-22 16:57:31 +00:00
|
|
|
then_val: Self::Value,
|
|
|
|
else_val: Self::Value,
|
|
|
|
) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-12-04 19:20:45 +00:00
|
|
|
fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
|
2018-10-05 13:08:49 +00:00
|
|
|
fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
|
|
|
|
fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
|
|
|
|
fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
|
|
|
|
fn insert_value(&mut self, agg_val: Self::Value, elt: Self::Value, idx: u64) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-10-05 13:08:49 +00:00
|
|
|
fn landing_pad(
|
|
|
|
&mut self,
|
|
|
|
ty: Self::Type,
|
|
|
|
pers_fn: Self::Value,
|
|
|
|
num_clauses: usize,
|
|
|
|
) -> Self::Value;
|
|
|
|
fn set_cleanup(&mut self, landing_pad: Self::Value);
|
|
|
|
fn resume(&mut self, exn: Self::Value) -> Self::Value;
|
|
|
|
fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
|
|
|
|
fn cleanup_ret(
|
|
|
|
&mut self,
|
|
|
|
funclet: &Self::Funclet,
|
|
|
|
unwind: Option<Self::BasicBlock>,
|
|
|
|
) -> Self::Value;
|
|
|
|
fn catch_pad(&mut self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
|
2018-08-07 15:14:40 +00:00
|
|
|
fn catch_switch(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-08-22 16:57:31 +00:00
|
|
|
parent: Option<Self::Value>,
|
|
|
|
unwind: Option<Self::BasicBlock>,
|
2018-08-07 15:14:40 +00:00
|
|
|
num_handlers: usize,
|
2018-08-22 16:57:31 +00:00
|
|
|
) -> Self::Value;
|
2018-10-05 13:08:49 +00:00
|
|
|
fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
|
|
|
|
fn set_personality_fn(&mut self, personality: Self::Value);
|
2018-08-07 15:14:40 +00:00
|
|
|
|
|
|
|
fn atomic_cmpxchg(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-08-22 16:57:31 +00:00
|
|
|
dst: Self::Value,
|
|
|
|
cmp: Self::Value,
|
|
|
|
src: Self::Value,
|
2018-08-07 15:14:40 +00:00
|
|
|
order: AtomicOrdering,
|
|
|
|
failure_order: AtomicOrdering,
|
2018-08-20 16:16:51 +00:00
|
|
|
weak: bool,
|
2018-08-22 16:57:31 +00:00
|
|
|
) -> Self::Value;
|
2018-08-07 15:14:40 +00:00
|
|
|
fn atomic_rmw(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-08-07 15:14:40 +00:00
|
|
|
op: AtomicRmwBinOp,
|
2018-08-22 16:57:31 +00:00
|
|
|
dst: Self::Value,
|
|
|
|
src: Self::Value,
|
2018-08-07 15:14:40 +00:00
|
|
|
order: AtomicOrdering,
|
2018-08-22 16:57:31 +00:00
|
|
|
) -> Self::Value;
|
2018-10-05 13:08:49 +00:00
|
|
|
fn atomic_fence(&mut self, order: AtomicOrdering, scope: SynchronizationScope);
|
|
|
|
fn set_invariant_load(&mut self, load: Self::Value);
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-11-24 15:36:41 +00:00
|
|
|
/// Called for `StorageLive`
|
2018-10-05 13:08:49 +00:00
|
|
|
fn lifetime_start(&mut self, ptr: Self::Value, size: Size);
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-11-24 15:36:41 +00:00
|
|
|
/// Called for `StorageDead`
|
|
|
|
fn lifetime_end(&mut self, ptr: Self::Value, size: Size);
|
2018-08-07 15:14:40 +00:00
|
|
|
|
2018-09-13 12:58:19 +00:00
|
|
|
fn call(
|
2018-10-05 13:08:49 +00:00
|
|
|
&mut self,
|
2018-09-13 12:58:19 +00:00
|
|
|
llfn: Self::Value,
|
|
|
|
args: &[Self::Value],
|
2018-11-13 10:51:42 +00:00
|
|
|
funclet: Option<&Self::Funclet>,
|
2018-09-13 12:58:19 +00:00
|
|
|
) -> Self::Value;
|
2018-10-05 13:08:49 +00:00
|
|
|
fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
2018-09-20 13:47:22 +00:00
|
|
|
|
2018-11-16 11:33:28 +00:00
|
|
|
unsafe fn delete_basic_block(&mut self, bb: Self::BasicBlock);
|
2018-10-05 13:08:49 +00:00
|
|
|
fn do_not_inline(&mut self, llret: Self::Value);
|
2018-08-07 15:14:40 +00:00
|
|
|
}
|