Skip to content

Commit 1239a02

Browse files
committed
Auto merge of #100999 - nnethercote:shrink-FnAbi, r=bjorn3
Shrink `FnAbi` Because they can take up a lot of memory in debug and release builds. r? `@bjorn3`
2 parents d9bbac0 + 2d2a3be commit 1239a02

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

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() {

src/abi/pass_mode.rs

+15-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,10 @@ 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, pad_i32) => {
104+
assert!(!pad_i32, "padding support not yet implemented");
105+
cast_target_to_abi_params(cast)
106+
}
104107
PassMode::Indirect { attrs, extra_attrs: None, on_stack } => {
105108
if on_stack {
106109
// Abi requires aligning struct size to pointer size
@@ -145,7 +148,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
145148
}
146149
_ => unreachable!("{:?}", self.layout.abi),
147150
},
148-
PassMode::Cast(cast) => (None, cast_target_to_abi_params(cast).into_iter().collect()),
151+
PassMode::Cast(ref cast, _) => {
152+
(None, cast_target_to_abi_params(cast).into_iter().collect())
153+
}
149154
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack } => {
150155
assert!(!on_stack);
151156
(Some(AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructReturn)), vec![])
@@ -160,7 +165,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
160165
pub(super) fn to_casted_value<'tcx>(
161166
fx: &mut FunctionCx<'_, '_, 'tcx>,
162167
arg: CValue<'tcx>,
163-
cast: CastTarget,
168+
cast: &CastTarget,
164169
) -> SmallVec<[Value; 2]> {
165170
let (ptr, meta) = arg.force_stack(fx);
166171
assert!(meta.is_none());
@@ -179,7 +184,7 @@ pub(super) fn from_casted_value<'tcx>(
179184
fx: &mut FunctionCx<'_, '_, 'tcx>,
180185
block_params: &[Value],
181186
layout: TyAndLayout<'tcx>,
182-
cast: CastTarget,
187+
cast: &CastTarget,
183188
) -> CValue<'tcx> {
184189
let abi_params = cast_target_to_abi_params(cast);
185190
let abi_param_size: u32 = abi_params.iter().map(|param| param.value_type.bytes()).sum();
@@ -224,7 +229,7 @@ pub(super) fn adjust_arg_for_abi<'tcx>(
224229
let (a, b) = arg.load_scalar_pair(fx);
225230
smallvec![a, b]
226231
}
227-
PassMode::Cast(cast) => to_casted_value(fx, arg, cast),
232+
PassMode::Cast(ref cast, _) => to_casted_value(fx, arg, cast),
228233
PassMode::Indirect { .. } => {
229234
if is_owned {
230235
match arg.force_stack(fx) {
@@ -268,7 +273,7 @@ pub(super) fn cvalue_for_param<'tcx>(
268273
local,
269274
local_field,
270275
&block_params,
271-
arg_abi.mode,
276+
&arg_abi.mode,
272277
arg_abi.layout,
273278
);
274279

@@ -282,7 +287,9 @@ pub(super) fn cvalue_for_param<'tcx>(
282287
assert_eq!(block_params.len(), 2, "{:?}", block_params);
283288
Some(CValue::by_val_pair(block_params[0], block_params[1], arg_abi.layout))
284289
}
285-
PassMode::Cast(cast) => Some(from_casted_value(fx, &block_params, arg_abi.layout, cast)),
290+
PassMode::Cast(ref cast, _) => {
291+
Some(from_casted_value(fx, &block_params, arg_abi.layout, cast))
292+
}
286293
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
287294
assert_eq!(block_params.len(), 1, "{:?}", block_params);
288295
Some(CValue::by_ref(Pointer::new(block_params[0]), arg_abi.layout))

src/abi/returning.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(super) fn codegen_return_param<'tcx>(
1313
block_params_iter: &mut impl Iterator<Item = Value>,
1414
) -> CPlace<'tcx> {
1515
let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode {
16-
PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(_) => {
16+
PassMode::Ignore | PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(..) => {
1717
let is_ssa = ssa_analyzed[RETURN_PLACE] == crate::analyze::SsaKind::Ssa;
1818
(
1919
super::make_local_place(
@@ -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

@@ -75,7 +75,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
7575
PassMode::Indirect { attrs: _, extra_attrs: Some(_), on_stack: _ } => {
7676
unreachable!("unsized return value")
7777
}
78-
PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(_) => (None, None),
78+
PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(..) => (None, None),
7979
};
8080

8181
let call_inst = f(fx, return_ptr);
@@ -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)