1
Fork 0

update cg_clif

This commit is contained in:
Bastian Kauschke 2020-10-28 08:25:06 +01:00
parent a6cbd64dae
commit 7f45668af6
9 changed files with 45 additions and 46 deletions

View file

@ -216,7 +216,7 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
assert!(!inst.substs.needs_infer()); assert!(!inst.substs.needs_infer());
let fn_sig = tcx.normalize_erasing_late_bound_regions( let fn_sig = tcx.normalize_erasing_late_bound_regions(
ParamEnv::reveal_all(), ParamEnv::reveal_all(),
&fn_sig_for_fn_abi(tcx, inst), fn_sig_for_fn_abi(tcx, inst),
); );
if fn_sig.c_variadic && !support_vararg { if fn_sig.c_variadic && !support_vararg {
tcx.sess.span_fatal( tcx.sess.span_fatal(
@ -372,7 +372,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
.mir .mir
.args_iter() .args_iter()
.map(|local| { .map(|local| {
let arg_ty = fx.monomorphize(&fx.mir.local_decls[local].ty); let arg_ty = fx.monomorphize(fx.mir.local_decls[local].ty);
// Adapted from https://github.com/rust-lang/rust/blob/145155dc96757002c7b2e9de8489416e2fdbbd57/src/librustc_codegen_llvm/mir/mod.rs#L442-L482 // Adapted from https://github.com/rust-lang/rust/blob/145155dc96757002c7b2e9de8489416e2fdbbd57/src/librustc_codegen_llvm/mir/mod.rs#L442-L482
if Some(local) == fx.mir.spread_arg { if Some(local) == fx.mir.spread_arg {
@ -470,7 +470,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
} }
for local in fx.mir.vars_and_temps_iter() { for local in fx.mir.vars_and_temps_iter() {
let ty = fx.monomorphize(&fx.mir.local_decls[local].ty); let ty = fx.monomorphize(fx.mir.local_decls[local].ty);
let layout = fx.layout_of(ty); let layout = fx.layout_of(ty);
let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa; let is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
@ -492,10 +492,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
args: &[Operand<'tcx>], args: &[Operand<'tcx>],
destination: Option<(Place<'tcx>, BasicBlock)>, destination: Option<(Place<'tcx>, BasicBlock)>,
) { ) {
let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.tcx)); let fn_ty = fx.monomorphize(func.ty(fx.mir, fx.tcx));
let fn_sig = fx let fn_sig = fx
.tcx .tcx
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), &fn_ty.fn_sig(fx.tcx)); .normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), fn_ty.fn_sig(fx.tcx));
let destination = destination.map(|(place, bb)| (codegen_place(fx, place), bb)); let destination = destination.map(|(place, bb)| (codegen_place(fx, place), bb));
@ -711,7 +711,7 @@ pub(crate) fn codegen_drop<'tcx>(
let drop_fn_ty = drop_fn.ty(fx.tcx, ParamEnv::reveal_all()); let drop_fn_ty = drop_fn.ty(fx.tcx, ParamEnv::reveal_all());
let fn_sig = fx.tcx.normalize_erasing_late_bound_regions( let fn_sig = fx.tcx.normalize_erasing_late_bound_regions(
ParamEnv::reveal_all(), ParamEnv::reveal_all(),
&drop_fn_ty.fn_sig(fx.tcx), drop_fn_ty.fn_sig(fx.tcx),
); );
assert_eq!(fn_sig.output(), fx.tcx.mk_unit()); assert_eq!(fn_sig.output(), fx.tcx.mk_unit());

View file

@ -17,7 +17,7 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Module>) -> IndexVec<Local, S
.local_decls .local_decls
.iter() .iter()
.map(|local_decl| { .map(|local_decl| {
let ty = fx.monomorphize(&local_decl.ty); let ty = fx.monomorphize(local_decl.ty);
if fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some() { if fx.clif_type(ty).is_some() || fx.clif_pair_type(ty).is_some() {
SsaKind::Ssa SsaKind::Ssa
} else { } else {

View file

@ -445,43 +445,43 @@ fn codegen_stmt<'tcx>(
StatementKind::Assign(to_place_and_rval) => { StatementKind::Assign(to_place_and_rval) => {
let lval = codegen_place(fx, to_place_and_rval.0); let lval = codegen_place(fx, to_place_and_rval.0);
let dest_layout = lval.layout(); let dest_layout = lval.layout();
match &to_place_and_rval.1 { match to_place_and_rval.1 {
Rvalue::Use(operand) => { Rvalue::Use(ref operand) => {
let val = codegen_operand(fx, operand); let val = codegen_operand(fx, operand);
lval.write_cvalue(fx, val); lval.write_cvalue(fx, val);
} }
Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => {
let place = codegen_place(fx, *place); let place = codegen_place(fx, place);
let ref_ = place.place_ref(fx, lval.layout()); let ref_ = place.place_ref(fx, lval.layout());
lval.write_cvalue(fx, ref_); lval.write_cvalue(fx, ref_);
} }
Rvalue::ThreadLocalRef(def_id) => { Rvalue::ThreadLocalRef(def_id) => {
let val = crate::constant::codegen_tls_ref(fx, *def_id, lval.layout()); let val = crate::constant::codegen_tls_ref(fx, def_id, lval.layout());
lval.write_cvalue(fx, val); lval.write_cvalue(fx, val);
} }
Rvalue::BinaryOp(bin_op, lhs, rhs) => { Rvalue::BinaryOp(bin_op, ref lhs, ref rhs) => {
let lhs = codegen_operand(fx, lhs); let lhs = codegen_operand(fx, lhs);
let rhs = codegen_operand(fx, rhs); let rhs = codegen_operand(fx, rhs);
let res = crate::num::codegen_binop(fx, *bin_op, lhs, rhs); let res = crate::num::codegen_binop(fx, bin_op, lhs, rhs);
lval.write_cvalue(fx, res); lval.write_cvalue(fx, res);
} }
Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => { Rvalue::CheckedBinaryOp(bin_op, ref lhs, ref rhs) => {
let lhs = codegen_operand(fx, lhs); let lhs = codegen_operand(fx, lhs);
let rhs = codegen_operand(fx, rhs); let rhs = codegen_operand(fx, rhs);
let res = if !fx.tcx.sess.overflow_checks() { let res = if !fx.tcx.sess.overflow_checks() {
let val = let val =
crate::num::codegen_int_binop(fx, *bin_op, lhs, rhs).load_scalar(fx); crate::num::codegen_int_binop(fx, bin_op, lhs, rhs).load_scalar(fx);
let is_overflow = fx.bcx.ins().iconst(types::I8, 0); let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
CValue::by_val_pair(val, is_overflow, lval.layout()) CValue::by_val_pair(val, is_overflow, lval.layout())
} else { } else {
crate::num::codegen_checked_int_binop(fx, *bin_op, lhs, rhs) crate::num::codegen_checked_int_binop(fx, bin_op, lhs, rhs)
}; };
lval.write_cvalue(fx, res); lval.write_cvalue(fx, res);
} }
Rvalue::UnaryOp(un_op, operand) => { Rvalue::UnaryOp(un_op, ref operand) => {
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
let layout = operand.layout(); let layout = operand.layout();
let val = operand.load_scalar(fx); let val = operand.load_scalar(fx);
@ -509,8 +509,8 @@ fn codegen_stmt<'tcx>(
}; };
lval.write_cvalue(fx, res); lval.write_cvalue(fx, res);
} }
Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), operand, to_ty) => { Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), ref operand, to_ty) => {
let from_ty = fx.monomorphize(&operand.ty(&fx.mir.local_decls, fx.tcx)); let from_ty = fx.monomorphize(operand.ty(&fx.mir.local_decls, fx.tcx));
let to_layout = fx.layout_of(fx.monomorphize(to_ty)); let to_layout = fx.layout_of(fx.monomorphize(to_ty));
match *from_ty.kind() { match *from_ty.kind() {
ty::FnDef(def_id, substs) => { ty::FnDef(def_id, substs) => {
@ -530,14 +530,14 @@ fn codegen_stmt<'tcx>(
_ => bug!("Trying to ReifyFnPointer on non FnDef {:?}", from_ty), _ => bug!("Trying to ReifyFnPointer on non FnDef {:?}", from_ty),
} }
} }
Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), operand, to_ty) Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), ref operand, to_ty)
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, to_ty) | Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), ref operand, to_ty)
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => { | Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), ref operand, to_ty) => {
let to_layout = fx.layout_of(fx.monomorphize(to_ty)); let to_layout = fx.layout_of(fx.monomorphize(to_ty));
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout)); lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
} }
Rvalue::Cast(CastKind::Misc, operand, to_ty) => { Rvalue::Cast(CastKind::Misc, ref operand, to_ty) => {
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
let from_ty = operand.layout().ty; let from_ty = operand.layout().ty;
let to_ty = fx.monomorphize(to_ty); let to_ty = fx.monomorphize(to_ty);
@ -577,12 +577,12 @@ fn codegen_stmt<'tcx>(
use rustc_target::abi::{Int, TagEncoding, Variants}; use rustc_target::abi::{Int, TagEncoding, Variants};
match &operand.layout().variants { match operand.layout().variants {
Variants::Single { index } => { Variants::Single { index } => {
let discr = operand let discr = operand
.layout() .layout()
.ty .ty
.discriminant_for_variant(fx.tcx, *index) .discriminant_for_variant(fx.tcx, index)
.unwrap(); .unwrap();
let discr = if discr.ty.is_signed() { let discr = if discr.ty.is_signed() {
fx.layout_of(discr.ty).size.sign_extend(discr.val) fx.layout_of(discr.ty).size.sign_extend(discr.val)
@ -595,7 +595,7 @@ fn codegen_stmt<'tcx>(
lval.write_cvalue(fx, discr); lval.write_cvalue(fx, discr);
} }
Variants::Multiple { Variants::Multiple {
tag, ref tag,
tag_field, tag_field,
tag_encoding: TagEncoding::Direct, tag_encoding: TagEncoding::Direct,
variants: _, variants: _,
@ -604,7 +604,7 @@ fn codegen_stmt<'tcx>(
// Read the tag/niche-encoded discriminant from memory. // Read the tag/niche-encoded discriminant from memory.
let encoded_discr = let encoded_discr =
operand.value_field(fx, mir::Field::new(*tag_field)); operand.value_field(fx, mir::Field::new(tag_field));
let encoded_discr = encoded_discr.load_scalar(fx); let encoded_discr = encoded_discr.load_scalar(fx);
// Decode the discriminant (specifically if it's niche-encoded). // Decode the discriminant (specifically if it's niche-encoded).
@ -634,7 +634,7 @@ fn codegen_stmt<'tcx>(
} }
Rvalue::Cast( Rvalue::Cast(
CastKind::Pointer(PointerCast::ClosureFnPointer(_)), CastKind::Pointer(PointerCast::ClosureFnPointer(_)),
operand, ref operand,
_to_ty, _to_ty,
) => { ) => {
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
@ -654,18 +654,18 @@ fn codegen_stmt<'tcx>(
_ => bug!("{} cannot be cast to a fn ptr", operand.layout().ty), _ => bug!("{} cannot be cast to a fn ptr", operand.layout().ty),
} }
} }
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), operand, _to_ty) => { Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), ref operand, _to_ty) => {
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
operand.unsize_value(fx, lval); operand.unsize_value(fx, lval);
} }
Rvalue::Discriminant(place) => { Rvalue::Discriminant(place) => {
let place = codegen_place(fx, *place); let place = codegen_place(fx, place);
let value = place.to_cvalue(fx); let value = place.to_cvalue(fx);
let discr = let discr =
crate::discriminant::codegen_get_discriminant(fx, value, dest_layout); crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
lval.write_cvalue(fx, discr); lval.write_cvalue(fx, discr);
} }
Rvalue::Repeat(operand, times) => { Rvalue::Repeat(ref operand, times) => {
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
let times = fx let times = fx
.monomorphize(times) .monomorphize(times)
@ -704,7 +704,7 @@ fn codegen_stmt<'tcx>(
} }
} }
Rvalue::Len(place) => { Rvalue::Len(place) => {
let place = codegen_place(fx, *place); let place = codegen_place(fx, place);
let usize_layout = fx.layout_of(fx.tcx.types.usize); let usize_layout = fx.layout_of(fx.tcx.types.usize);
let len = codegen_array_len(fx, place); let len = codegen_array_len(fx, place);
lval.write_cvalue(fx, CValue::by_val(len, usize_layout)); lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
@ -749,7 +749,7 @@ fn codegen_stmt<'tcx>(
CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), ty_size.into()); CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), ty_size.into());
lval.write_cvalue(fx, val); lval.write_cvalue(fx, val);
} }
Rvalue::Aggregate(kind, operands) => match **kind { Rvalue::Aggregate(ref kind, ref operands) => match kind.as_ref() {
AggregateKind::Array(_ty) => { AggregateKind::Array(_ty) => {
for (i, operand) in operands.iter().enumerate() { for (i, operand) in operands.iter().enumerate() {
let operand = codegen_operand(fx, operand); let operand = codegen_operand(fx, operand);
@ -877,8 +877,7 @@ fn codegen_array_len<'tcx>(
match *place.layout().ty.kind() { match *place.layout().ty.kind() {
ty::Array(_elem_ty, len) => { ty::Array(_elem_ty, len) => {
let len = fx let len = fx
.monomorphize(&len) .monomorphize(len)
.eval(fx.tcx, ParamEnv::reveal_all())
.eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64; .eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
fx.bcx.ins().iconst(fx.pointer_type, len) fx.bcx.ins().iconst(fx.pointer_type, len)
} }

View file

@ -357,7 +357,7 @@ impl<'tcx, M: Module> HasTargetSpec for FunctionCx<'_, 'tcx, M> {
} }
impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> { impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
pub(crate) fn monomorphize<T>(&self, value: &T) -> T pub(crate) fn monomorphize<T>(&self, value: T) -> T
where where
T: TypeFoldable<'tcx> + Copy, T: TypeFoldable<'tcx> + Copy,
{ {

View file

@ -38,7 +38,7 @@ impl ConstantCx {
pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) { pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) {
for constant in &fx.mir.required_consts { for constant in &fx.mir.required_consts {
let const_ = fx.monomorphize(&constant.literal); let const_ = fx.monomorphize(constant.literal);
match const_.val { match const_.val {
ConstKind::Value(_) => {} ConstKind::Value(_) => {}
ConstKind::Unevaluated(def, ref substs, promoted) => { ConstKind::Unevaluated(def, ref substs, promoted) => {
@ -110,7 +110,7 @@ pub(crate) fn codegen_constant<'tcx>(
fx: &mut FunctionCx<'_, 'tcx, impl Module>, fx: &mut FunctionCx<'_, 'tcx, impl Module>,
constant: &Constant<'tcx>, constant: &Constant<'tcx>,
) -> CValue<'tcx> { ) -> CValue<'tcx> {
let const_ = fx.monomorphize(&constant.literal); let const_ = fx.monomorphize(constant.literal);
let const_val = match const_.val { let const_val = match const_.val {
ConstKind::Value(const_val) => const_val, ConstKind::Value(const_val) => const_val,
ConstKind::Unevaluated(def, ref substs, promoted) if fx.tcx.is_static(def.did) => { ConstKind::Unevaluated(def, ref substs, promoted) if fx.tcx.is_static(def.did) => {
@ -466,7 +466,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
match operand { match operand {
Operand::Copy(_) | Operand::Move(_) => None, Operand::Copy(_) | Operand::Move(_) => None,
Operand::Constant(const_) => Some( Operand::Constant(const_) => Some(
fx.monomorphize(&const_.literal) fx.monomorphize(const_.literal)
.eval(fx.tcx, ParamEnv::reveal_all()), .eval(fx.tcx, ParamEnv::reveal_all()),
), ),
} }

View file

@ -365,7 +365,7 @@ impl<'tcx> DebugContext<'tcx> {
let ty = self.tcx.subst_and_normalize_erasing_regions( let ty = self.tcx.subst_and_normalize_erasing_regions(
instance.substs, instance.substs,
ty::ParamEnv::reveal_all(), ty::ParamEnv::reveal_all(),
&mir.local_decls[local].ty, mir.local_decls[local].ty,
); );
let var_id = self.define_local(entry_id, format!("{:?}", local), ty); let var_id = self.define_local(entry_id, format!("{:?}", local), ty);

View file

@ -50,7 +50,7 @@ pub(crate) fn maybe_create_entry_wrapper(
// late-bound regions, since late-bound // late-bound regions, since late-bound
// regions must appear in the argument // regions must appear in the argument
// listing. // listing.
let main_ret_ty = tcx.erase_regions(&main_ret_ty.no_bound_vars().unwrap()); let main_ret_ty = tcx.erase_regions(main_ret_ty.no_bound_vars().unwrap());
let cmain_sig = Signature { let cmain_sig = Signature {
params: vec![ params: vec![

View file

@ -80,7 +80,7 @@ impl CommentWriter {
"sig {:?}", "sig {:?}",
tcx.normalize_erasing_late_bound_regions( tcx.normalize_erasing_late_bound_regions(
ParamEnv::reveal_all(), ParamEnv::reveal_all(),
&crate::abi::fn_sig_for_fn_abi(tcx, instance) crate::abi::fn_sig_for_fn_abi(tcx, instance)
) )
), ),
String::new(), String::new(),

View file

@ -455,7 +455,7 @@ impl<'tcx> CPlace<'tcx> {
from_ty: Ty<'tcx>, from_ty: Ty<'tcx>,
to_ty: Ty<'tcx>, to_ty: Ty<'tcx>,
) { ) {
match (&from_ty.kind(), &to_ty.kind()) { match (from_ty.kind(), to_ty.kind()) {
(ty::Ref(_, a, _), ty::Ref(_, b, _)) (ty::Ref(_, a, _), ty::Ref(_, b, _))
| ( | (
ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }), ty::RawPtr(TypeAndMut { ty: a, mutbl: _ }),
@ -466,11 +466,11 @@ impl<'tcx> CPlace<'tcx> {
(ty::FnPtr(_), ty::FnPtr(_)) => { (ty::FnPtr(_), ty::FnPtr(_)) => {
let from_sig = fx.tcx.normalize_erasing_late_bound_regions( let from_sig = fx.tcx.normalize_erasing_late_bound_regions(
ParamEnv::reveal_all(), ParamEnv::reveal_all(),
&from_ty.fn_sig(fx.tcx), from_ty.fn_sig(fx.tcx),
); );
let to_sig = fx.tcx.normalize_erasing_late_bound_regions( let to_sig = fx.tcx.normalize_erasing_late_bound_regions(
ParamEnv::reveal_all(), ParamEnv::reveal_all(),
&to_ty.fn_sig(fx.tcx), to_ty.fn_sig(fx.tcx),
); );
assert_eq!( assert_eq!(
from_sig, to_sig, from_sig, to_sig,
@ -479,7 +479,7 @@ impl<'tcx> CPlace<'tcx> {
); );
// fn(&T) -> for<'l> fn(&'l T) is allowed // fn(&T) -> for<'l> fn(&'l T) is allowed
} }
(ty::Dynamic(from_traits, _), ty::Dynamic(to_traits, _)) => { (&ty::Dynamic(from_traits, _), &ty::Dynamic(to_traits, _)) => {
let from_traits = fx let from_traits = fx
.tcx .tcx
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from_traits); .normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from_traits);