mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
update cg_clif
This commit is contained in:
parent
a6cbd64dae
commit
7f45668af6
@ -216,7 +216,7 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
|
||||
assert!(!inst.substs.needs_infer());
|
||||
let fn_sig = tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&fn_sig_for_fn_abi(tcx, inst),
|
||||
fn_sig_for_fn_abi(tcx, inst),
|
||||
);
|
||||
if fn_sig.c_variadic && !support_vararg {
|
||||
tcx.sess.span_fatal(
|
||||
@ -372,7 +372,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
|
||||
.mir
|
||||
.args_iter()
|
||||
.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
|
||||
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() {
|
||||
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 is_ssa = ssa_analyzed[local] == crate::analyze::SsaKind::Ssa;
|
||||
@ -492,10 +492,10 @@ 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.tcx));
|
||||
let fn_ty = fx.monomorphize(func.ty(fx.mir, fx.tcx));
|
||||
let fn_sig = fx
|
||||
.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));
|
||||
|
||||
@ -711,7 +711,7 @@ pub(crate) fn codegen_drop<'tcx>(
|
||||
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.tcx),
|
||||
drop_fn_ty.fn_sig(fx.tcx),
|
||||
);
|
||||
assert_eq!(fn_sig.output(), fx.tcx.mk_unit());
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, impl Module>) -> IndexVec<Local, S
|
||||
.local_decls
|
||||
.iter()
|
||||
.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() {
|
||||
SsaKind::Ssa
|
||||
} else {
|
||||
|
@ -445,43 +445,43 @@ fn codegen_stmt<'tcx>(
|
||||
StatementKind::Assign(to_place_and_rval) => {
|
||||
let lval = codegen_place(fx, to_place_and_rval.0);
|
||||
let dest_layout = lval.layout();
|
||||
match &to_place_and_rval.1 {
|
||||
Rvalue::Use(operand) => {
|
||||
match to_place_and_rval.1 {
|
||||
Rvalue::Use(ref operand) => {
|
||||
let val = codegen_operand(fx, operand);
|
||||
lval.write_cvalue(fx, val);
|
||||
}
|
||||
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());
|
||||
lval.write_cvalue(fx, ref_);
|
||||
}
|
||||
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);
|
||||
}
|
||||
Rvalue::BinaryOp(bin_op, lhs, rhs) => {
|
||||
Rvalue::BinaryOp(bin_op, ref lhs, ref rhs) => {
|
||||
let lhs = codegen_operand(fx, lhs);
|
||||
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);
|
||||
}
|
||||
Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => {
|
||||
Rvalue::CheckedBinaryOp(bin_op, ref lhs, ref rhs) => {
|
||||
let lhs = codegen_operand(fx, lhs);
|
||||
let rhs = codegen_operand(fx, rhs);
|
||||
|
||||
let res = if !fx.tcx.sess.overflow_checks() {
|
||||
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);
|
||||
CValue::by_val_pair(val, is_overflow, lval.layout())
|
||||
} 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);
|
||||
}
|
||||
Rvalue::UnaryOp(un_op, operand) => {
|
||||
Rvalue::UnaryOp(un_op, ref operand) => {
|
||||
let operand = codegen_operand(fx, operand);
|
||||
let layout = operand.layout();
|
||||
let val = operand.load_scalar(fx);
|
||||
@ -509,8 +509,8 @@ fn codegen_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.tcx));
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), ref operand, to_ty) => {
|
||||
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) => {
|
||||
@ -530,14 +530,14 @@ fn codegen_stmt<'tcx>(
|
||||
_ => bug!("Trying to ReifyFnPointer on non FnDef {:?}", from_ty),
|
||||
}
|
||||
}
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), operand, to_ty)
|
||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, to_ty)
|
||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, to_ty) => {
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), ref operand, to_ty)
|
||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), ref operand, to_ty)
|
||||
| Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), ref operand, to_ty) => {
|
||||
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
|
||||
let operand = codegen_operand(fx, operand);
|
||||
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 from_ty = operand.layout().ty;
|
||||
let to_ty = fx.monomorphize(to_ty);
|
||||
@ -577,12 +577,12 @@ fn codegen_stmt<'tcx>(
|
||||
|
||||
use rustc_target::abi::{Int, TagEncoding, Variants};
|
||||
|
||||
match &operand.layout().variants {
|
||||
match operand.layout().variants {
|
||||
Variants::Single { index } => {
|
||||
let discr = operand
|
||||
.layout()
|
||||
.ty
|
||||
.discriminant_for_variant(fx.tcx, *index)
|
||||
.discriminant_for_variant(fx.tcx, index)
|
||||
.unwrap();
|
||||
let discr = if discr.ty.is_signed() {
|
||||
fx.layout_of(discr.ty).size.sign_extend(discr.val)
|
||||
@ -595,7 +595,7 @@ fn codegen_stmt<'tcx>(
|
||||
lval.write_cvalue(fx, discr);
|
||||
}
|
||||
Variants::Multiple {
|
||||
tag,
|
||||
ref tag,
|
||||
tag_field,
|
||||
tag_encoding: TagEncoding::Direct,
|
||||
variants: _,
|
||||
@ -604,7 +604,7 @@ fn codegen_stmt<'tcx>(
|
||||
|
||||
// Read the tag/niche-encoded discriminant from memory.
|
||||
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);
|
||||
|
||||
// Decode the discriminant (specifically if it's niche-encoded).
|
||||
@ -634,7 +634,7 @@ fn codegen_stmt<'tcx>(
|
||||
}
|
||||
Rvalue::Cast(
|
||||
CastKind::Pointer(PointerCast::ClosureFnPointer(_)),
|
||||
operand,
|
||||
ref operand,
|
||||
_to_ty,
|
||||
) => {
|
||||
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),
|
||||
}
|
||||
}
|
||||
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);
|
||||
operand.unsize_value(fx, lval);
|
||||
}
|
||||
Rvalue::Discriminant(place) => {
|
||||
let place = codegen_place(fx, *place);
|
||||
let place = codegen_place(fx, place);
|
||||
let value = place.to_cvalue(fx);
|
||||
let discr =
|
||||
crate::discriminant::codegen_get_discriminant(fx, value, dest_layout);
|
||||
lval.write_cvalue(fx, discr);
|
||||
}
|
||||
Rvalue::Repeat(operand, times) => {
|
||||
Rvalue::Repeat(ref operand, times) => {
|
||||
let operand = codegen_operand(fx, operand);
|
||||
let times = fx
|
||||
.monomorphize(times)
|
||||
@ -704,7 +704,7 @@ fn codegen_stmt<'tcx>(
|
||||
}
|
||||
}
|
||||
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 len = codegen_array_len(fx, place);
|
||||
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());
|
||||
lval.write_cvalue(fx, val);
|
||||
}
|
||||
Rvalue::Aggregate(kind, operands) => match **kind {
|
||||
Rvalue::Aggregate(ref kind, ref operands) => match kind.as_ref() {
|
||||
AggregateKind::Array(_ty) => {
|
||||
for (i, operand) in operands.iter().enumerate() {
|
||||
let operand = codegen_operand(fx, operand);
|
||||
@ -877,8 +877,7 @@ fn codegen_array_len<'tcx>(
|
||||
match *place.layout().ty.kind() {
|
||||
ty::Array(_elem_ty, len) => {
|
||||
let len = fx
|
||||
.monomorphize(&len)
|
||||
.eval(fx.tcx, ParamEnv::reveal_all())
|
||||
.monomorphize(len)
|
||||
.eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64;
|
||||
fx.bcx.ins().iconst(fx.pointer_type, len)
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ impl<'tcx, M: Module> HasTargetSpec for 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
|
||||
T: TypeFoldable<'tcx> + Copy,
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ impl ConstantCx {
|
||||
|
||||
pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, impl Module>) {
|
||||
for constant in &fx.mir.required_consts {
|
||||
let const_ = fx.monomorphize(&constant.literal);
|
||||
let const_ = fx.monomorphize(constant.literal);
|
||||
match const_.val {
|
||||
ConstKind::Value(_) => {}
|
||||
ConstKind::Unevaluated(def, ref substs, promoted) => {
|
||||
@ -110,7 +110,7 @@ pub(crate) fn codegen_constant<'tcx>(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
constant: &Constant<'tcx>,
|
||||
) -> CValue<'tcx> {
|
||||
let const_ = fx.monomorphize(&constant.literal);
|
||||
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.tcx.is_static(def.did) => {
|
||||
@ -466,7 +466,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)
|
||||
fx.monomorphize(const_.literal)
|
||||
.eval(fx.tcx, ParamEnv::reveal_all()),
|
||||
),
|
||||
}
|
||||
|
@ -365,7 +365,7 @@ impl<'tcx> DebugContext<'tcx> {
|
||||
let ty = self.tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
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);
|
||||
|
||||
|
@ -50,7 +50,7 @@ pub(crate) fn maybe_create_entry_wrapper(
|
||||
// late-bound regions, since late-bound
|
||||
// regions must appear in the argument
|
||||
// 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 {
|
||||
params: vec![
|
||||
|
@ -80,7 +80,7 @@ impl CommentWriter {
|
||||
"sig {:?}",
|
||||
tcx.normalize_erasing_late_bound_regions(
|
||||
ParamEnv::reveal_all(),
|
||||
&crate::abi::fn_sig_for_fn_abi(tcx, instance)
|
||||
crate::abi::fn_sig_for_fn_abi(tcx, instance)
|
||||
)
|
||||
),
|
||||
String::new(),
|
||||
|
@ -455,7 +455,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
from_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::RawPtr(TypeAndMut { ty: a, mutbl: _ }),
|
||||
@ -466,11 +466,11 @@ impl<'tcx> CPlace<'tcx> {
|
||||
(ty::FnPtr(_), ty::FnPtr(_)) => {
|
||||
let from_sig = fx.tcx.normalize_erasing_late_bound_regions(
|
||||
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(
|
||||
ParamEnv::reveal_all(),
|
||||
&to_ty.fn_sig(fx.tcx),
|
||||
to_ty.fn_sig(fx.tcx),
|
||||
);
|
||||
assert_eq!(
|
||||
from_sig, to_sig,
|
||||
@ -479,7 +479,7 @@ impl<'tcx> CPlace<'tcx> {
|
||||
);
|
||||
// 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
|
||||
.tcx
|
||||
.normalize_erasing_late_bound_regions(ParamEnv::reveal_all(), from_traits);
|
||||
|
Loading…
Reference in New Issue
Block a user