Box CastTarget
within PassMode
.
Because `PassMode::Cast` is by far the largest variant, but is relatively rare. This requires making `PassMode` not impl `Copy`, and `Clone` is no longer necessary. This causes lots of sigil adjusting, but nothing very notable.
This commit is contained in:
parent
5a9b11648f
commit
1c989472e4
3 changed files with 16 additions and 12 deletions
|
@ -24,7 +24,7 @@ pub(super) fn add_arg_comment<'tcx>(
|
||||||
local: Option<mir::Local>,
|
local: Option<mir::Local>,
|
||||||
local_field: Option<usize>,
|
local_field: Option<usize>,
|
||||||
params: &[Value],
|
params: &[Value],
|
||||||
arg_abi_mode: PassMode,
|
arg_abi_mode: &PassMode,
|
||||||
arg_layout: TyAndLayout<'tcx>,
|
arg_layout: TyAndLayout<'tcx>,
|
||||||
) {
|
) {
|
||||||
if !fx.clif_comments.enabled() {
|
if !fx.clif_comments.enabled() {
|
||||||
|
|
|
@ -38,7 +38,7 @@ fn apply_arg_attrs_to_abi_param(mut param: AbiParam, arg_attrs: ArgAttributes) -
|
||||||
param
|
param
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cast_target_to_abi_params(cast: CastTarget) -> SmallVec<[AbiParam; 2]> {
|
fn cast_target_to_abi_params(cast: &CastTarget) -> SmallVec<[AbiParam; 2]> {
|
||||||
let (rest_count, rem_bytes) = if cast.rest.unit.size.bytes() == 0 {
|
let (rest_count, rem_bytes) = if cast.rest.unit.size.bytes() == 0 {
|
||||||
(0, 0)
|
(0, 0)
|
||||||
} else {
|
} else {
|
||||||
|
@ -100,7 +100,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
|
||||||
}
|
}
|
||||||
_ => unreachable!("{:?}", self.layout.abi),
|
_ => unreachable!("{:?}", self.layout.abi),
|
||||||
},
|
},
|
||||||
PassMode::Cast(cast) => cast_target_to_abi_params(cast),
|
PassMode::Cast(ref cast) => cast_target_to_abi_params(cast),
|
||||||
PassMode::Indirect { attrs, extra_attrs: None, on_stack } => {
|
PassMode::Indirect { attrs, extra_attrs: None, on_stack } => {
|
||||||
if on_stack {
|
if on_stack {
|
||||||
// Abi requires aligning struct size to pointer size
|
// Abi requires aligning struct size to pointer size
|
||||||
|
@ -145,7 +145,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
|
||||||
}
|
}
|
||||||
_ => unreachable!("{:?}", self.layout.abi),
|
_ => unreachable!("{:?}", self.layout.abi),
|
||||||
},
|
},
|
||||||
PassMode::Cast(cast) => (None, cast_target_to_abi_params(cast).into_iter().collect()),
|
PassMode::Cast(ref cast) => {
|
||||||
|
(None, cast_target_to_abi_params(cast).into_iter().collect())
|
||||||
|
}
|
||||||
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack } => {
|
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack } => {
|
||||||
assert!(!on_stack);
|
assert!(!on_stack);
|
||||||
(Some(AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructReturn)), vec![])
|
(Some(AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructReturn)), vec![])
|
||||||
|
@ -160,7 +162,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
|
||||||
pub(super) fn to_casted_value<'tcx>(
|
pub(super) fn to_casted_value<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||||
arg: CValue<'tcx>,
|
arg: CValue<'tcx>,
|
||||||
cast: CastTarget,
|
cast: &CastTarget,
|
||||||
) -> SmallVec<[Value; 2]> {
|
) -> SmallVec<[Value; 2]> {
|
||||||
let (ptr, meta) = arg.force_stack(fx);
|
let (ptr, meta) = arg.force_stack(fx);
|
||||||
assert!(meta.is_none());
|
assert!(meta.is_none());
|
||||||
|
@ -179,7 +181,7 @@ pub(super) fn from_casted_value<'tcx>(
|
||||||
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
||||||
block_params: &[Value],
|
block_params: &[Value],
|
||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
cast: CastTarget,
|
cast: &CastTarget,
|
||||||
) -> CValue<'tcx> {
|
) -> CValue<'tcx> {
|
||||||
let abi_params = cast_target_to_abi_params(cast);
|
let abi_params = cast_target_to_abi_params(cast);
|
||||||
let abi_param_size: u32 = abi_params.iter().map(|param| param.value_type.bytes()).sum();
|
let abi_param_size: u32 = abi_params.iter().map(|param| param.value_type.bytes()).sum();
|
||||||
|
@ -224,7 +226,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
|
||||||
let (a, b) = arg.load_scalar_pair(fx);
|
let (a, b) = arg.load_scalar_pair(fx);
|
||||||
smallvec![a, b]
|
smallvec![a, b]
|
||||||
}
|
}
|
||||||
PassMode::Cast(cast) => to_casted_value(fx, arg, cast),
|
PassMode::Cast(ref cast) => to_casted_value(fx, arg, cast),
|
||||||
PassMode::Indirect { .. } => {
|
PassMode::Indirect { .. } => {
|
||||||
if is_owned {
|
if is_owned {
|
||||||
match arg.force_stack(fx) {
|
match arg.force_stack(fx) {
|
||||||
|
@ -268,7 +270,7 @@ pub(super) fn cvalue_for_param<'tcx>(
|
||||||
local,
|
local,
|
||||||
local_field,
|
local_field,
|
||||||
&block_params,
|
&block_params,
|
||||||
arg_abi.mode,
|
&arg_abi.mode,
|
||||||
arg_abi.layout,
|
arg_abi.layout,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -282,7 +284,9 @@ pub(super) fn cvalue_for_param<'tcx>(
|
||||||
assert_eq!(block_params.len(), 2, "{:?}", block_params);
|
assert_eq!(block_params.len(), 2, "{:?}", block_params);
|
||||||
Some(CValue::by_val_pair(block_params[0], block_params[1], arg_abi.layout))
|
Some(CValue::by_val_pair(block_params[0], block_params[1], arg_abi.layout))
|
||||||
}
|
}
|
||||||
PassMode::Cast(cast) => Some(from_casted_value(fx, &block_params, arg_abi.layout, cast)),
|
PassMode::Cast(ref cast) => {
|
||||||
|
Some(from_casted_value(fx, &block_params, arg_abi.layout, cast))
|
||||||
|
}
|
||||||
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
|
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
|
||||||
assert_eq!(block_params.len(), 1, "{:?}", block_params);
|
assert_eq!(block_params.len(), 1, "{:?}", block_params);
|
||||||
Some(CValue::by_ref(Pointer::new(block_params[0]), arg_abi.layout))
|
Some(CValue::by_ref(Pointer::new(block_params[0]), arg_abi.layout))
|
||||||
|
|
|
@ -44,7 +44,7 @@ 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.as_ref().unwrap().ret.mode,
|
||||||
fx.fn_abi.as_ref().unwrap().ret.layout,
|
fx.fn_abi.as_ref().unwrap().ret.layout,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
|
||||||
ret_place
|
ret_place
|
||||||
.write_cvalue(fx, CValue::by_val_pair(ret_val_a, ret_val_b, ret_arg_abi.layout));
|
.write_cvalue(fx, CValue::by_val_pair(ret_val_a, ret_val_b, ret_arg_abi.layout));
|
||||||
}
|
}
|
||||||
PassMode::Cast(cast) => {
|
PassMode::Cast(ref cast) => {
|
||||||
let results =
|
let results =
|
||||||
fx.bcx.inst_results(call_inst).iter().copied().collect::<SmallVec<[Value; 2]>>();
|
fx.bcx.inst_results(call_inst).iter().copied().collect::<SmallVec<[Value; 2]>>();
|
||||||
let result =
|
let result =
|
||||||
|
@ -131,7 +131,7 @@ pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) {
|
||||||
let (ret_val_a, ret_val_b) = place.to_cvalue(fx).load_scalar_pair(fx);
|
let (ret_val_a, ret_val_b) = place.to_cvalue(fx).load_scalar_pair(fx);
|
||||||
fx.bcx.ins().return_(&[ret_val_a, ret_val_b]);
|
fx.bcx.ins().return_(&[ret_val_a, ret_val_b]);
|
||||||
}
|
}
|
||||||
PassMode::Cast(cast) => {
|
PassMode::Cast(ref cast) => {
|
||||||
let place = fx.get_local_place(RETURN_PLACE);
|
let place = fx.get_local_place(RETURN_PLACE);
|
||||||
let ret_val = place.to_cvalue(fx);
|
let ret_val = place.to_cvalue(fx);
|
||||||
let ret_vals = super::pass_mode::to_casted_value(fx, ret_val, cast);
|
let ret_vals = super::pass_mode::to_casted_value(fx, ret_val, cast);
|
||||||
|
|
Loading…
Add table
Reference in a new issue