Sync from rust 04006d8e3b
This commit is contained in:
commit
89fedb1e4d
6 changed files with 86 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "rustc_codegen_cranelift"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["dylib"]
|
||||
|
|
|
@ -5,7 +5,7 @@ mod pass_mode;
|
|||
mod returning;
|
||||
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::ty::layout::FnAbiExt;
|
||||
use rustc_middle::ty::layout::FnAbiOf;
|
||||
use rustc_target::abi::call::{Conv, FnAbi};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
|
@ -53,7 +53,11 @@ pub(crate) fn get_function_sig<'tcx>(
|
|||
inst: Instance<'tcx>,
|
||||
) -> Signature {
|
||||
assert!(!inst.substs.needs_infer());
|
||||
clif_sig_from_fn_abi(tcx, triple, &FnAbi::of_instance(&RevealAllLayoutCx(tcx), inst, &[]))
|
||||
clif_sig_from_fn_abi(
|
||||
tcx,
|
||||
triple,
|
||||
&RevealAllLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()),
|
||||
)
|
||||
}
|
||||
|
||||
/// Instance must be monomorphized
|
||||
|
@ -350,14 +354,13 @@ pub(crate) fn codegen_terminator_call<'tcx>(
|
|||
};
|
||||
|
||||
let extra_args = &args[fn_sig.inputs().len()..];
|
||||
let extra_args = extra_args
|
||||
.iter()
|
||||
.map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx)))
|
||||
.collect::<Vec<_>>();
|
||||
let extra_args = fx
|
||||
.tcx
|
||||
.mk_type_list(extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx))));
|
||||
let fn_abi = if let Some(instance) = instance {
|
||||
FnAbi::of_instance(&RevealAllLayoutCx(fx.tcx), instance, &extra_args)
|
||||
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args)
|
||||
} else {
|
||||
FnAbi::of_fn_ptr(&RevealAllLayoutCx(fx.tcx), fn_ty.fn_sig(fx.tcx), &extra_args)
|
||||
RevealAllLayoutCx(fx.tcx).fn_abi_of_fn_ptr(fn_ty.fn_sig(fx.tcx), extra_args)
|
||||
};
|
||||
|
||||
let is_cold = instance
|
||||
|
@ -525,7 +528,8 @@ pub(crate) fn codegen_drop<'tcx>(
|
|||
def: ty::InstanceDef::Virtual(drop_instance.def_id(), 0),
|
||||
substs: drop_instance.substs,
|
||||
};
|
||||
let fn_abi = FnAbi::of_instance(&RevealAllLayoutCx(fx.tcx), virtual_drop, &[]);
|
||||
let fn_abi =
|
||||
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(virtual_drop, ty::List::empty());
|
||||
|
||||
let sig = clif_sig_from_fn_abi(fx.tcx, fx.triple(), &fn_abi);
|
||||
let sig = fx.bcx.import_signature(sig);
|
||||
|
@ -534,7 +538,8 @@ pub(crate) fn codegen_drop<'tcx>(
|
|||
_ => {
|
||||
assert!(!matches!(drop_instance.def, InstanceDef::Virtual(_, _)));
|
||||
|
||||
let fn_abi = FnAbi::of_instance(&RevealAllLayoutCx(fx.tcx), drop_instance, &[]);
|
||||
let fn_abi =
|
||||
RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(drop_instance, ty::List::empty());
|
||||
|
||||
let arg_value = drop_place.place_ref(
|
||||
fx,
|
||||
|
|
12
src/base.rs
12
src/base.rs
|
@ -3,8 +3,7 @@
|
|||
use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::ty::adjustment::PointerCast;
|
||||
use rustc_middle::ty::layout::FnAbiExt;
|
||||
use rustc_target::abi::call::FnAbi;
|
||||
use rustc_middle::ty::layout::FnAbiOf;
|
||||
|
||||
use crate::constant::ConstantCx;
|
||||
use crate::prelude::*;
|
||||
|
@ -62,7 +61,7 @@ pub(crate) fn codegen_fn<'tcx>(
|
|||
instance,
|
||||
symbol_name,
|
||||
mir,
|
||||
fn_abi: Some(FnAbi::of_instance(&RevealAllLayoutCx(tcx), instance, &[])),
|
||||
fn_abi: Some(RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty())),
|
||||
|
||||
bcx,
|
||||
block_map,
|
||||
|
@ -702,6 +701,13 @@ fn codegen_stmt<'tcx>(
|
|||
let len = codegen_array_len(fx, place);
|
||||
lval.write_cvalue(fx, CValue::by_val(len, usize_layout));
|
||||
}
|
||||
Rvalue::ShallowInitBox(ref operand, content_ty) => {
|
||||
let content_ty = fx.monomorphize(content_ty);
|
||||
let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty));
|
||||
let operand = codegen_operand(fx, operand);
|
||||
let operand = operand.load_scalar(fx);
|
||||
lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
|
||||
}
|
||||
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
|
||||
let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap();
|
||||
let content_ty = fx.monomorphize(content_ty);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers};
|
||||
use rustc_middle::ty::layout::{
|
||||
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers,
|
||||
};
|
||||
use rustc_middle::ty::SymbolName;
|
||||
use rustc_target::abi::call::FnAbi;
|
||||
use rustc_target::abi::{Integer, Primitive};
|
||||
|
@ -239,7 +241,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
|
|||
pub(crate) instance: Instance<'tcx>,
|
||||
pub(crate) symbol_name: SymbolName<'tcx>,
|
||||
pub(crate) mir: &'tcx Body<'tcx>,
|
||||
pub(crate) fn_abi: Option<FnAbi<'tcx, Ty<'tcx>>>,
|
||||
pub(crate) fn_abi: Option<&'tcx FnAbi<'tcx, Ty<'tcx>>>,
|
||||
|
||||
pub(crate) bcx: FunctionBuilder<'clif>,
|
||||
pub(crate) block_map: IndexVec<BasicBlock, Block>,
|
||||
|
@ -266,6 +268,20 @@ impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
|
||||
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;
|
||||
|
||||
#[inline]
|
||||
fn handle_fn_abi_err(
|
||||
&self,
|
||||
err: FnAbiError<'tcx>,
|
||||
span: Span,
|
||||
fn_abi_request: FnAbiRequest<'tcx>,
|
||||
) -> ! {
|
||||
RevealAllLayoutCx(self.tcx).handle_fn_abi_err(err, span, fn_abi_request)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> layout::HasTyCtxt<'tcx> for FunctionCx<'_, '_, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
|
@ -378,6 +394,43 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
|
||||
type FnAbiOfResult = &'tcx FnAbi<'tcx, Ty<'tcx>>;
|
||||
|
||||
#[inline]
|
||||
fn handle_fn_abi_err(
|
||||
&self,
|
||||
err: FnAbiError<'tcx>,
|
||||
span: Span,
|
||||
fn_abi_request: FnAbiRequest<'tcx>,
|
||||
) -> ! {
|
||||
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
|
||||
self.0.sess.span_fatal(span, &err.to_string())
|
||||
} else {
|
||||
match fn_abi_request {
|
||||
FnAbiRequest::OfFnPtr { sig, extra_args } => {
|
||||
span_bug!(
|
||||
span,
|
||||
"`fn_abi_of_fn_ptr({}, {:?})` failed: {}",
|
||||
sig,
|
||||
extra_args,
|
||||
err
|
||||
);
|
||||
}
|
||||
FnAbiRequest::OfInstance { instance, extra_args } => {
|
||||
span_bug!(
|
||||
span,
|
||||
"`fn_abi_of_instance({}, {:?})` failed: {}",
|
||||
instance,
|
||||
extra_args,
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> layout::HasTyCtxt<'tcx> for RevealAllLayoutCx<'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
|
||||
self.0
|
||||
|
|
|
@ -129,9 +129,7 @@ pub(crate) fn codegen_constant<'tcx>(
|
|||
};
|
||||
let const_val = match const_.val {
|
||||
ConstKind::Value(const_val) => const_val,
|
||||
ConstKind::Unevaluated(uv)
|
||||
if fx.tcx.is_static(uv.def.did) =>
|
||||
{
|
||||
ConstKind::Unevaluated(uv) if fx.tcx.is_static(uv.def.did) => {
|
||||
assert!(uv.substs(fx.tcx).is_empty());
|
||||
assert!(uv.promoted.is_none());
|
||||
|
||||
|
|
|
@ -61,9 +61,8 @@ use cranelift_codegen::{
|
|||
write::{FuncWriter, PlainWriter},
|
||||
};
|
||||
|
||||
use rustc_middle::ty::layout::FnAbiExt;
|
||||
use rustc_middle::ty::layout::FnAbiOf;
|
||||
use rustc_session::config::OutputType;
|
||||
use rustc_target::abi::call::FnAbi;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -81,7 +80,10 @@ impl CommentWriter {
|
|||
vec![
|
||||
format!("symbol {}", tcx.symbol_name(instance).name),
|
||||
format!("instance {:?}", instance),
|
||||
format!("abi {:?}", FnAbi::of_instance(&RevealAllLayoutCx(tcx), instance, &[])),
|
||||
format!(
|
||||
"abi {:?}",
|
||||
RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty())
|
||||
),
|
||||
String::new(),
|
||||
]
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue