FunctionCx: Refactor fx.cx.tcx
into fx.tcx
This commit is contained in:
parent
5cf4577352
commit
0d1f8c802e
@ -226,7 +226,7 @@ pub(crate) fn import_function<'tcx>(
|
||||
impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||
/// Instance must be monomorphized
|
||||
pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
|
||||
let func_id = import_function(self.cx.tcx, &mut self.cx.module, inst);
|
||||
let func_id = import_function(self.tcx, &mut self.cx.module, inst);
|
||||
let func_ref = self
|
||||
.cx.module
|
||||
.declare_func_in_func(func_id, &mut self.bcx.func);
|
||||
@ -374,9 +374,9 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
|
||||
.collect::<Vec<(Local, ArgKind<'tcx>, Ty<'tcx>)>>();
|
||||
|
||||
assert!(fx.caller_location.is_none());
|
||||
if fx.instance.def.requires_caller_location(fx.cx.tcx) {
|
||||
if fx.instance.def.requires_caller_location(fx.tcx) {
|
||||
// Store caller location for `#[track_caller]`.
|
||||
fx.caller_location = Some(cvalue_for_param(fx, start_block, None, None, fx.cx.tcx.caller_location_ty()).unwrap());
|
||||
fx.caller_location = Some(cvalue_for_param(fx, start_block, None, None, fx.tcx.caller_location_ty()).unwrap());
|
||||
}
|
||||
|
||||
fx.bcx.switch_to_block(start_block);
|
||||
@ -398,7 +398,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
|
||||
let local_decl = &fx.mir.local_decls[local];
|
||||
// v this ! is important
|
||||
let internally_mutable = !val.layout().ty.is_freeze(
|
||||
fx.cx.tcx.at(local_decl.source_info.span),
|
||||
fx.tcx.at(local_decl.source_info.span),
|
||||
ParamEnv::reveal_all(),
|
||||
);
|
||||
if local_decl.mutability == mir::Mutability::Not && !internally_mutable {
|
||||
@ -465,24 +465,24 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
args: &[Operand<'tcx>],
|
||||
destination: Option<(Place<'tcx>, BasicBlock)>,
|
||||
) {
|
||||
let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.cx.tcx));
|
||||
let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.tcx));
|
||||
let fn_sig = fx
|
||||
.cx.tcx
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.cx.tcx));
|
||||
.tcx
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx));
|
||||
|
||||
let destination = destination.map(|(place, bb)| (trans_place(fx, place), bb));
|
||||
|
||||
// Handle special calls like instrinsics and empty drop glue.
|
||||
let instance = if let ty::FnDef(def_id, substs) = fn_ty.kind {
|
||||
let instance = ty::Instance::resolve(fx.cx.tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
||||
let instance = ty::Instance::resolve(fx.tcx, ty::ParamEnv::reveal_all(), def_id, substs)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.polymorphize(fx.cx.tcx);
|
||||
.polymorphize(fx.tcx);
|
||||
|
||||
if fx.cx.tcx.symbol_name(instance).name.starts_with("llvm.") {
|
||||
if fx.tcx.symbol_name(instance).name.starts_with("llvm.") {
|
||||
crate::intrinsics::codegen_llvm_intrinsic_call(
|
||||
fx,
|
||||
&fx.cx.tcx.symbol_name(instance).name,
|
||||
&fx.tcx.symbol_name(instance).name,
|
||||
substs,
|
||||
args,
|
||||
destination,
|
||||
@ -510,7 +510,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
|
||||
let is_cold =
|
||||
instance.map(|inst|
|
||||
fx.cx.tcx.codegen_fn_attrs(inst.def_id())
|
||||
fx.tcx.codegen_fn_attrs(inst.def_id())
|
||||
.flags.contains(CodegenFnAttrFlags::COLD))
|
||||
.unwrap_or(false);
|
||||
if is_cold {
|
||||
@ -558,7 +558,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
nop_inst,
|
||||
format!(
|
||||
"virtual call; self arg pass mode: {:?}",
|
||||
get_pass_mode(fx.cx.tcx, args[0].layout())
|
||||
get_pass_mode(fx.tcx, args[0].layout())
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -608,7 +608,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if instance.map(|inst| inst.def.requires_caller_location(fx.cx.tcx)).unwrap_or(false) {
|
||||
if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) {
|
||||
// Pass the caller location for `#[track_caller]`.
|
||||
let caller_location = fx.get_caller_location(span);
|
||||
call_args.extend(adjust_arg_for_abi(fx, caller_location).into_iter());
|
||||
@ -616,7 +616,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
|
||||
let call_inst = if let Some(func_ref) = func_ref {
|
||||
let sig = clif_sig_from_fn_sig(
|
||||
fx.cx.tcx,
|
||||
fx.tcx,
|
||||
fx.triple(),
|
||||
fn_sig,
|
||||
span,
|
||||
@ -637,7 +637,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
// FIXME find a cleaner way to support varargs
|
||||
if fn_sig.c_variadic {
|
||||
if fn_sig.abi != Abi::C {
|
||||
fx.cx.tcx.sess.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
|
||||
fx.tcx.sess.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
|
||||
}
|
||||
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
|
||||
let abi_params = call_args
|
||||
@ -646,7 +646,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
||||
let ty = fx.bcx.func.dfg.value_type(arg);
|
||||
if !ty.is_int() {
|
||||
// FIXME set %al to upperbound on float args once floats are supported
|
||||
fx.cx.tcx.sess.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
|
||||
fx.tcx.sess.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
|
||||
}
|
||||
AbiParam::new(ty)
|
||||
})
|
||||
@ -668,17 +668,17 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||
drop_place: CPlace<'tcx>,
|
||||
) {
|
||||
let ty = drop_place.layout().ty;
|
||||
let drop_fn = Instance::resolve_drop_in_place(fx.cx.tcx, ty).polymorphize(fx.cx.tcx);
|
||||
let drop_fn = Instance::resolve_drop_in_place(fx.tcx, ty).polymorphize(fx.tcx);
|
||||
|
||||
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
|
||||
// we don't actually need to drop anything
|
||||
} else {
|
||||
let drop_fn_ty = drop_fn.ty(fx.cx.tcx, ParamEnv::reveal_all());
|
||||
let fn_sig = fx.cx.tcx.normalize_erasing_late_bound_regions(
|
||||
let drop_fn_ty = drop_fn.ty(fx.tcx, ParamEnv::reveal_all());
|
||||
let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&drop_fn_ty.fn_sig(fx.cx.tcx),
|
||||
&drop_fn_ty.fn_sig(fx.tcx),
|
||||
);
|
||||
assert_eq!(fn_sig.output(), fx.cx.tcx.mk_unit());
|
||||
assert_eq!(fn_sig.output(), fx.tcx.mk_unit());
|
||||
|
||||
match ty.kind {
|
||||
ty::Dynamic(..) => {
|
||||
@ -687,7 +687,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||
let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable.unwrap());
|
||||
|
||||
let sig = clif_sig_from_fn_sig(
|
||||
fx.cx.tcx,
|
||||
fx.tcx,
|
||||
fx.triple(),
|
||||
fn_sig,
|
||||
span,
|
||||
@ -702,7 +702,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||
|
||||
let arg_place = CPlace::new_stack_slot(
|
||||
fx,
|
||||
fx.layout_of(fx.cx.tcx.mk_ref(
|
||||
fx.layout_of(fx.tcx.mk_ref(
|
||||
&ty::RegionKind::ReErased,
|
||||
TypeAndMut {
|
||||
ty,
|
||||
@ -716,7 +716,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||
|
||||
let mut call_args: Vec<Value> = arg_value.into_iter().collect::<Vec<_>>();
|
||||
|
||||
if drop_fn.def.requires_caller_location(fx.cx.tcx) {
|
||||
if drop_fn.def.requires_caller_location(fx.tcx) {
|
||||
// Pass the caller location for `#[track_caller]`.
|
||||
let caller_location = fx.get_caller_location(span);
|
||||
call_args.extend(adjust_arg_for_abi(fx, caller_location).into_iter());
|
||||
|
@ -118,7 +118,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
||||
arg: CValue<'tcx>,
|
||||
) -> EmptySinglePair<Value> {
|
||||
match get_pass_mode(fx.cx.tcx, arg.layout()) {
|
||||
match get_pass_mode(fx.tcx, arg.layout()) {
|
||||
PassMode::NoPass => Empty,
|
||||
PassMode::ByVal(_) => Single(arg.load_scalar(fx)),
|
||||
PassMode::ByValPair(_, _) => {
|
||||
@ -144,13 +144,13 @@ pub(super) fn cvalue_for_param<'tcx>(
|
||||
arg_ty: Ty<'tcx>,
|
||||
) -> Option<CValue<'tcx>> {
|
||||
let layout = fx.layout_of(arg_ty);
|
||||
let pass_mode = get_pass_mode(fx.cx.tcx, layout);
|
||||
let pass_mode = get_pass_mode(fx.tcx, layout);
|
||||
|
||||
if let PassMode::NoPass = pass_mode {
|
||||
return None;
|
||||
}
|
||||
|
||||
let clif_types = pass_mode.get_param_ty(fx.cx.tcx);
|
||||
let clif_types = pass_mode.get_param_ty(fx.tcx);
|
||||
let block_params = clif_types.map(|t| fx.bcx.append_block_param(start_block, t));
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
|
@ -19,7 +19,7 @@ pub(super) fn codegen_return_param(
|
||||
start_block: Block,
|
||||
) {
|
||||
let ret_layout = return_layout(fx);
|
||||
let ret_pass_mode = get_pass_mode(fx.cx.tcx, ret_layout);
|
||||
let ret_pass_mode = get_pass_mode(fx.tcx, ret_layout);
|
||||
let ret_param = match ret_pass_mode {
|
||||
PassMode::NoPass => {
|
||||
fx.local_map
|
||||
@ -66,7 +66,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
|
||||
) -> (Inst, T) {
|
||||
let ret_layout = fx.layout_of(fn_sig.output());
|
||||
|
||||
let output_pass_mode = get_pass_mode(fx.cx.tcx, ret_layout);
|
||||
let output_pass_mode = get_pass_mode(fx.tcx, ret_layout);
|
||||
let return_ptr = match output_pass_mode {
|
||||
PassMode::NoPass => None,
|
||||
PassMode::ByRef { size: Some(_)} => match ret_place {
|
||||
@ -102,7 +102,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, B: Backend, T>(
|
||||
}
|
||||
|
||||
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||
match get_pass_mode(fx.cx.tcx, return_layout(fx)) {
|
||||
match get_pass_mode(fx.tcx, return_layout(fx)) {
|
||||
PassMode::NoPass | PassMode::ByRef { size: Some(_) } => {
|
||||
fx.bcx.ins().return_(&[]);
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Backend>) -> IndexVec<Local,
|
||||
match &bb.terminator().kind {
|
||||
TerminatorKind::Call { destination, .. } => {
|
||||
if let Some((dest_place, _dest_bb)) = destination {
|
||||
let dest_layout = fx.layout_of(fx.monomorphize(&dest_place.ty(&fx.mir.local_decls, fx.cx.tcx).ty));
|
||||
if !crate::abi::can_return_to_ssa_var(fx.cx.tcx, dest_layout) {
|
||||
let dest_layout = fx.layout_of(fx.monomorphize(&dest_place.ty(&fx.mir.local_decls, fx.tcx).ty));
|
||||
if !crate::abi::can_return_to_ssa_var(fx.tcx, dest_layout) {
|
||||
not_ssa(&mut flag_map, dest_place.local)
|
||||
}
|
||||
}
|
||||
|
72
src/base.rs
72
src/base.rs
@ -77,7 +77,7 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
|
||||
let cold_blocks = fx.cold_blocks;
|
||||
|
||||
crate::pretty_clif::write_clif_file(
|
||||
fx.cx.tcx,
|
||||
fx.tcx,
|
||||
"unopt",
|
||||
None,
|
||||
instance,
|
||||
@ -112,7 +112,7 @@ pub(crate) fn trans_fn<'tcx, B: Backend + 'static>(
|
||||
|
||||
// Write optimized function to file for debugging
|
||||
crate::pretty_clif::write_clif_file(
|
||||
fx.cx.tcx,
|
||||
fx.tcx,
|
||||
"opt",
|
||||
Some(fx.cx.module.isa()),
|
||||
instance,
|
||||
@ -223,7 +223,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||
target,
|
||||
cleanup: _,
|
||||
} => {
|
||||
if !fx.cx.tcx.sess.overflow_checks() {
|
||||
if !fx.tcx.sess.overflow_checks() {
|
||||
if let mir::AssertKind::OverflowNeg(_) = *msg {
|
||||
let target = fx.get_block(*target);
|
||||
fx.bcx.ins().jump(target, &[]);
|
||||
@ -264,12 +264,12 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||
}
|
||||
};
|
||||
|
||||
let def_id = fx.cx.tcx.lang_items().require(lang_item).unwrap_or_else(|s| {
|
||||
fx.cx.tcx.sess.span_fatal(bb_data.terminator().source_info.span, &s)
|
||||
let def_id = fx.tcx.lang_items().require(lang_item).unwrap_or_else(|s| {
|
||||
fx.tcx.sess.span_fatal(bb_data.terminator().source_info.span, &s)
|
||||
});
|
||||
|
||||
let instance = Instance::mono(fx.cx.tcx, def_id).polymorphize(fx.cx.tcx);
|
||||
let symbol_name = fx.cx.tcx.symbol_name(instance).name;
|
||||
let instance = Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
|
||||
let symbol_name = fx.tcx.symbol_name(instance).name;
|
||||
|
||||
fx.lib_call(&*symbol_name, vec![fx.pointer_type, fx.pointer_type, fx.pointer_type], vec![], &args);
|
||||
|
||||
@ -299,7 +299,7 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||
cleanup: _,
|
||||
from_hir_call: _,
|
||||
} => {
|
||||
fx.cx.tcx.sess.time("codegen call", || crate::abi::codegen_terminator_call(
|
||||
fx.tcx.sess.time("codegen call", || crate::abi::codegen_terminator_call(
|
||||
fx,
|
||||
*fn_span,
|
||||
block,
|
||||
@ -418,7 +418,7 @@ fn trans_stmt<'tcx>(
|
||||
let lhs = trans_operand(fx, lhs);
|
||||
let rhs = trans_operand(fx, rhs);
|
||||
|
||||
let res = if !fx.cx.tcx.sess.overflow_checks() {
|
||||
let res = if !fx.tcx.sess.overflow_checks() {
|
||||
let val =
|
||||
crate::num::trans_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx);
|
||||
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
|
||||
@ -464,14 +464,14 @@ fn trans_stmt<'tcx>(
|
||||
lval.write_cvalue(fx, res);
|
||||
}
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), operand, to_ty) => {
|
||||
let from_ty = fx.monomorphize(&operand.ty(&fx.mir.local_decls, fx.cx.tcx));
|
||||
let from_ty = fx.monomorphize(&operand.ty(&fx.mir.local_decls, fx.tcx));
|
||||
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
|
||||
match from_ty.kind {
|
||||
ty::FnDef(def_id, substs) => {
|
||||
let func_ref = fx.get_function_ref(
|
||||
Instance::resolve_for_fn_ptr(fx.cx.tcx, ParamEnv::reveal_all(), def_id, substs)
|
||||
Instance::resolve_for_fn_ptr(fx.tcx, ParamEnv::reveal_all(), def_id, substs)
|
||||
.unwrap()
|
||||
.polymorphize(fx.cx.tcx),
|
||||
.polymorphize(fx.tcx),
|
||||
);
|
||||
let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);
|
||||
lval.write_cvalue(fx, CValue::by_val(func_addr, to_layout));
|
||||
@ -500,7 +500,7 @@ fn trans_stmt<'tcx>(
|
||||
|ty::TypeAndMut {
|
||||
ty: pointee_ty,
|
||||
mutbl: _,
|
||||
}| has_ptr_meta(fx.cx.tcx, pointee_ty),
|
||||
}| has_ptr_meta(fx.tcx, pointee_ty),
|
||||
)
|
||||
.unwrap_or(false)
|
||||
}
|
||||
@ -526,7 +526,7 @@ fn trans_stmt<'tcx>(
|
||||
|
||||
match &operand.layout().variants {
|
||||
Variants::Single { index } => {
|
||||
let discr = operand.layout().ty.discriminant_for_variant(fx.cx.tcx, *index).unwrap();
|
||||
let discr = operand.layout().ty.discriminant_for_variant(fx.tcx, *index).unwrap();
|
||||
let discr = if discr.ty.is_signed() {
|
||||
rustc_middle::mir::interpret::sign_extend(discr.val, fx.layout_of(discr.ty).size)
|
||||
} else {
|
||||
@ -578,11 +578,11 @@ fn trans_stmt<'tcx>(
|
||||
match operand.layout().ty.kind {
|
||||
ty::Closure(def_id, substs) => {
|
||||
let instance = Instance::resolve_closure(
|
||||
fx.cx.tcx,
|
||||
fx.tcx,
|
||||
def_id,
|
||||
substs,
|
||||
ty::ClosureKind::FnOnce,
|
||||
).polymorphize(fx.cx.tcx);
|
||||
).polymorphize(fx.tcx);
|
||||
let func_ref = fx.get_function_ref(instance);
|
||||
let func_addr = fx.bcx.ins().func_addr(fx.pointer_type, func_ref);
|
||||
lval.write_cvalue(fx, CValue::by_val(func_addr, lval.layout()));
|
||||
@ -605,9 +605,9 @@ fn trans_stmt<'tcx>(
|
||||
let operand = trans_operand(fx, operand);
|
||||
let times = fx
|
||||
.monomorphize(times)
|
||||
.eval(fx.cx.tcx, ParamEnv::reveal_all())
|
||||
.eval(fx.tcx, ParamEnv::reveal_all())
|
||||
.val
|
||||
.try_to_bits(fx.cx.tcx.data_layout.pointer_size)
|
||||
.try_to_bits(fx.tcx.data_layout.pointer_size)
|
||||
.unwrap();
|
||||
for i in 0..times {
|
||||
let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
|
||||
@ -617,14 +617,14 @@ fn trans_stmt<'tcx>(
|
||||
}
|
||||
Rvalue::Len(place) => {
|
||||
let place = trans_place(fx, *place);
|
||||
let usize_layout = fx.layout_of(fx.cx.tcx.types.usize);
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
let len = codegen_array_len(fx, place);
|
||||
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
|
||||
}
|
||||
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
|
||||
use rustc_hir::lang_items::ExchangeMallocFnLangItem;
|
||||
|
||||
let usize_type = fx.clif_type(fx.cx.tcx.types.usize).unwrap();
|
||||
let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap();
|
||||
let content_ty = fx.monomorphize(content_ty);
|
||||
let layout = fx.layout_of(content_ty);
|
||||
let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64);
|
||||
@ -632,18 +632,18 @@ fn trans_stmt<'tcx>(
|
||||
.bcx
|
||||
.ins()
|
||||
.iconst(usize_type, layout.align.abi.bytes() as i64);
|
||||
let box_layout = fx.layout_of(fx.cx.tcx.mk_box(content_ty));
|
||||
let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty));
|
||||
|
||||
// Allocate space:
|
||||
let def_id = match fx.cx.tcx.lang_items().require(ExchangeMallocFnLangItem) {
|
||||
let def_id = match fx.tcx.lang_items().require(ExchangeMallocFnLangItem) {
|
||||
Ok(id) => id,
|
||||
Err(s) => {
|
||||
fx.cx.tcx
|
||||
fx.tcx
|
||||
.sess
|
||||
.fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
|
||||
}
|
||||
};
|
||||
let instance = ty::Instance::mono(fx.cx.tcx, def_id).polymorphize(fx.cx.tcx);
|
||||
let instance = ty::Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
|
||||
let func_ref = fx.get_function_ref(instance);
|
||||
let call = fx.bcx.ins().call(func_ref, &[llsize, llalign]);
|
||||
let ptr = fx.bcx.inst_results(call)[0];
|
||||
@ -653,9 +653,9 @@ fn trans_stmt<'tcx>(
|
||||
assert!(lval
|
||||
.layout()
|
||||
.ty
|
||||
.is_sized(fx.cx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all()));
|
||||
.is_sized(fx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all()));
|
||||
let ty_size = fx.layout_of(fx.monomorphize(ty)).size.bytes();
|
||||
let val = CValue::const_val(fx, fx.layout_of(fx.cx.tcx.types.usize), ty_size.into());
|
||||
let val = CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), ty_size.into());
|
||||
lval.write_cvalue(fx, val);
|
||||
}
|
||||
Rvalue::Aggregate(kind, operands) => match **kind {
|
||||
@ -720,10 +720,10 @@ fn trans_stmt<'tcx>(
|
||||
let (eax, ebx, ecx, edx) = crate::intrinsics::codegen_cpuid_call(fx, leaf, subleaf);
|
||||
|
||||
assert_eq!(outputs.len(), 4);
|
||||
trans_place(fx, outputs[0]).write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.cx.tcx.types.u32)));
|
||||
trans_place(fx, outputs[1]).write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.cx.tcx.types.u32)));
|
||||
trans_place(fx, outputs[2]).write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.cx.tcx.types.u32)));
|
||||
trans_place(fx, outputs[3]).write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.cx.tcx.types.u32)));
|
||||
trans_place(fx, outputs[0]).write_cvalue(fx, CValue::by_val(eax, fx.layout_of(fx.tcx.types.u32)));
|
||||
trans_place(fx, outputs[1]).write_cvalue(fx, CValue::by_val(ebx, fx.layout_of(fx.tcx.types.u32)));
|
||||
trans_place(fx, outputs[2]).write_cvalue(fx, CValue::by_val(ecx, fx.layout_of(fx.tcx.types.u32)));
|
||||
trans_place(fx, outputs[3]).write_cvalue(fx, CValue::by_val(edx, fx.layout_of(fx.tcx.types.u32)));
|
||||
}
|
||||
"xgetbv" => {
|
||||
assert_eq!(input_names, &[Symbol::intern("{ecx}")]);
|
||||
@ -743,17 +743,17 @@ fn trans_stmt<'tcx>(
|
||||
crate::trap::trap_unimplemented(fx, "_xgetbv arch intrinsic is not supported");
|
||||
}
|
||||
// ___chkstk, ___chkstk_ms and __alloca are only used on Windows
|
||||
_ if fx.cx.tcx.symbol_name(fx.instance).name.starts_with("___chkstk") => {
|
||||
_ if fx.tcx.symbol_name(fx.instance).name.starts_with("___chkstk") => {
|
||||
crate::trap::trap_unimplemented(fx, "Stack probes are not supported");
|
||||
}
|
||||
_ if fx.cx.tcx.symbol_name(fx.instance).name == "__alloca" => {
|
||||
_ if fx.tcx.symbol_name(fx.instance).name == "__alloca" => {
|
||||
crate::trap::trap_unimplemented(fx, "Alloca is not supported");
|
||||
}
|
||||
// Used in sys::windows::abort_internal
|
||||
"int $$0x29" => {
|
||||
crate::trap::trap_unimplemented(fx, "Windows abort");
|
||||
}
|
||||
_ => fx.cx.tcx.sess.span_fatal(stmt.source_info.span, "Inline assembly is not supported"),
|
||||
_ => fx.tcx.sess.span_fatal(stmt.source_info.span, "Inline assembly is not supported"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -766,8 +766,8 @@ fn codegen_array_len<'tcx>(
|
||||
match place.layout().ty.kind {
|
||||
ty::Array(_elem_ty, len) => {
|
||||
let len = fx.monomorphize(&len)
|
||||
.eval(fx.cx.tcx, ParamEnv::reveal_all())
|
||||
.eval_usize(fx.cx.tcx, ParamEnv::reveal_all()) as i64;
|
||||
.eval(fx.tcx, ParamEnv::reveal_all())
|
||||
.eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
|
||||
fx.bcx.ins().iconst(fx.pointer_type, len)
|
||||
}
|
||||
ty::Slice(_elem_ty) => place
|
||||
@ -820,7 +820,7 @@ pub(crate) fn trans_place<'tcx>(
|
||||
let ptr = cplace.to_ptr();
|
||||
cplace = CPlace::for_ptr(
|
||||
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * i64::from(from)),
|
||||
fx.layout_of(fx.cx.tcx.mk_array(elem_ty, u64::from(to) - u64::from(from))),
|
||||
fx.layout_of(fx.tcx.mk_array(elem_ty, u64::from(to) - u64::from(from))),
|
||||
);
|
||||
}
|
||||
ty::Slice(elem_ty) => {
|
||||
|
16
src/cast.rs
16
src/cast.rs
@ -86,14 +86,14 @@ pub(crate) fn clif_int_or_float_cast(
|
||||
);
|
||||
|
||||
let from_rust_ty = if from_signed {
|
||||
fx.cx.tcx.types.i128
|
||||
fx.tcx.types.i128
|
||||
} else {
|
||||
fx.cx.tcx.types.u128
|
||||
fx.tcx.types.u128
|
||||
};
|
||||
|
||||
let to_rust_ty = match to_ty {
|
||||
types::F32 => fx.cx.tcx.types.f32,
|
||||
types::F64 => fx.cx.tcx.types.f64,
|
||||
types::F32 => fx.tcx.types.f32,
|
||||
types::F64 => fx.tcx.types.f64,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
@ -131,15 +131,15 @@ pub(crate) fn clif_int_or_float_cast(
|
||||
);
|
||||
|
||||
let from_rust_ty = match from_ty {
|
||||
types::F32 => fx.cx.tcx.types.f32,
|
||||
types::F64 => fx.cx.tcx.types.f64,
|
||||
types::F32 => fx.tcx.types.f32,
|
||||
types::F64 => fx.tcx.types.f64,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let to_rust_ty = if to_signed {
|
||||
fx.cx.tcx.types.i128
|
||||
fx.tcx.types.i128
|
||||
} else {
|
||||
fx.cx.tcx.types.u128
|
||||
fx.tcx.types.u128
|
||||
};
|
||||
|
||||
return fx
|
||||
|
@ -9,7 +9,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
lhs: CValue<'tcx>,
|
||||
rhs: CValue<'tcx>,
|
||||
) -> Option<CValue<'tcx>> {
|
||||
if lhs.layout().ty != fx.cx.tcx.types.u128 && lhs.layout().ty != fx.cx.tcx.types.i128 {
|
||||
if lhs.layout().ty != fx.tcx.types.u128 && lhs.layout().ty != fx.tcx.types.i128 {
|
||||
return None;
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
}
|
||||
BinOp::Add | BinOp::Sub if !checked => return None,
|
||||
BinOp::Add => {
|
||||
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
|
||||
return Some(if is_signed {
|
||||
fx.easy_call("__rust_i128_addo", &[lhs, rhs], out_ty)
|
||||
} else {
|
||||
@ -33,7 +33,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
});
|
||||
}
|
||||
BinOp::Sub => {
|
||||
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
|
||||
return Some(if is_signed {
|
||||
fx.easy_call("__rust_i128_subo", &[lhs, rhs], out_ty)
|
||||
} else {
|
||||
@ -43,7 +43,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
|
||||
BinOp::Mul => {
|
||||
let res = if checked {
|
||||
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
|
||||
if is_signed {
|
||||
fx.easy_call("__rust_i128_mulo", &[lhs, rhs], out_ty)
|
||||
} else {
|
||||
@ -51,9 +51,9 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
}
|
||||
} else {
|
||||
let val_ty = if is_signed {
|
||||
fx.cx.tcx.types.i128
|
||||
fx.tcx.types.i128
|
||||
} else {
|
||||
fx.cx.tcx.types.u128
|
||||
fx.tcx.types.u128
|
||||
};
|
||||
fx.easy_call("__multi3", &[lhs, rhs], val_ty)
|
||||
};
|
||||
@ -62,17 +62,17 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
BinOp::Div => {
|
||||
assert!(!checked);
|
||||
if is_signed {
|
||||
Some(fx.easy_call("__divti3", &[lhs, rhs], fx.cx.tcx.types.i128))
|
||||
Some(fx.easy_call("__divti3", &[lhs, rhs], fx.tcx.types.i128))
|
||||
} else {
|
||||
Some(fx.easy_call("__udivti3", &[lhs, rhs], fx.cx.tcx.types.u128))
|
||||
Some(fx.easy_call("__udivti3", &[lhs, rhs], fx.tcx.types.u128))
|
||||
}
|
||||
}
|
||||
BinOp::Rem => {
|
||||
assert!(!checked);
|
||||
if is_signed {
|
||||
Some(fx.easy_call("__modti3", &[lhs, rhs], fx.cx.tcx.types.i128))
|
||||
Some(fx.easy_call("__modti3", &[lhs, rhs], fx.tcx.types.i128))
|
||||
} else {
|
||||
Some(fx.easy_call("__umodti3", &[lhs, rhs], fx.cx.tcx.types.u128))
|
||||
Some(fx.easy_call("__umodti3", &[lhs, rhs], fx.tcx.types.u128))
|
||||
}
|
||||
}
|
||||
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => {
|
||||
@ -104,7 +104,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
let val = match (bin_op, is_signed) {
|
||||
(BinOp::Shr, false) => {
|
||||
let val = fx.bcx.ins().iconcat(lhs_msb, all_zeros);
|
||||
Some(CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.u128)))
|
||||
Some(CValue::by_val(val, fx.layout_of(fx.tcx.types.u128)))
|
||||
}
|
||||
(BinOp::Shr, true) => {
|
||||
let sign = fx.bcx.ins().icmp_imm(IntCC::SignedLessThan, lhs_msb, 0);
|
||||
@ -112,13 +112,13 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
let all_sign_bits = fx.bcx.ins().select(sign, all_zeros, all_ones);
|
||||
|
||||
let val = fx.bcx.ins().iconcat(lhs_msb, all_sign_bits);
|
||||
Some(CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.i128)))
|
||||
Some(CValue::by_val(val, fx.layout_of(fx.tcx.types.i128)))
|
||||
}
|
||||
(BinOp::Shl, _) => {
|
||||
let val_ty = if is_signed {
|
||||
fx.cx.tcx.types.i128
|
||||
fx.tcx.types.i128
|
||||
} else {
|
||||
fx.cx.tcx.types.u128
|
||||
fx.tcx.types.u128
|
||||
};
|
||||
let val = fx.bcx.ins().iconcat(all_zeros, lhs_lsb);
|
||||
Some(CValue::by_val(val, fx.layout_of(val_ty)))
|
||||
@ -127,7 +127,7 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
};
|
||||
if let Some(val) = val {
|
||||
if let Some(is_overflow) = is_overflow {
|
||||
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
|
||||
let val = val.load_scalar(fx);
|
||||
return Some(CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty)));
|
||||
} else {
|
||||
@ -137,24 +137,24 @@ pub(crate) fn maybe_codegen<'tcx>(
|
||||
}
|
||||
|
||||
let truncated_rhs = clif_intcast(fx, rhs_val, types::I32, false);
|
||||
let truncated_rhs = CValue::by_val(truncated_rhs, fx.layout_of(fx.cx.tcx.types.u32));
|
||||
let truncated_rhs = CValue::by_val(truncated_rhs, fx.layout_of(fx.tcx.types.u32));
|
||||
let val = match (bin_op, is_signed) {
|
||||
(BinOp::Shl, false) => {
|
||||
fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.cx.tcx.types.u128)
|
||||
fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.tcx.types.u128)
|
||||
}
|
||||
(BinOp::Shl, true) => {
|
||||
fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.cx.tcx.types.i128)
|
||||
fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.tcx.types.i128)
|
||||
}
|
||||
(BinOp::Shr, false) => {
|
||||
fx.easy_call("__lshrti3", &[lhs, truncated_rhs], fx.cx.tcx.types.u128)
|
||||
fx.easy_call("__lshrti3", &[lhs, truncated_rhs], fx.tcx.types.u128)
|
||||
}
|
||||
(BinOp::Shr, true) => {
|
||||
fx.easy_call("__ashrti3", &[lhs, truncated_rhs], fx.cx.tcx.types.i128)
|
||||
fx.easy_call("__ashrti3", &[lhs, truncated_rhs], fx.tcx.types.i128)
|
||||
}
|
||||
(_, _) => unreachable!(),
|
||||
};
|
||||
if let Some(is_overflow) = is_overflow {
|
||||
let out_ty = fx.cx.tcx.mk_tup([lhs.layout().ty, fx.cx.tcx.types.bool].iter());
|
||||
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
|
||||
let val = val.load_scalar(fx);
|
||||
Some(CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty)))
|
||||
} else {
|
||||
|
@ -297,11 +297,11 @@ impl<'tcx, B: Backend> LayoutOf for FunctionCx<'_, 'tcx, B> {
|
||||
|
||||
fn layout_of(&self, ty: Ty<'tcx>) -> TyAndLayout<'tcx> {
|
||||
assert!(!ty.still_further_specializable());
|
||||
self.cx.tcx
|
||||
self.tcx
|
||||
.layout_of(ParamEnv::reveal_all().and(&ty))
|
||||
.unwrap_or_else(|e| {
|
||||
if let layout::LayoutError::SizeOverflow(_) = e {
|
||||
self.cx.tcx.sess.fatal(&e.to_string())
|
||||
self.tcx.sess.fatal(&e.to_string())
|
||||
} else {
|
||||
bug!("failed to get layout for `{}`: {}", ty, e)
|
||||
}
|
||||
@ -311,13 +311,13 @@ impl<'tcx, B: Backend> LayoutOf for FunctionCx<'_, 'tcx, B> {
|
||||
|
||||
impl<'tcx, B: Backend + 'static> layout::HasTyCtxt<'tcx> for FunctionCx<'_, 'tcx, B> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
||||
self.cx.tcx
|
||||
self.tcx
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, B: Backend + 'static> rustc_target::abi::HasDataLayout for FunctionCx<'_, 'tcx, B> {
|
||||
fn data_layout(&self) -> &rustc_target::abi::TargetDataLayout {
|
||||
&self.cx.tcx.data_layout
|
||||
&self.tcx.data_layout
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,7 +329,7 @@ impl<'tcx, B: Backend + 'static> layout::HasParamEnv<'tcx> for FunctionCx<'_, 't
|
||||
|
||||
impl<'tcx, B: Backend + 'static> HasTargetSpec for FunctionCx<'_, 'tcx, B> {
|
||||
fn target_spec(&self) -> &Target {
|
||||
&self.cx.tcx.sess.target.target
|
||||
&self.tcx.sess.target.target
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,22 +339,22 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||
T: TypeFoldable<'tcx> + Copy,
|
||||
{
|
||||
if let Some(substs) = self.instance.substs_for_mir_body() {
|
||||
self.cx.tcx.subst_and_normalize_erasing_regions(
|
||||
self.tcx.subst_and_normalize_erasing_regions(
|
||||
substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
value,
|
||||
)
|
||||
} else {
|
||||
self.cx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), *value)
|
||||
self.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), *value)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn clif_type(&self, ty: Ty<'tcx>) -> Option<Type> {
|
||||
clif_type_from_ty(self.cx.tcx, ty)
|
||||
clif_type_from_ty(self.tcx, ty)
|
||||
}
|
||||
|
||||
pub(crate) fn clif_pair_type(&self, ty: Ty<'tcx>) -> Option<(Type, Type)> {
|
||||
clif_pair_type_from_ty(self.cx.tcx, ty)
|
||||
clif_pair_type_from_ty(self.tcx, ty)
|
||||
}
|
||||
|
||||
pub(crate) fn get_block(&self, bb: BasicBlock) -> Block {
|
||||
@ -379,8 +379,8 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||
}
|
||||
|
||||
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
|
||||
let caller = self.cx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
||||
let const_loc = self.cx.tcx.const_caller_location((
|
||||
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
|
||||
let const_loc = self.tcx.const_caller_location((
|
||||
rustc_span::symbol::Symbol::intern(&caller.file.name.to_string()),
|
||||
caller.line as u32,
|
||||
caller.col_display as u32 + 1,
|
||||
@ -388,7 +388,7 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
|
||||
crate::constant::trans_const_value(
|
||||
self,
|
||||
const_loc,
|
||||
self.cx.tcx.caller_location_ty(),
|
||||
self.tcx.caller_location_ty(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -41,10 +41,10 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Backend>) {
|
||||
match const_.val {
|
||||
ConstKind::Value(_) => {}
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
||||
if let Err(err) = fx.cx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
|
||||
if let Err(err) = fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
|
||||
match err {
|
||||
ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted => {
|
||||
fx.cx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
||||
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
||||
}
|
||||
ErrorHandled::TooGeneric => {
|
||||
span_bug!(constant.span, "codgen encountered polymorphic constant: {:?}", err);
|
||||
@ -67,7 +67,7 @@ pub(crate) fn codegen_tls_ref<'tcx>(
|
||||
def_id: DefId,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
let data_id = data_id_for_static(fx.cx.tcx, &mut fx.cx.module, def_id, false);
|
||||
let data_id = data_id_for_static(fx.tcx, &mut fx.cx.module, def_id, false);
|
||||
let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||
#[cfg(debug_assertions)]
|
||||
fx.add_comment(local_data_id, format!("tls {:?}", def_id));
|
||||
@ -80,7 +80,7 @@ fn codegen_static_ref<'tcx>(
|
||||
def_id: DefId,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
) -> CPlace<'tcx> {
|
||||
let data_id = data_id_for_static(fx.cx.tcx, &mut fx.cx.module, def_id, false);
|
||||
let data_id = data_id_for_static(fx.tcx, &mut fx.cx.module, def_id, false);
|
||||
let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||
#[cfg(debug_assertions)]
|
||||
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
||||
@ -97,7 +97,7 @@ pub(crate) fn trans_constant<'tcx>(
|
||||
let const_ = fx.monomorphize(&constant.literal);
|
||||
let const_val = match const_.val {
|
||||
ConstKind::Value(const_val) => const_val,
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) if fx.cx.tcx.is_static(def.did) => {
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) if fx.tcx.is_static(def.did) => {
|
||||
assert!(substs.is_empty());
|
||||
assert!(promoted.is_none());
|
||||
|
||||
@ -108,11 +108,11 @@ pub(crate) fn trans_constant<'tcx>(
|
||||
).to_cvalue(fx);
|
||||
}
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
||||
match fx.cx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
|
||||
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), def, substs, promoted, None) {
|
||||
Ok(const_val) => const_val,
|
||||
Err(_) => {
|
||||
if promoted.is_none() {
|
||||
fx.cx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
||||
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
|
||||
}
|
||||
return crate::trap::trap_unreachable_ret_value(
|
||||
fx,
|
||||
@ -154,7 +154,7 @@ pub(crate) fn trans_const_value<'tcx>(
|
||||
);
|
||||
let ptr = Pointer::new(AllocId(!0), Size::ZERO); // The alloc id is never used
|
||||
alloc.write_scalar(fx, ptr, x.into(), size).unwrap();
|
||||
let alloc = fx.cx.tcx.intern_const_alloc(alloc);
|
||||
let alloc = fx.tcx.intern_const_alloc(alloc);
|
||||
return CValue::by_ref(pointer_for_allocation(fx, alloc), layout);
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ pub(crate) fn trans_const_value<'tcx>(
|
||||
return CValue::const_val(fx, layout, data);
|
||||
}
|
||||
Scalar::Ptr(ptr) => {
|
||||
let alloc_kind = fx.cx.tcx.get_global_alloc(ptr.alloc_id);
|
||||
let alloc_kind = fx.tcx.get_global_alloc(ptr.alloc_id);
|
||||
let base_addr = match alloc_kind {
|
||||
Some(GlobalAlloc::Memory(alloc)) => {
|
||||
fx.cx.constants_cx.todo.push(TodoItem::Alloc(ptr.alloc_id));
|
||||
@ -175,13 +175,13 @@ pub(crate) fn trans_const_value<'tcx>(
|
||||
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
|
||||
}
|
||||
Some(GlobalAlloc::Function(instance)) => {
|
||||
let func_id = crate::abi::import_function(fx.cx.tcx, &mut fx.cx.module, instance);
|
||||
let func_id = crate::abi::import_function(fx.tcx, &mut fx.cx.module, instance);
|
||||
let local_func_id = fx.cx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
|
||||
fx.bcx.ins().func_addr(fx.pointer_type, local_func_id)
|
||||
}
|
||||
Some(GlobalAlloc::Static(def_id)) => {
|
||||
assert!(fx.cx.tcx.is_static(def_id));
|
||||
let data_id = data_id_for_static(fx.cx.tcx, &mut fx.cx.module, def_id, false);
|
||||
assert!(fx.tcx.is_static(def_id));
|
||||
let data_id = data_id_for_static(fx.tcx, &mut fx.cx.module, def_id, false);
|
||||
let local_data_id = fx.cx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
|
||||
#[cfg(debug_assertions)]
|
||||
fx.add_comment(local_data_id, format!("{:?}", def_id));
|
||||
@ -215,7 +215,7 @@ fn pointer_for_allocation<'tcx>(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
|
||||
alloc: &'tcx Allocation,
|
||||
) -> crate::pointer::Pointer {
|
||||
let alloc_id = fx.cx.tcx.create_memory_alloc(alloc);
|
||||
let alloc_id = fx.tcx.create_memory_alloc(alloc);
|
||||
fx.cx.constants_cx.todo.push(TodoItem::Alloc(alloc_id));
|
||||
let data_id = data_id_for_alloc_id(&mut fx.cx.module, alloc_id, alloc.align, alloc.mutability);
|
||||
|
||||
@ -419,7 +419,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
|
||||
match operand {
|
||||
Operand::Copy(_) | Operand::Move(_) => None,
|
||||
Operand::Constant(const_) => {
|
||||
Some(fx.monomorphize(&const_.literal).eval(fx.cx.tcx, ParamEnv::reveal_all()))
|
||||
Some(fx.monomorphize(&const_.literal).eval(fx.tcx, ParamEnv::reveal_all()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
|
||||
let ptr = place.place_field(fx, mir::Field::new(tag_field));
|
||||
let to = layout
|
||||
.ty
|
||||
.discriminant_for_variant(fx.cx.tcx, variant_index)
|
||||
.discriminant_for_variant(fx.tcx, variant_index)
|
||||
.unwrap()
|
||||
.val;
|
||||
let discr = CValue::const_val(fx, ptr.layout(), to);
|
||||
@ -73,7 +73,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
|
||||
Variants::Single { index } => {
|
||||
let discr_val = layout
|
||||
.ty
|
||||
.discriminant_for_variant(fx.cx.tcx, *index)
|
||||
.discriminant_for_variant(fx.tcx, *index)
|
||||
.map_or(u128::from(index.as_u32()), |discr| discr.val);
|
||||
return CValue::const_val(fx, dest_layout, discr_val);
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ fn trans_mono_item<'tcx, B: Backend + 'static>(
|
||||
}
|
||||
});
|
||||
|
||||
cx.tcx.sess.time("codegen fn", || crate::base::trans_fn(cx, inst, linkage));
|
||||
tcx.sess.time("codegen fn", || crate::base::trans_fn(cx, inst, linkage));
|
||||
}
|
||||
MonoItem::Static(def_id) => {
|
||||
crate::constant::codegen_static(&mut cx.constants_cx, def_id);
|
||||
|
@ -70,7 +70,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
|
||||
|
||||
let inline_asm_index = fx.inline_asm_index;
|
||||
fx.inline_asm_index += 1;
|
||||
let asm_name = format!("{}__inline_asm_{}", fx.cx.tcx.symbol_name(fx.instance).name, inline_asm_index);
|
||||
let asm_name = format!("{}__inline_asm_{}", fx.tcx.symbol_name(fx.instance).name, inline_asm_index);
|
||||
|
||||
let generated_asm = generate_asm_wrapper(&asm_name, InlineAsmArch::X86_64, options, template, clobbered_regs, &inputs, &outputs);
|
||||
fx.cx.global_asm.push_str(&generated_asm);
|
||||
|
@ -30,13 +30,13 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
|
||||
intrinsic_match! {
|
||||
fx, intrinsic, substs, args,
|
||||
_ => {
|
||||
fx.cx.tcx.sess.warn(&format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic));
|
||||
fx.tcx.sess.warn(&format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic));
|
||||
crate::trap::trap_unimplemented(fx, intrinsic);
|
||||
};
|
||||
|
||||
// Used by `_mm_movemask_epi8` and `_mm256_movemask_epi8`
|
||||
llvm.x86.sse2.pmovmskb.128 | llvm.x86.avx2.pmovmskb | llvm.x86.sse2.movmsk.pd, (c a) {
|
||||
let (lane_layout, lane_count) = lane_type_and_count(fx.cx.tcx, a.layout());
|
||||
let (lane_layout, lane_count) = lane_type_and_count(fx.tcx, a.layout());
|
||||
let lane_ty = fx.clif_type(lane_layout.ty).unwrap();
|
||||
assert!(lane_count <= 32);
|
||||
|
||||
@ -61,7 +61,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
|
||||
res = fx.bcx.ins().bor(res, a_lane_sign);
|
||||
}
|
||||
|
||||
let res = CValue::by_val(res, fx.layout_of(fx.cx.tcx.types.i32));
|
||||
let res = CValue::by_val(res, fx.layout_of(fx.tcx.types.i32));
|
||||
ret.write_cvalue(fx, res);
|
||||
};
|
||||
llvm.x86.sse2.cmp.ps | llvm.x86.sse2.cmp.pd, (c x, c y, o kind) {
|
||||
|
@ -88,7 +88,7 @@ macro call_intrinsic_match {
|
||||
let ($($arg,)*) = (
|
||||
$(trans_operand($fx, $arg),)*
|
||||
);
|
||||
let res = $fx.easy_call(stringify!($func), &[$($arg),*], $fx.cx.tcx.types.$ty);
|
||||
let res = $fx.easy_call(stringify!($func), &[$($arg),*], $fx.tcx.types.$ty);
|
||||
$ret.write_cvalue($fx, res);
|
||||
|
||||
if let Some((_, dest)) = $destination {
|
||||
@ -144,7 +144,7 @@ macro validate_atomic_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
|
||||
match $ty.kind {
|
||||
ty::Uint(_) | ty::Int(_) => {}
|
||||
_ => {
|
||||
$fx.cx.tcx.sess.span_err($span, &format!("`{}` intrinsic: expected basic integer type, found `{:?}`", $intrinsic, $ty));
|
||||
$fx.tcx.sess.span_err($span, &format!("`{}` intrinsic: expected basic integer type, found `{:?}`", $intrinsic, $ty));
|
||||
// Prevent verifier error
|
||||
crate::trap::trap_unreachable($fx, "compilation should not have succeeded");
|
||||
return;
|
||||
@ -154,7 +154,7 @@ macro validate_atomic_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
|
||||
|
||||
macro validate_simd_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
|
||||
if !$ty.is_simd() {
|
||||
$fx.cx.tcx.sess.span_err($span, &format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", $intrinsic, $ty));
|
||||
$fx.tcx.sess.span_err($span, &format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", $intrinsic, $ty));
|
||||
// Prevent verifier error
|
||||
crate::trap::trap_unreachable($fx, "compilation should not have succeeded");
|
||||
return;
|
||||
@ -203,8 +203,8 @@ fn simd_for_each_lane<'tcx, B: Backend>(
|
||||
) {
|
||||
let layout = val.layout();
|
||||
|
||||
let (lane_layout, lane_count) = lane_type_and_count(fx.cx.tcx, layout);
|
||||
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.cx.tcx, ret.layout());
|
||||
let (lane_layout, lane_count) = lane_type_and_count(fx.tcx, layout);
|
||||
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.tcx, ret.layout());
|
||||
assert_eq!(lane_count, ret_lane_count);
|
||||
|
||||
for lane_idx in 0..lane_count {
|
||||
@ -233,8 +233,8 @@ fn simd_pair_for_each_lane<'tcx, B: Backend>(
|
||||
assert_eq!(x.layout(), y.layout());
|
||||
let layout = x.layout();
|
||||
|
||||
let (lane_layout, lane_count) = lane_type_and_count(fx.cx.tcx, layout);
|
||||
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.cx.tcx, ret.layout());
|
||||
let (lane_layout, lane_count) = lane_type_and_count(fx.tcx, layout);
|
||||
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.tcx, ret.layout());
|
||||
assert_eq!(lane_count, ret_lane_count);
|
||||
|
||||
for lane in 0..lane_count {
|
||||
@ -273,7 +273,7 @@ fn bool_to_zero_or_max_uint<'tcx>(
|
||||
|
||||
macro simd_cmp {
|
||||
($fx:expr, $cc:ident($x:ident, $y:ident) -> $ret:ident) => {
|
||||
let vector_ty = clif_vector_type($fx.cx.tcx, $x.layout());
|
||||
let vector_ty = clif_vector_type($fx.tcx, $x.layout());
|
||||
|
||||
if let Some(vector_ty) = vector_ty {
|
||||
let x = $x.load_scalar($fx);
|
||||
@ -390,7 +390,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
let def_id = instance.def_id();
|
||||
let substs = instance.substs;
|
||||
|
||||
let intrinsic = fx.cx.tcx.item_name(def_id).as_str();
|
||||
let intrinsic = fx.tcx.item_name(def_id).as_str();
|
||||
let intrinsic = &intrinsic[..];
|
||||
|
||||
let ret = match destination {
|
||||
@ -423,7 +423,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
return;
|
||||
}
|
||||
|
||||
let usize_layout = fx.layout_of(fx.cx.tcx.types.usize);
|
||||
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
||||
|
||||
call_intrinsic_match! {
|
||||
fx, intrinsic, substs, ret, destination, args,
|
||||
@ -473,7 +473,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
intrinsic_match! {
|
||||
fx, intrinsic, substs, args,
|
||||
_ => {
|
||||
fx.cx.tcx.sess.span_fatal(span, &format!("unsupported intrinsic {}", intrinsic));
|
||||
fx.tcx.sess.span_fatal(span, &format!("unsupported intrinsic {}", intrinsic));
|
||||
};
|
||||
|
||||
assume, (c _a) {};
|
||||
@ -684,7 +684,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
};
|
||||
ctlz | ctlz_nonzero, <T> (v arg) {
|
||||
// FIXME trap on `ctlz_nonzero` with zero arg.
|
||||
let res = if T == fx.cx.tcx.types.u128 || T == fx.cx.tcx.types.i128 {
|
||||
let res = if T == fx.tcx.types.u128 || T == fx.tcx.types.i128 {
|
||||
// FIXME verify this algorithm is correct
|
||||
let (lsb, msb) = fx.bcx.ins().isplit(arg);
|
||||
let lsb_lz = fx.bcx.ins().clz(lsb);
|
||||
@ -701,7 +701,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
};
|
||||
cttz | cttz_nonzero, <T> (v arg) {
|
||||
// FIXME trap on `cttz_nonzero` with zero arg.
|
||||
let res = if T == fx.cx.tcx.types.u128 || T == fx.cx.tcx.types.i128 {
|
||||
let res = if T == fx.tcx.types.u128 || T == fx.tcx.types.i128 {
|
||||
// FIXME verify this algorithm is correct
|
||||
let (lsb, msb) = fx.bcx.ins().isplit(arg);
|
||||
let lsb_tz = fx.bcx.ins().ctz(lsb);
|
||||
@ -842,7 +842,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
|
||||
size_of | pref_align_of | min_align_of | needs_drop | type_id | type_name | variant_count, () {
|
||||
let const_val =
|
||||
fx.cx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
|
||||
fx.tcx.const_eval_instance(ParamEnv::reveal_all(), instance, None).unwrap();
|
||||
let val = crate::constant::trans_const_value(
|
||||
fx,
|
||||
const_val,
|
||||
@ -852,7 +852,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
};
|
||||
|
||||
ptr_offset_from, <T> (v ptr, v base) {
|
||||
let isize_layout = fx.layout_of(fx.cx.tcx.types.isize);
|
||||
let isize_layout = fx.layout_of(fx.tcx.types.isize);
|
||||
|
||||
let pointee_size: u64 = fx.layout_of(T).size.bytes();
|
||||
let diff = fx.bcx.ins().isub(ptr, base);
|
||||
@ -1011,22 +1011,22 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
|
||||
minnumf32, (v a, v b) {
|
||||
let val = fx.bcx.ins().fmin(a, b);
|
||||
let val = CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.f32));
|
||||
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f32));
|
||||
ret.write_cvalue(fx, val);
|
||||
};
|
||||
minnumf64, (v a, v b) {
|
||||
let val = fx.bcx.ins().fmin(a, b);
|
||||
let val = CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.f64));
|
||||
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f64));
|
||||
ret.write_cvalue(fx, val);
|
||||
};
|
||||
maxnumf32, (v a, v b) {
|
||||
let val = fx.bcx.ins().fmax(a, b);
|
||||
let val = CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.f32));
|
||||
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f32));
|
||||
ret.write_cvalue(fx, val);
|
||||
};
|
||||
maxnumf64, (v a, v b) {
|
||||
let val = fx.bcx.ins().fmax(a, b);
|
||||
let val = CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.f64));
|
||||
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f64));
|
||||
ret.write_cvalue(fx, val);
|
||||
};
|
||||
|
||||
|
@ -11,13 +11,13 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
let def_id = instance.def_id();
|
||||
let substs = instance.substs;
|
||||
|
||||
let intrinsic = fx.cx.tcx.item_name(def_id).as_str();
|
||||
let intrinsic = fx.tcx.item_name(def_id).as_str();
|
||||
let intrinsic = &intrinsic[..];
|
||||
|
||||
intrinsic_match! {
|
||||
fx, intrinsic, substs, args,
|
||||
_ => {
|
||||
fx.cx.tcx.sess.span_fatal(span, &format!("Unknown SIMD intrinsic {}", intrinsic));
|
||||
fx.tcx.sess.span_fatal(span, &format!("Unknown SIMD intrinsic {}", intrinsic));
|
||||
};
|
||||
|
||||
simd_cast, (c a) {
|
||||
@ -68,8 +68,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
assert_eq!(x.layout(), y.layout());
|
||||
let layout = x.layout();
|
||||
|
||||
let (lane_type, lane_count) = lane_type_and_count(fx.cx.tcx, layout);
|
||||
let (ret_lane_type, ret_lane_count) = lane_type_and_count(fx.cx.tcx, ret.layout());
|
||||
let (lane_type, lane_count) = lane_type_and_count(fx.tcx, layout);
|
||||
let (ret_lane_type, ret_lane_count) = lane_type_and_count(fx.tcx, ret.layout());
|
||||
|
||||
assert_eq!(lane_type, ret_lane_type);
|
||||
assert_eq!(n, ret_lane_count);
|
||||
@ -92,7 +92,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
(0..ret_lane_count).map(|i| {
|
||||
let i = usize::try_from(i).unwrap();
|
||||
let idx = rustc_middle::mir::interpret::read_target_uint(
|
||||
fx.cx.tcx.data_layout.endian,
|
||||
fx.tcx.data_layout.endian,
|
||||
&idx_bytes[4*i.. 4*i + 4],
|
||||
).expect("read_target_uint");
|
||||
u16::try_from(idx).expect("try_from u32")
|
||||
@ -119,7 +119,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
|
||||
idx_const
|
||||
} else {
|
||||
fx.cx.tcx.sess.span_warn(
|
||||
fx.tcx.sess.span_warn(
|
||||
fx.mir.span,
|
||||
"`#[rustc_arg_required_const(..)]` is not yet supported. Calling this function will panic.",
|
||||
);
|
||||
@ -128,9 +128,9 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
};
|
||||
|
||||
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
|
||||
let (_lane_type, lane_count) = lane_type_and_count(fx.cx.tcx, base.layout());
|
||||
let (_lane_type, lane_count) = lane_type_and_count(fx.tcx, base.layout());
|
||||
if idx >= lane_count.into() {
|
||||
fx.cx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count));
|
||||
fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count));
|
||||
}
|
||||
|
||||
ret.write_cvalue(fx, base);
|
||||
@ -143,7 +143,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
|
||||
idx_const
|
||||
} else {
|
||||
fx.cx.tcx.sess.span_warn(
|
||||
fx.tcx.sess.span_warn(
|
||||
fx.mir.span,
|
||||
"`#[rustc_arg_required_const(..)]` is not yet supported. Calling this function will panic.",
|
||||
);
|
||||
@ -153,9 +153,9 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
};
|
||||
|
||||
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
|
||||
let (_lane_type, lane_count) = lane_type_and_count(fx.cx.tcx, v.layout());
|
||||
let (_lane_type, lane_count) = lane_type_and_count(fx.tcx, v.layout());
|
||||
if idx >= lane_count.into() {
|
||||
fx.cx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count));
|
||||
fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count));
|
||||
}
|
||||
|
||||
let ret_lane = v.value_field(fx, mir::Field::new(idx.try_into().unwrap()));
|
||||
@ -205,8 +205,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
|
||||
assert_eq!(a.layout(), c.layout());
|
||||
let layout = a.layout();
|
||||
|
||||
let (_lane_layout, lane_count) = lane_type_and_count(fx.cx.tcx, layout);
|
||||
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.cx.tcx, ret.layout());
|
||||
let (_lane_layout, lane_count) = lane_type_and_count(fx.tcx, layout);
|
||||
let (ret_lane_layout, ret_lane_count) = lane_type_and_count(fx.tcx, ret.layout());
|
||||
assert_eq!(lane_count, ret_lane_count);
|
||||
|
||||
for lane in 0..lane_count {
|
||||
|
16
src/num.rs
16
src/num.rs
@ -48,7 +48,7 @@ fn codegen_compare_bin_op<'tcx>(
|
||||
let intcc = crate::num::bin_op_to_intcc(bin_op, signed).unwrap();
|
||||
let val = fx.bcx.ins().icmp(intcc, lhs, rhs);
|
||||
let val = fx.bcx.ins().bint(types::I8, val);
|
||||
CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.bool))
|
||||
CValue::by_val(val, fx.layout_of(fx.tcx.types.bool))
|
||||
}
|
||||
|
||||
pub(crate) fn codegen_binop<'tcx>(
|
||||
@ -66,8 +66,8 @@ pub(crate) fn codegen_binop<'tcx>(
|
||||
let rhs = in_rhs.load_scalar(fx);
|
||||
|
||||
let (lhs, rhs) = if (bin_op == BinOp::Eq || bin_op == BinOp::Ne)
|
||||
&& (in_lhs.layout().ty.kind == fx.cx.tcx.types.i8.kind
|
||||
|| in_lhs.layout().ty.kind == fx.cx.tcx.types.i16.kind)
|
||||
&& (in_lhs.layout().ty.kind == fx.tcx.types.i8.kind
|
||||
|| in_lhs.layout().ty.kind == fx.tcx.types.i16.kind)
|
||||
{
|
||||
// FIXME(CraneStation/cranelift#896) icmp_imm.i8/i16 with eq/ne for signed ints is implemented wrong.
|
||||
(
|
||||
@ -118,7 +118,7 @@ pub(crate) fn trans_bool_binop<'tcx>(
|
||||
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs, in_rhs),
|
||||
};
|
||||
|
||||
CValue::by_val(res, fx.layout_of(fx.cx.tcx.types.bool))
|
||||
CValue::by_val(res, fx.layout_of(fx.tcx.types.bool))
|
||||
}
|
||||
|
||||
pub(crate) fn trans_int_binop<'tcx>(
|
||||
@ -323,7 +323,7 @@ pub(crate) fn trans_checked_int_binop<'tcx>(
|
||||
// FIXME directly write to result place instead
|
||||
let out_place = CPlace::new_stack_slot(
|
||||
fx,
|
||||
fx.layout_of(fx.cx.tcx.mk_tup([in_lhs.layout().ty, fx.cx.tcx.types.bool].iter())),
|
||||
fx.layout_of(fx.tcx.mk_tup([in_lhs.layout().ty, fx.tcx.types.bool].iter())),
|
||||
);
|
||||
let out_layout = out_place.layout();
|
||||
out_place.write_cvalue(fx, CValue::by_val_pair(res, has_overflow, out_layout));
|
||||
@ -368,7 +368,7 @@ pub(crate) fn trans_float_binop<'tcx>(
|
||||
};
|
||||
let val = fx.bcx.ins().fcmp(fltcc, lhs, rhs);
|
||||
let val = fx.bcx.ins().bint(types::I8, val);
|
||||
return CValue::by_val(val, fx.layout_of(fx.cx.tcx.types.bool));
|
||||
return CValue::by_val(val, fx.layout_of(fx.tcx.types.bool));
|
||||
}
|
||||
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs, in_rhs),
|
||||
};
|
||||
@ -383,7 +383,7 @@ pub(crate) fn trans_ptr_binop<'tcx>(
|
||||
in_rhs: CValue<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
let is_thin_ptr = in_lhs.layout().ty.builtin_deref(true).map(|TypeAndMut { ty, mutbl: _}| {
|
||||
!has_ptr_meta(fx.cx.tcx, ty)
|
||||
!has_ptr_meta(fx.tcx, ty)
|
||||
}).unwrap_or(true);
|
||||
|
||||
if is_thin_ptr {
|
||||
@ -440,7 +440,7 @@ pub(crate) fn trans_ptr_binop<'tcx>(
|
||||
|
||||
CValue::by_val(
|
||||
fx.bcx.ins().bint(types::I8, res),
|
||||
fx.layout_of(fx.cx.tcx.types.bool),
|
||||
fx.layout_of(fx.tcx.types.bool),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, ms
|
||||
Linkage::Import,
|
||||
&Signature {
|
||||
call_conv: CallConv::triple_default(fx.triple()),
|
||||
params: vec![AbiParam::new(pointer_ty(fx.cx.tcx))],
|
||||
params: vec![AbiParam::new(pointer_ty(fx.tcx))],
|
||||
returns: vec![AbiParam::new(types::I32)],
|
||||
},
|
||||
)
|
||||
@ -19,7 +19,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, ms
|
||||
fx.add_comment(puts, "puts");
|
||||
}
|
||||
|
||||
let symbol_name = fx.cx.tcx.symbol_name(fx.instance);
|
||||
let symbol_name = fx.tcx.symbol_name(fx.instance);
|
||||
let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, symbol_name, msg);
|
||||
let msg_ptr = fx.anonymous_str("trap", &real_msg);
|
||||
fx.bcx.ins().call(puts, &[msg_ptr]);
|
||||
|
@ -15,12 +15,12 @@ pub(crate) fn unsized_info<'tcx>(
|
||||
old_info: Option<Value>,
|
||||
) -> Value {
|
||||
let (source, target) =
|
||||
fx.cx.tcx
|
||||
fx.tcx
|
||||
.struct_lockstep_tails_erasing_lifetimes(source, target, ParamEnv::reveal_all());
|
||||
match (&source.kind, &target.kind) {
|
||||
(&ty::Array(_, len), &ty::Slice(_)) => fx.bcx.ins().iconst(
|
||||
fx.pointer_type,
|
||||
len.eval_usize(fx.cx.tcx, ParamEnv::reveal_all()) as i64,
|
||||
len.eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64,
|
||||
),
|
||||
(&ty::Dynamic(..), &ty::Dynamic(..)) => {
|
||||
// For now, upcasts are limited to changes in marker
|
||||
|
@ -35,10 +35,10 @@ fn codegen_field<'tcx>(
|
||||
let unaligned_offset = field_offset.bytes();
|
||||
let (_, unsized_align) = crate::unsize::size_and_align_of_dst(fx, field_layout, extra);
|
||||
|
||||
let one = fx.bcx.ins().iconst(pointer_ty(fx.cx.tcx), 1);
|
||||
let one = fx.bcx.ins().iconst(pointer_ty(fx.tcx), 1);
|
||||
let align_sub_1 = fx.bcx.ins().isub(unsized_align, one);
|
||||
let and_lhs = fx.bcx.ins().iadd_imm(align_sub_1, unaligned_offset as i64);
|
||||
let zero = fx.bcx.ins().iconst(pointer_ty(fx.cx.tcx), 0);
|
||||
let zero = fx.bcx.ins().iconst(pointer_ty(fx.tcx), 0);
|
||||
let and_rhs = fx.bcx.ins().isub(zero, unsized_align);
|
||||
let offset = fx.bcx.ins().band(and_lhs, and_rhs);
|
||||
|
||||
@ -119,9 +119,9 @@ impl<'tcx> CValue<'tcx> {
|
||||
match self.0 {
|
||||
CValueInner::ByRef(ptr, None) => {
|
||||
let clif_ty = match layout.abi {
|
||||
Abi::Scalar(ref scalar) => scalar_to_clif_type(fx.cx.tcx, scalar.clone()),
|
||||
Abi::Scalar(ref scalar) => scalar_to_clif_type(fx.tcx, scalar.clone()),
|
||||
Abi::Vector { ref element, count } => {
|
||||
scalar_to_clif_type(fx.cx.tcx, element.clone())
|
||||
scalar_to_clif_type(fx.tcx, element.clone())
|
||||
.by(u16::try_from(count).unwrap()).unwrap()
|
||||
}
|
||||
_ => unreachable!("{:?}", layout.ty),
|
||||
@ -146,9 +146,9 @@ impl<'tcx> CValue<'tcx> {
|
||||
Abi::ScalarPair(a, b) => (a, b),
|
||||
_ => unreachable!("load_scalar_pair({:?})", self),
|
||||
};
|
||||
let b_offset = scalar_pair_calculate_b_offset(fx.cx.tcx, a_scalar, b_scalar);
|
||||
let clif_ty1 = scalar_to_clif_type(fx.cx.tcx, a_scalar.clone());
|
||||
let clif_ty2 = scalar_to_clif_type(fx.cx.tcx, b_scalar.clone());
|
||||
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
|
||||
let clif_ty1 = scalar_to_clif_type(fx.tcx, a_scalar.clone());
|
||||
let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar.clone());
|
||||
let val1 = ptr.load(fx, clif_ty1, MemFlags::new());
|
||||
let val2 = ptr.offset(fx, b_offset).load(fx, clif_ty2, MemFlags::new());
|
||||
(val1, val2)
|
||||
@ -419,13 +419,13 @@ impl<'tcx> CPlace<'tcx> {
|
||||
assert_assignable(fx, a, b);
|
||||
}
|
||||
(ty::FnPtr(_), ty::FnPtr(_)) => {
|
||||
let from_sig = fx.cx.tcx.normalize_erasing_late_bound_regions(
|
||||
let from_sig = fx.tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&from_ty.fn_sig(fx.cx.tcx),
|
||||
&from_ty.fn_sig(fx.tcx),
|
||||
);
|
||||
let to_sig = fx.cx.tcx.normalize_erasing_late_bound_regions(
|
||||
let to_sig = fx.tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&to_ty.fn_sig(fx.cx.tcx),
|
||||
&to_ty.fn_sig(fx.tcx),
|
||||
);
|
||||
assert_eq!(
|
||||
from_sig, to_sig,
|
||||
@ -436,10 +436,10 @@ impl<'tcx> CPlace<'tcx> {
|
||||
}
|
||||
(ty::Dynamic(from_traits, _), ty::Dynamic(to_traits, _)) => {
|
||||
let from_traits = fx
|
||||
.cx.tcx
|
||||
.tcx
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from_traits);
|
||||
let to_traits = fx
|
||||
.cx.tcx
|
||||
.tcx
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), to_traits);
|
||||
assert_eq!(
|
||||
from_traits, to_traits,
|
||||
@ -569,7 +569,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
}
|
||||
Abi::ScalarPair(ref a_scalar, ref b_scalar) => {
|
||||
let (value, extra) = from.load_scalar_pair(fx);
|
||||
let b_offset = scalar_pair_calculate_b_offset(fx.cx.tcx, a_scalar, b_scalar);
|
||||
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
|
||||
to_ptr.store(fx, value, MemFlags::new());
|
||||
to_ptr.offset(fx, b_offset).store(fx, extra, MemFlags::new());
|
||||
return;
|
||||
@ -673,7 +673,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
|
||||
pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> CPlace<'tcx> {
|
||||
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap().ty);
|
||||
if has_ptr_meta(fx.cx.tcx, inner_layout.ty) {
|
||||
if has_ptr_meta(fx.tcx, inner_layout.ty) {
|
||||
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
|
||||
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)
|
||||
} else {
|
||||
@ -682,7 +682,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
}
|
||||
|
||||
pub(crate) fn write_place_ref(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>, dest: CPlace<'tcx>) {
|
||||
if has_ptr_meta(fx.cx.tcx, self.layout().ty) {
|
||||
if has_ptr_meta(fx.tcx, self.layout().ty) {
|
||||
let (ptr, extra) = self.to_ptr_maybe_unsized();
|
||||
let ptr = CValue::by_val_pair(
|
||||
ptr.get_addr(fx),
|
||||
|
@ -13,9 +13,9 @@ fn vtable_memflags() -> MemFlags {
|
||||
}
|
||||
|
||||
pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value {
|
||||
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes() as usize;
|
||||
let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize;
|
||||
fx.bcx.ins().load(
|
||||
pointer_ty(fx.cx.tcx),
|
||||
pointer_ty(fx.tcx),
|
||||
vtable_memflags(),
|
||||
vtable,
|
||||
(DROP_FN_INDEX * usize_size) as i32,
|
||||
@ -23,9 +23,9 @@ pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable:
|
||||
}
|
||||
|
||||
pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value {
|
||||
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes() as usize;
|
||||
let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize;
|
||||
fx.bcx.ins().load(
|
||||
pointer_ty(fx.cx.tcx),
|
||||
pointer_ty(fx.tcx),
|
||||
vtable_memflags(),
|
||||
vtable,
|
||||
(SIZE_INDEX * usize_size) as i32,
|
||||
@ -33,9 +33,9 @@ pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Val
|
||||
}
|
||||
|
||||
pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, impl Backend>, vtable: Value) -> Value {
|
||||
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes() as usize;
|
||||
let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize;
|
||||
fx.bcx.ins().load(
|
||||
pointer_ty(fx.cx.tcx),
|
||||
pointer_ty(fx.tcx),
|
||||
vtable_memflags(),
|
||||
vtable,
|
||||
(ALIGN_INDEX * usize_size) as i32,
|
||||
@ -57,9 +57,9 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
|
||||
)
|
||||
};
|
||||
|
||||
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes();
|
||||
let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes();
|
||||
let func_ref = fx.bcx.ins().load(
|
||||
pointer_ty(fx.cx.tcx),
|
||||
pointer_ty(fx.tcx),
|
||||
vtable_memflags(),
|
||||
vtable,
|
||||
((idx + 3) * usize_size as usize) as i32,
|
||||
@ -89,11 +89,11 @@ fn build_vtable<'tcx>(
|
||||
layout: TyAndLayout<'tcx>,
|
||||
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
|
||||
) -> DataId {
|
||||
let tcx = fx.cx.tcx;
|
||||
let usize_size = fx.layout_of(fx.cx.tcx.types.usize).size.bytes() as usize;
|
||||
let tcx = fx.tcx;
|
||||
let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize;
|
||||
|
||||
let drop_in_place_fn =
|
||||
import_function(tcx, &mut fx.cx.module, Instance::resolve_drop_in_place(tcx, layout.ty).polymorphize(fx.cx.tcx));
|
||||
import_function(tcx, &mut fx.cx.module, Instance::resolve_drop_in_place(tcx, layout.ty).polymorphize(fx.tcx));
|
||||
|
||||
let mut components: Vec<_> = vec![Some(drop_in_place_fn), None, None];
|
||||
|
||||
@ -109,7 +109,7 @@ fn build_vtable<'tcx>(
|
||||
Some(import_function(
|
||||
tcx,
|
||||
&mut fx.cx.module,
|
||||
Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs).unwrap().polymorphize(fx.cx.tcx),
|
||||
Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs).unwrap().polymorphize(fx.tcx),
|
||||
))
|
||||
})
|
||||
});
|
||||
@ -121,8 +121,8 @@ fn build_vtable<'tcx>(
|
||||
.collect::<Vec<u8>>()
|
||||
.into_boxed_slice();
|
||||
|
||||
write_usize(fx.cx.tcx, &mut data, SIZE_INDEX, layout.size.bytes());
|
||||
write_usize(fx.cx.tcx, &mut data, ALIGN_INDEX, layout.align.abi.bytes());
|
||||
write_usize(fx.tcx, &mut data, SIZE_INDEX, layout.size.bytes());
|
||||
write_usize(fx.tcx, &mut data, ALIGN_INDEX, layout.align.abi.bytes());
|
||||
data_ctx.define(data);
|
||||
|
||||
for (i, component) in components.into_iter().enumerate() {
|
||||
@ -148,7 +148,7 @@ fn build_vtable<'tcx>(
|
||||
false,
|
||||
false,
|
||||
Some(
|
||||
fx.cx.tcx
|
||||
fx.tcx
|
||||
.data_layout
|
||||
.pointer_align
|
||||
.pref
|
||||
|
Loading…
x
Reference in New Issue
Block a user