2020-04-03 04:54:18 -05:00
|
|
|
use rustc_target::abi::{Integer, Primitive};
|
2018-11-07 06:29:38 -06:00
|
|
|
use rustc_target::spec::{HasTargetSpec, Target};
|
2020-01-04 06:23:42 -06:00
|
|
|
use rustc_index::vec::IndexVec;
|
2018-06-22 12:18:53 -05:00
|
|
|
|
2019-12-24 05:40:18 -06:00
|
|
|
use cranelift_codegen::ir::{InstructionData, Opcode, ValueDef};
|
2018-06-22 12:18:53 -05:00
|
|
|
|
2018-07-30 09:57:40 -05:00
|
|
|
use crate::prelude::*;
|
2018-06-22 12:18:53 -05:00
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn mir_var(loc: Local) -> Variable {
|
2018-08-15 05:36:13 -05:00
|
|
|
Variable::with_u32(loc.index() as u32)
|
2018-06-22 12:18:53 -05:00
|
|
|
}
|
|
|
|
|
2020-04-05 06:48:26 -05:00
|
|
|
pub(crate) fn pointer_ty(tcx: TyCtxt<'_>) -> types::Type {
|
2018-08-18 10:10:02 -05:00
|
|
|
match tcx.data_layout.pointer_size.bits() {
|
|
|
|
16 => types::I16,
|
|
|
|
32 => types::I32,
|
|
|
|
64 => types::I64,
|
|
|
|
bits => bug!("ptr_sized_integer: unknown pointer bit size {}", bits),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 06:48:26 -05:00
|
|
|
pub(crate) fn scalar_to_clif_type(tcx: TyCtxt<'_>, scalar: Scalar) -> Type {
|
2019-08-30 04:58:52 -05:00
|
|
|
match scalar.value {
|
|
|
|
Primitive::Int(int, _sign) => match int {
|
|
|
|
Integer::I8 => types::I8,
|
|
|
|
Integer::I16 => types::I16,
|
|
|
|
Integer::I32 => types::I32,
|
|
|
|
Integer::I64 => types::I64,
|
|
|
|
Integer::I128 => types::I128,
|
|
|
|
},
|
2019-11-09 04:14:18 -06:00
|
|
|
Primitive::F32 => types::F32,
|
|
|
|
Primitive::F64 => types::F64,
|
2019-08-30 04:58:52 -05:00
|
|
|
Primitive::Pointer => pointer_ty(tcx),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-14 10:11:06 -06:00
|
|
|
fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types::Type> {
|
2019-09-28 04:13:40 -05:00
|
|
|
Some(match ty.kind {
|
2018-08-24 07:51:02 -05:00
|
|
|
ty::Bool => types::I8,
|
|
|
|
ty::Uint(size) => match size {
|
2018-07-31 05:25:16 -05:00
|
|
|
UintTy::U8 => types::I8,
|
|
|
|
UintTy::U16 => types::I16,
|
|
|
|
UintTy::U32 => types::I32,
|
|
|
|
UintTy::U64 => types::I64,
|
2019-06-12 13:54:38 -05:00
|
|
|
UintTy::U128 => types::I128,
|
2018-08-18 10:10:02 -05:00
|
|
|
UintTy::Usize => pointer_ty(tcx),
|
2018-07-31 05:25:16 -05:00
|
|
|
},
|
2018-08-24 07:51:02 -05:00
|
|
|
ty::Int(size) => match size {
|
2018-07-31 05:25:16 -05:00
|
|
|
IntTy::I8 => types::I8,
|
|
|
|
IntTy::I16 => types::I16,
|
|
|
|
IntTy::I32 => types::I32,
|
|
|
|
IntTy::I64 => types::I64,
|
2019-06-12 13:54:38 -05:00
|
|
|
IntTy::I128 => types::I128,
|
2018-08-22 05:31:45 -05:00
|
|
|
IntTy::Isize => pointer_ty(tcx),
|
2018-07-31 05:25:16 -05:00
|
|
|
},
|
2018-08-24 07:51:02 -05:00
|
|
|
ty::Char => types::I32,
|
|
|
|
ty::Float(size) => match size {
|
2018-08-08 03:26:25 -05:00
|
|
|
FloatTy::F32 => types::F32,
|
|
|
|
FloatTy::F64 => types::F64,
|
2018-07-31 05:25:16 -05:00
|
|
|
},
|
2018-08-24 07:51:02 -05:00
|
|
|
ty::FnPtr(_) => pointer_ty(tcx),
|
2019-09-14 10:53:36 -05:00
|
|
|
ty::RawPtr(TypeAndMut { ty: pointee_ty, mutbl: _ }) | ty::Ref(_, pointee_ty, _) => {
|
|
|
|
if has_ptr_meta(tcx, pointee_ty) {
|
2018-07-14 09:39:49 -05:00
|
|
|
return None;
|
2019-09-14 10:53:36 -05:00
|
|
|
} else {
|
|
|
|
pointer_ty(tcx)
|
2018-07-14 09:39:49 -05:00
|
|
|
}
|
|
|
|
}
|
2019-03-16 04:54:02 -05:00
|
|
|
ty::Param(_) => bug!("ty param {:?}", ty),
|
2018-06-22 12:18:53 -05:00
|
|
|
_ => return None,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-14 10:53:36 -05:00
|
|
|
/// Is a pointer to this type a fat ptr?
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
|
2020-01-09 10:43:10 -06:00
|
|
|
let ptr_ty = tcx.mk_ptr(TypeAndMut { ty, mutbl: rustc_hir::Mutability::Not });
|
2019-09-14 10:53:36 -05:00
|
|
|
match &tcx.layout_of(ParamEnv::reveal_all().and(ptr_ty)).unwrap().abi {
|
|
|
|
Abi::Scalar(_) => false,
|
|
|
|
Abi::ScalarPair(_, _) => true,
|
|
|
|
abi => unreachable!("Abi of ptr to {:?} is {:?}???", ty, abi),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn codegen_icmp(
|
2019-08-18 09:52:07 -05:00
|
|
|
fx: &mut FunctionCx<'_, '_, impl Backend>,
|
2019-08-15 04:36:06 -05:00
|
|
|
intcc: IntCC,
|
|
|
|
lhs: Value,
|
|
|
|
rhs: Value,
|
|
|
|
) -> Value {
|
|
|
|
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
|
|
|
|
let rhs_ty = fx.bcx.func.dfg.value_type(rhs);
|
|
|
|
assert_eq!(lhs_ty, rhs_ty);
|
|
|
|
if lhs_ty == types::I128 {
|
|
|
|
// FIXME legalize `icmp.i128` in Cranelift
|
|
|
|
|
|
|
|
let (lhs_lsb, lhs_msb) = fx.bcx.ins().isplit(lhs);
|
|
|
|
let (rhs_lsb, rhs_msb) = fx.bcx.ins().isplit(rhs);
|
|
|
|
|
|
|
|
match intcc {
|
|
|
|
IntCC::Equal => {
|
|
|
|
let lsb_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_lsb, rhs_lsb);
|
|
|
|
let msb_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_msb, rhs_msb);
|
|
|
|
fx.bcx.ins().band(lsb_eq, msb_eq)
|
|
|
|
}
|
|
|
|
IntCC::NotEqual => {
|
|
|
|
let lsb_ne = fx.bcx.ins().icmp(IntCC::NotEqual, lhs_lsb, rhs_lsb);
|
|
|
|
let msb_ne = fx.bcx.ins().icmp(IntCC::NotEqual, lhs_msb, rhs_msb);
|
|
|
|
fx.bcx.ins().bor(lsb_ne, msb_ne)
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
// if msb_eq {
|
|
|
|
// lsb_cc
|
|
|
|
// } else {
|
|
|
|
// msb_cc
|
|
|
|
// }
|
|
|
|
|
|
|
|
let msb_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_msb, rhs_msb);
|
|
|
|
let lsb_cc = fx.bcx.ins().icmp(intcc, lhs_lsb, rhs_lsb);
|
|
|
|
let msb_cc = fx.bcx.ins().icmp(intcc, lhs_msb, rhs_msb);
|
|
|
|
|
|
|
|
fx.bcx.ins().select(msb_eq, lsb_cc, msb_cc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fx.bcx.ins().icmp(intcc, lhs, rhs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn codegen_icmp_imm(
|
2019-08-18 09:52:07 -05:00
|
|
|
fx: &mut FunctionCx<'_, '_, impl Backend>,
|
2019-08-15 04:36:06 -05:00
|
|
|
intcc: IntCC,
|
|
|
|
lhs: Value,
|
|
|
|
rhs: i128,
|
|
|
|
) -> Value {
|
|
|
|
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
|
|
|
|
if lhs_ty == types::I128 {
|
|
|
|
// FIXME legalize `icmp_imm.i128` in Cranelift
|
|
|
|
|
|
|
|
let (lhs_lsb, lhs_msb) = fx.bcx.ins().isplit(lhs);
|
|
|
|
let (rhs_lsb, rhs_msb) = (rhs as u128 as u64 as i64, (rhs as u128 >> 64) as u64 as i64);
|
|
|
|
|
|
|
|
match intcc {
|
|
|
|
IntCC::Equal => {
|
|
|
|
let lsb_eq = fx.bcx.ins().icmp_imm(IntCC::Equal, lhs_lsb, rhs_lsb);
|
|
|
|
let msb_eq = fx.bcx.ins().icmp_imm(IntCC::Equal, lhs_msb, rhs_msb);
|
|
|
|
fx.bcx.ins().band(lsb_eq, msb_eq)
|
|
|
|
}
|
|
|
|
IntCC::NotEqual => {
|
|
|
|
let lsb_ne = fx.bcx.ins().icmp_imm(IntCC::NotEqual, lhs_lsb, rhs_lsb);
|
|
|
|
let msb_ne = fx.bcx.ins().icmp_imm(IntCC::NotEqual, lhs_msb, rhs_msb);
|
|
|
|
fx.bcx.ins().bor(lsb_ne, msb_ne)
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
// if msb_eq {
|
|
|
|
// lsb_cc
|
|
|
|
// } else {
|
|
|
|
// msb_cc
|
|
|
|
// }
|
|
|
|
|
|
|
|
let msb_eq = fx.bcx.ins().icmp_imm(IntCC::Equal, lhs_msb, rhs_msb);
|
|
|
|
let lsb_cc = fx.bcx.ins().icmp_imm(intcc, lhs_lsb, rhs_lsb);
|
|
|
|
let msb_cc = fx.bcx.ins().icmp_imm(intcc, lhs_msb, rhs_msb);
|
|
|
|
|
|
|
|
fx.bcx.ins().select(msb_eq, lsb_cc, msb_cc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let rhs = i64::try_from(rhs).expect("codegen_icmp_imm rhs out of range for <128bit int");
|
|
|
|
fx.bcx.ins().icmp_imm(intcc, lhs, rhs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-20 10:44:41 -05:00
|
|
|
fn resolve_normal_value_imm(func: &Function, val: Value) -> Option<i64> {
|
|
|
|
if let ValueDef::Result(inst, 0 /*param*/) = func.dfg.value_def(val) {
|
|
|
|
if let InstructionData::UnaryImm {
|
|
|
|
opcode: Opcode::Iconst,
|
|
|
|
imm,
|
2019-08-31 12:28:09 -05:00
|
|
|
} = func.dfg[inst]
|
|
|
|
{
|
2019-07-20 10:44:41 -05:00
|
|
|
Some(imm.into())
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resolve_128bit_value_imm(func: &Function, val: Value) -> Option<u128> {
|
|
|
|
let (lsb, msb) = if let ValueDef::Result(inst, 0 /*param*/) = func.dfg.value_def(val) {
|
|
|
|
if let InstructionData::Binary {
|
|
|
|
opcode: Opcode::Iconcat,
|
|
|
|
args: [lsb, msb],
|
2019-08-31 12:28:09 -05:00
|
|
|
} = func.dfg[inst]
|
|
|
|
{
|
2019-07-20 10:44:41 -05:00
|
|
|
(lsb, msb)
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return None;
|
|
|
|
};
|
|
|
|
|
|
|
|
let lsb = resolve_normal_value_imm(func, lsb)? as u64 as u128;
|
|
|
|
let msb = resolve_normal_value_imm(func, msb)? as u64 as u128;
|
|
|
|
|
|
|
|
Some(msb << 64 | lsb)
|
|
|
|
}
|
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn resolve_value_imm(func: &Function, val: Value) -> Option<u128> {
|
2019-07-20 10:44:41 -05:00
|
|
|
if func.dfg.value_type(val) == types::I128 {
|
|
|
|
resolve_128bit_value_imm(func, val)
|
|
|
|
} else {
|
|
|
|
resolve_normal_value_imm(func, val).map(|imm| imm as u64 as u128)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-17 07:14:18 -05:00
|
|
|
pub(crate) fn type_min_max_value(bcx: &mut FunctionBuilder<'_>, ty: Type, signed: bool) -> (Value, Value) {
|
2019-08-12 10:25:16 -05:00
|
|
|
assert!(ty.is_int());
|
2020-04-17 07:14:18 -05:00
|
|
|
|
|
|
|
if ty == types::I128 {
|
|
|
|
if signed {
|
|
|
|
let min = i128::MIN as u128;
|
|
|
|
let min_lsb = bcx.ins().iconst(types::I64, min as u64 as i64);
|
|
|
|
let min_msb = bcx.ins().iconst(types::I64, (min >> 64) as u64 as i64);
|
|
|
|
let min = bcx.ins().iconcat(min_lsb, min_msb);
|
|
|
|
|
|
|
|
let max = i128::MIN as u128;
|
|
|
|
let max_lsb = bcx.ins().iconst(types::I64, max as u64 as i64);
|
|
|
|
let max_msb = bcx.ins().iconst(types::I64, (max >> 64) as u64 as i64);
|
|
|
|
let max = bcx.ins().iconcat(max_lsb, max_msb);
|
|
|
|
|
|
|
|
return (min, max);
|
|
|
|
} else {
|
|
|
|
let min_half = bcx.ins().iconst(types::I64, 0);
|
|
|
|
let min = bcx.ins().iconcat(min_half, min_half);
|
|
|
|
|
|
|
|
let max_half = bcx.ins().iconst(types::I64, u64::MAX as i64);
|
|
|
|
let max = bcx.ins().iconcat(max_half, max_half);
|
|
|
|
|
|
|
|
return (min, max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 10:25:16 -05:00
|
|
|
let min = match (ty, signed) {
|
2019-08-31 12:28:09 -05:00
|
|
|
(types::I8, false) | (types::I16, false) | (types::I32, false) | (types::I64, false) => {
|
|
|
|
0i64
|
|
|
|
}
|
2020-03-20 10:29:05 -05:00
|
|
|
(types::I8, true) => i8::MIN as i64,
|
|
|
|
(types::I16, true) => i16::MIN as i64,
|
|
|
|
(types::I32, true) => i32::MIN as i64,
|
|
|
|
(types::I64, true) => i64::MIN,
|
2019-08-08 08:54:13 -05:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
2019-08-12 10:25:16 -05:00
|
|
|
let max = match (ty, signed) {
|
2020-03-20 10:29:05 -05:00
|
|
|
(types::I8, false) => u8::MAX as i64,
|
|
|
|
(types::I16, false) => u16::MAX as i64,
|
|
|
|
(types::I32, false) => u32::MAX as i64,
|
|
|
|
(types::I64, false) => u64::MAX as i64,
|
|
|
|
(types::I8, true) => i8::MAX as i64,
|
|
|
|
(types::I16, true) => i16::MAX as i64,
|
|
|
|
(types::I32, true) => i32::MAX as i64,
|
|
|
|
(types::I64, true) => i64::MAX,
|
2019-08-08 08:54:13 -05:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
2020-04-17 07:14:18 -05:00
|
|
|
let (min, max) = (bcx.ins().iconst(ty, min), bcx.ins().iconst(ty, max));
|
|
|
|
|
2019-08-08 08:54:13 -05:00
|
|
|
(min, max)
|
|
|
|
}
|
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn type_sign(ty: Ty<'_>) -> bool {
|
2019-09-28 04:13:40 -05:00
|
|
|
match ty.kind {
|
2019-08-12 10:25:16 -05:00
|
|
|
ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..) | ty::Char | ty::Uint(..) | ty::Bool => false,
|
|
|
|
ty::Int(..) => true,
|
|
|
|
ty::Float(..) => false, // `signed` is unused for floats
|
|
|
|
_ => panic!("{}", ty),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) struct FunctionCx<'clif, 'tcx, B: Backend + 'static> {
|
2018-12-18 11:28:02 -06:00
|
|
|
// FIXME use a reference to `CodegenCx` instead of `tcx`, `module` and `constants` and `caches`
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) tcx: TyCtxt<'tcx>,
|
|
|
|
pub(crate) module: &'clif mut Module<B>,
|
|
|
|
pub(crate) pointer_type: Type, // Cached from module
|
2018-12-01 04:49:44 -06:00
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) instance: Instance<'tcx>,
|
|
|
|
pub(crate) mir: &'tcx Body<'tcx>,
|
2018-12-01 04:49:44 -06:00
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) bcx: FunctionBuilder<'clif>,
|
|
|
|
pub(crate) block_map: IndexVec<BasicBlock, Block>,
|
2020-04-05 07:01:02 -05:00
|
|
|
pub(crate) local_map: FxHashMap<Local, CPlace<'tcx>>,
|
2018-12-01 04:49:44 -06:00
|
|
|
|
2020-01-11 09:49:42 -06:00
|
|
|
/// When `#[track_caller]` is used, the implicit caller location is stored in this variable.
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) caller_location: Option<CValue<'tcx>>,
|
2020-01-11 09:49:42 -06:00
|
|
|
|
2020-01-11 10:57:18 -06:00
|
|
|
/// See [crate::optimize::code_layout] for more information.
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) cold_blocks: EntitySet<Block>,
|
2020-01-11 10:57:18 -06:00
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) clif_comments: crate::pretty_clif::CommentWriter,
|
|
|
|
pub(crate) constants_cx: &'clif mut crate::constant::ConstantCx,
|
2020-04-05 07:01:02 -05:00
|
|
|
pub(crate) vtables: &'clif mut FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), DataId>,
|
2019-10-25 14:24:50 -05:00
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) source_info_set: indexmap::IndexSet<SourceInfo>,
|
2018-06-22 12:18:53 -05:00
|
|
|
}
|
|
|
|
|
2019-08-18 09:52:07 -05:00
|
|
|
impl<'tcx, B: Backend> LayoutOf for FunctionCx<'_, 'tcx, B> {
|
2018-06-24 07:01:41 -05:00
|
|
|
type Ty = Ty<'tcx>;
|
2020-03-30 12:00:24 -05:00
|
|
|
type TyAndLayout = TyAndLayout<'tcx>;
|
2018-06-24 07:01:41 -05:00
|
|
|
|
2020-03-30 12:00:24 -05:00
|
|
|
fn layout_of(&self, ty: Ty<'tcx>) -> TyAndLayout<'tcx> {
|
2019-12-17 09:58:34 -06:00
|
|
|
assert!(!ty.needs_subst());
|
2019-08-31 12:28:09 -05:00
|
|
|
self.tcx
|
|
|
|
.layout_of(ParamEnv::reveal_all().and(&ty))
|
|
|
|
.unwrap_or_else(|e| {
|
|
|
|
if let layout::LayoutError::SizeOverflow(_) = e {
|
|
|
|
self.tcx.sess.fatal(&e.to_string())
|
|
|
|
} else {
|
|
|
|
bug!("failed to get layout for `{}`: {}", ty, e)
|
|
|
|
}
|
2019-08-01 07:58:27 -05:00
|
|
|
})
|
2018-06-24 07:01:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 09:52:07 -05:00
|
|
|
impl<'tcx, B: Backend + 'static> layout::HasTyCtxt<'tcx> for FunctionCx<'_, 'tcx, B> {
|
2019-06-16 04:13:49 -05:00
|
|
|
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
2018-06-24 07:25:29 -05:00
|
|
|
self.tcx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-03 04:54:18 -05:00
|
|
|
impl<'tcx, B: Backend + 'static> rustc_target::abi::HasDataLayout for FunctionCx<'_, 'tcx, B> {
|
|
|
|
fn data_layout(&self) -> &rustc_target::abi::TargetDataLayout {
|
2018-06-24 07:25:29 -05:00
|
|
|
&self.tcx.data_layout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 09:52:07 -05:00
|
|
|
impl<'tcx, B: Backend + 'static> layout::HasParamEnv<'tcx> for FunctionCx<'_, 'tcx, B> {
|
2019-05-08 13:05:01 -05:00
|
|
|
fn param_env(&self) -> ParamEnv<'tcx> {
|
|
|
|
ParamEnv::reveal_all()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 09:52:07 -05:00
|
|
|
impl<'tcx, B: Backend + 'static> HasTargetSpec for FunctionCx<'_, 'tcx, B> {
|
2018-06-24 07:25:29 -05:00
|
|
|
fn target_spec(&self) -> &Target {
|
|
|
|
&self.tcx.sess.target.target
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 09:52:07 -05:00
|
|
|
impl<'tcx, B: Backend> BackendTypes for FunctionCx<'_, 'tcx, B> {
|
2018-11-21 09:01:33 -06:00
|
|
|
type Value = Value;
|
2019-10-16 11:39:12 -05:00
|
|
|
type Function = Value;
|
2020-02-14 11:23:29 -06:00
|
|
|
type BasicBlock = Block;
|
2018-11-21 09:01:33 -06:00
|
|
|
type Type = Type;
|
|
|
|
type Funclet = !;
|
|
|
|
type DIScope = !;
|
2020-02-07 06:49:48 -06:00
|
|
|
type DIVariable = !;
|
2018-11-21 09:01:33 -06:00
|
|
|
}
|
|
|
|
|
2019-08-18 09:52:07 -05:00
|
|
|
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn monomorphize<T>(&self, value: &T) -> T
|
2018-07-31 05:25:16 -05:00
|
|
|
where
|
|
|
|
T: TypeFoldable<'tcx>,
|
2018-06-23 11:54:15 -05:00
|
|
|
{
|
|
|
|
self.tcx.subst_and_normalize_erasing_regions(
|
2018-12-01 04:49:44 -06:00
|
|
|
self.instance.substs,
|
2018-06-23 11:54:15 -05:00
|
|
|
ty::ParamEnv::reveal_all(),
|
|
|
|
value,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn clif_type(&self, ty: Ty<'tcx>) -> Option<Type> {
|
2020-02-07 13:27:37 -06:00
|
|
|
clif_type_from_ty(self.tcx, ty)
|
2018-06-24 07:01:41 -05:00
|
|
|
}
|
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn get_block(&self, bb: BasicBlock) -> Block {
|
2020-02-14 11:23:29 -06:00
|
|
|
*self.block_map.get(bb).unwrap()
|
2018-06-22 12:18:53 -05:00
|
|
|
}
|
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn get_local_place(&mut self, local: Local) -> CPlace<'tcx> {
|
2020-03-10 14:41:31 -05:00
|
|
|
*self.local_map.get(&local).unwrap_or_else(|| {
|
|
|
|
panic!("Local {:?} doesn't exist", local);
|
|
|
|
})
|
2018-06-22 12:18:53 -05:00
|
|
|
}
|
2019-01-17 11:07:27 -06:00
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
|
2019-12-24 05:44:07 -06:00
|
|
|
let (index, _) = self.source_info_set.insert_full(source_info);
|
2019-01-19 05:18:39 -06:00
|
|
|
self.bcx.set_srcloc(SourceLoc::new(index as u32));
|
2019-01-17 11:07:27 -06:00
|
|
|
}
|
2019-11-09 04:14:18 -06:00
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn get_caller_location(&mut self, span: Span) -> CValue<'tcx> {
|
2020-01-11 09:49:42 -06:00
|
|
|
if let Some(loc) = self.caller_location {
|
|
|
|
// `#[track_caller]` is used; return caller location instead of current location.
|
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
|
2019-11-09 04:14:18 -06:00
|
|
|
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
|
|
|
|
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
|
|
|
let const_loc = self.tcx.const_caller_location((
|
2020-01-06 13:11:03 -06:00
|
|
|
rustc_span::symbol::Symbol::intern(&caller.file.name.to_string()),
|
2019-11-09 04:14:18 -06:00
|
|
|
caller.line as u32,
|
|
|
|
caller.col_display as u32 + 1,
|
|
|
|
));
|
2020-02-22 07:20:37 -06:00
|
|
|
crate::constant::trans_const_value(
|
|
|
|
self,
|
|
|
|
ty::Const::from_value(self.tcx, const_loc, self.tcx.caller_location_ty()),
|
|
|
|
)
|
2019-11-09 04:14:18 -06:00
|
|
|
}
|
2019-12-17 08:03:32 -06:00
|
|
|
|
2020-03-27 06:14:45 -05:00
|
|
|
pub(crate) fn triple(&self) -> &target_lexicon::Triple {
|
2019-12-17 08:03:32 -06:00
|
|
|
self.module.isa().triple()
|
|
|
|
}
|
2018-06-22 12:18:53 -05:00
|
|
|
}
|