Stop taking FunctionCx's fn_abi field

This commit is contained in:
bjorn3 2024-03-27 19:49:20 +00:00
parent 69363cf9e7
commit fee1204ffa
4 changed files with 11 additions and 26 deletions

View File

@ -222,17 +222,15 @@ enum ArgKind<'tcx> {
Spread(Vec<Option<CValue<'tcx>>>), Spread(Vec<Option<CValue<'tcx>>>),
} }
let fn_abi = fx.fn_abi.take().unwrap();
// FIXME implement variadics in cranelift // FIXME implement variadics in cranelift
if fn_abi.c_variadic { if fx.fn_abi.c_variadic {
fx.tcx.dcx().span_fatal( fx.tcx.dcx().span_fatal(
fx.mir.span, fx.mir.span,
"Defining variadic functions is not yet supported by Cranelift", "Defining variadic functions is not yet supported by Cranelift",
); );
} }
let mut arg_abis_iter = fn_abi.args.iter(); let mut arg_abis_iter = fx.fn_abi.args.iter();
let func_params = fx let func_params = fx
.mir .mir
@ -279,7 +277,6 @@ enum ArgKind<'tcx> {
} }
assert!(arg_abis_iter.next().is_none(), "ArgAbi left behind"); assert!(arg_abis_iter.next().is_none(), "ArgAbi left behind");
fx.fn_abi = Some(fn_abi);
assert!(block_params_iter.next().is_none(), "arg_value left behind"); assert!(block_params_iter.next().is_none(), "arg_value left behind");
self::comments::add_locals_header_comment(fx); self::comments::add_locals_header_comment(fx);

View File

@ -12,27 +12,15 @@ pub(super) fn codegen_return_param<'tcx>(
ssa_analyzed: &rustc_index::IndexSlice<Local, crate::analyze::SsaKind>, ssa_analyzed: &rustc_index::IndexSlice<Local, crate::analyze::SsaKind>,
block_params_iter: &mut impl Iterator<Item = Value>, block_params_iter: &mut impl Iterator<Item = Value>,
) -> CPlace<'tcx> { ) -> CPlace<'tcx> {
let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode { let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.ret.mode {
PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast { .. } => { PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast { .. } => {
let is_ssa = let is_ssa = ssa_analyzed[RETURN_PLACE].is_ssa(fx, fx.fn_abi.ret.layout.ty);
ssa_analyzed[RETURN_PLACE].is_ssa(fx, fx.fn_abi.as_ref().unwrap().ret.layout.ty); (super::make_local_place(fx, RETURN_PLACE, fx.fn_abi.ret.layout, is_ssa), smallvec![])
(
super::make_local_place(
fx,
RETURN_PLACE,
fx.fn_abi.as_ref().unwrap().ret.layout,
is_ssa,
),
smallvec![],
)
} }
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => { PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
let ret_param = block_params_iter.next().unwrap(); let ret_param = block_params_iter.next().unwrap();
assert_eq!(fx.bcx.func.dfg.value_type(ret_param), fx.pointer_type); assert_eq!(fx.bcx.func.dfg.value_type(ret_param), fx.pointer_type);
( (CPlace::for_ptr(Pointer::new(ret_param), fx.fn_abi.ret.layout), smallvec![ret_param])
CPlace::for_ptr(Pointer::new(ret_param), fx.fn_abi.as_ref().unwrap().ret.layout),
smallvec![ret_param],
)
} }
PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => { PassMode::Indirect { attrs: _, meta_attrs: Some(_), on_stack: _ } => {
unreachable!("unsized return value") unreachable!("unsized return value")
@ -45,8 +33,8 @@ pub(super) fn codegen_return_param<'tcx>(
Some(RETURN_PLACE), Some(RETURN_PLACE),
None, None,
&ret_param, &ret_param,
&fx.fn_abi.as_ref().unwrap().ret.mode, &fx.fn_abi.ret.mode,
fx.fn_abi.as_ref().unwrap().ret.layout, fx.fn_abi.ret.layout,
); );
ret_place ret_place
@ -115,7 +103,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
/// Codegen a return instruction with the right return value(s) if any. /// Codegen a return instruction with the right return value(s) if any.
pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) { pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) {
match fx.fn_abi.as_ref().unwrap().ret.mode { match fx.fn_abi.ret.mode {
PassMode::Ignore | PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => { PassMode::Ignore | PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: _ } => {
fx.bcx.ins().return_(&[]); fx.bcx.ins().return_(&[]);
} }

View File

@ -87,7 +87,7 @@ pub(crate) fn codegen_fn<'tcx>(
instance, instance,
symbol_name, symbol_name,
mir, mir,
fn_abi: Some(RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty())), fn_abi: RevealAllLayoutCx(tcx).fn_abi_of_instance(instance, ty::List::empty()),
bcx, bcx,
block_map, block_map,

View File

@ -291,7 +291,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
pub(crate) instance: Instance<'tcx>, pub(crate) instance: Instance<'tcx>,
pub(crate) symbol_name: String, pub(crate) symbol_name: String,
pub(crate) mir: &'tcx Body<'tcx>, pub(crate) mir: &'tcx Body<'tcx>,
pub(crate) fn_abi: Option<&'tcx FnAbi<'tcx, Ty<'tcx>>>, pub(crate) fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
pub(crate) bcx: FunctionBuilder<'clif>, pub(crate) bcx: FunctionBuilder<'clif>,
pub(crate) block_map: IndexVec<BasicBlock, Block>, pub(crate) block_map: IndexVec<BasicBlock, Block>,