Skip to content

Commit 1c98947

Browse files
committed
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.
1 parent 5a9b116 commit 1c98947

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

Diff for: src/abi/comments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(super) fn add_arg_comment<'tcx>(
2424
local: Option<mir::Local>,
2525
local_field: Option<usize>,
2626
params: &[Value],
27-
arg_abi_mode: PassMode,
27+
arg_abi_mode: &PassMode,
2828
arg_layout: TyAndLayout<'tcx>,
2929
) {
3030
if !fx.clif_comments.enabled() {

Diff for: src/abi/pass_mode.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn apply_arg_attrs_to_abi_param(mut param: AbiParam, arg_attrs: ArgAttributes) -
3838
param
3939
}
4040

41-
fn cast_target_to_abi_params(cast: CastTarget) -> SmallVec<[AbiParam; 2]> {
41+
fn cast_target_to_abi_params(cast: &CastTarget) -> SmallVec<[AbiParam; 2]> {
4242
let (rest_count, rem_bytes) = if cast.rest.unit.size.bytes() == 0 {
4343
(0, 0)
4444
} else {
@@ -100,7 +100,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
100100
}
101101
_ => unreachable!("{:?}", self.layout.abi),
102102
},
103-
PassMode::Cast(cast) => cast_target_to_abi_params(cast),
103+
PassMode::Cast(ref cast) => cast_target_to_abi_params(cast),
104104
PassMode::Indirect { attrs, extra_attrs: None, on_stack } => {
105105
if on_stack {
106106
// Abi requires aligning struct size to pointer size
@@ -145,7 +145,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
145145
}
146146
_ => unreachable!("{:?}", self.layout.abi),
147147
},
148-
PassMode::Cast(cast) => (None, cast_target_to_abi_params(cast).into_iter().collect()),
148+
PassMode::Cast(ref cast) => {
149+
(None, cast_target_to_abi_params(cast).into_iter().collect())
150+
}
149151
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack } => {
150152
assert!(!on_stack);
151153
(Some(AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructReturn)), vec![])
@@ -160,7 +162,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
160162
pub(super) fn to_casted_value<'tcx>(
161163
fx: &mut FunctionCx<'_, '_, 'tcx>,
162164
arg: CValue<'tcx>,
163-
cast: CastTarget,
165+
cast: &CastTarget,
164166
) -> SmallVec<[Value; 2]> {
165167
let (ptr, meta) = arg.force_stack(fx);
166168
assert!(meta.is_none());
@@ -179,7 +181,7 @@ pub(super) fn from_casted_value<'tcx>(
179181
fx: &mut FunctionCx<'_, '_, 'tcx>,
180182
block_params: &[Value],
181183
layout: TyAndLayout<'tcx>,
182-
cast: CastTarget,
184+
cast: &CastTarget,
183185
) -> CValue<'tcx> {
184186
let abi_params = cast_target_to_abi_params(cast);
185187
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>(
224226
let (a, b) = arg.load_scalar_pair(fx);
225227
smallvec![a, b]
226228
}
227-
PassMode::Cast(cast) => to_casted_value(fx, arg, cast),
229+
PassMode::Cast(ref cast) => to_casted_value(fx, arg, cast),
228230
PassMode::Indirect { .. } => {
229231
if is_owned {
230232
match arg.force_stack(fx) {
@@ -268,7 +270,7 @@ pub(super) fn cvalue_for_param<'tcx>(
268270
local,
269271
local_field,
270272
&block_params,
271-
arg_abi.mode,
273+
&arg_abi.mode,
272274
arg_abi.layout,
273275
);
274276

@@ -282,7 +284,9 @@ pub(super) fn cvalue_for_param<'tcx>(
282284
assert_eq!(block_params.len(), 2, "{:?}", block_params);
283285
Some(CValue::by_val_pair(block_params[0], block_params[1], arg_abi.layout))
284286
}
285-
PassMode::Cast(cast) => Some(from_casted_value(fx, &block_params, arg_abi.layout, cast)),
287+
PassMode::Cast(ref cast) => {
288+
Some(from_casted_value(fx, &block_params, arg_abi.layout, cast))
289+
}
286290
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
287291
assert_eq!(block_params.len(), 1, "{:?}", block_params);
288292
Some(CValue::by_ref(Pointer::new(block_params[0]), arg_abi.layout))

Diff for: src/abi/returning.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(super) fn codegen_return_param<'tcx>(
4444
Some(RETURN_PLACE),
4545
None,
4646
&ret_param,
47-
fx.fn_abi.as_ref().unwrap().ret.mode,
47+
&fx.fn_abi.as_ref().unwrap().ret.mode,
4848
fx.fn_abi.as_ref().unwrap().ret.layout,
4949
);
5050

@@ -92,7 +92,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
9292
ret_place
9393
.write_cvalue(fx, CValue::by_val_pair(ret_val_a, ret_val_b, ret_arg_abi.layout));
9494
}
95-
PassMode::Cast(cast) => {
95+
PassMode::Cast(ref cast) => {
9696
let results =
9797
fx.bcx.inst_results(call_inst).iter().copied().collect::<SmallVec<[Value; 2]>>();
9898
let result =
@@ -131,7 +131,7 @@ pub(crate) fn codegen_return(fx: &mut FunctionCx<'_, '_, '_>) {
131131
let (ret_val_a, ret_val_b) = place.to_cvalue(fx).load_scalar_pair(fx);
132132
fx.bcx.ins().return_(&[ret_val_a, ret_val_b]);
133133
}
134-
PassMode::Cast(cast) => {
134+
PassMode::Cast(ref cast) => {
135135
let place = fx.get_local_place(RETURN_PLACE);
136136
let ret_val = place.to_cvalue(fx);
137137
let ret_vals = super::pass_mode::to_casted_value(fx, ret_val, cast);

0 commit comments

Comments
 (0)