Skip to content

Commit 1a61b6e

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 5b1229e + 8900341 commit 1a61b6e

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

src/abi.rs

+12-27
Original file line numberDiff line numberDiff line change
@@ -107,45 +107,24 @@ pub trait FnAbiGccExt<'gcc, 'tcx> {
107107
impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
108108
fn gcc_type(&self, cx: &CodegenCx<'gcc, 'tcx>) -> (Type<'gcc>, Vec<Type<'gcc>>, bool, FxHashSet<usize>) {
109109
let mut on_stack_param_indices = FxHashSet::default();
110-
let args_capacity: usize = self.args.iter().map(|arg|
111-
if arg.pad.is_some() {
112-
1
113-
}
114-
else {
115-
0
116-
} +
117-
if let PassMode::Pair(_, _) = arg.mode {
118-
2
119-
} else {
120-
1
121-
}
122-
).sum();
110+
111+
// This capacity calculation is approximate.
123112
let mut argument_tys = Vec::with_capacity(
124-
if let PassMode::Indirect { .. } = self.ret.mode {
125-
1
126-
}
127-
else {
128-
0
129-
} + args_capacity,
113+
self.args.len() + if let PassMode::Indirect { .. } = self.ret.mode { 1 } else { 0 }
130114
);
131115

132116
let return_ty =
133117
match self.ret.mode {
134118
PassMode::Ignore => cx.type_void(),
135119
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_gcc_type(cx),
136-
PassMode::Cast(cast) => cast.gcc_type(cx),
120+
PassMode::Cast(ref cast, _) => cast.gcc_type(cx),
137121
PassMode::Indirect { .. } => {
138122
argument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
139123
cx.type_void()
140124
}
141125
};
142126

143-
for arg in &self.args {
144-
// add padding
145-
if let Some(ty) = arg.pad {
146-
argument_tys.push(ty.gcc_type(cx));
147-
}
148-
127+
for arg in self.args.iter() {
149128
let arg_ty = match arg.mode {
150129
PassMode::Ignore => continue,
151130
PassMode::Direct(_) => arg.layout.immediate_gcc_type(cx),
@@ -157,7 +136,13 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
157136
PassMode::Indirect { extra_attrs: Some(_), .. } => {
158137
unimplemented!();
159138
}
160-
PassMode::Cast(cast) => cast.gcc_type(cx),
139+
PassMode::Cast(ref cast, pad_i32) => {
140+
// add padding
141+
if pad_i32 {
142+
argument_tys.push(Reg::i32().gcc_type(cx));
143+
}
144+
cast.gcc_type(cx)
145+
}
161146
PassMode::Indirect { extra_attrs: None, on_stack: true, .. } => {
162147
on_stack_param_indices.insert(argument_tys.len());
163148
arg.memory_ty(cx)

src/intrinsic/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
130130
sym::volatile_load | sym::unaligned_volatile_load => {
131131
let tp_ty = substs.type_at(0);
132132
let mut ptr = args[0].immediate();
133-
if let PassMode::Cast(ty) = fn_abi.ret.mode {
133+
if let PassMode::Cast(ty, _) = &fn_abi.ret.mode {
134134
ptr = self.pointercast(ptr, self.type_ptr_to(ty.gcc_type(self)));
135135
}
136136
let load = self.volatile_load(ptr.get_type(), ptr);
@@ -320,7 +320,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
320320
};
321321

322322
if !fn_abi.ret.is_ignore() {
323-
if let PassMode::Cast(ty) = fn_abi.ret.mode {
323+
if let PassMode::Cast(ty, _) = &fn_abi.ret.mode {
324324
let ptr_llty = self.type_ptr_to(ty.gcc_type(self));
325325
let ptr = self.pointercast(result.llval, ptr_llty);
326326
self.store(llval, ptr, result.align);
@@ -416,7 +416,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
416416
else if self.is_unsized_indirect() {
417417
bug!("unsized `ArgAbi` must be handled through `store_fn_arg`");
418418
}
419-
else if let PassMode::Cast(cast) = self.mode {
419+
else if let PassMode::Cast(ref cast, _) = self.mode {
420420
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
421421
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
422422
let can_store_through_cast_ptr = false;
@@ -481,7 +481,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
481481
PassMode::Indirect { extra_attrs: Some(_), .. } => {
482482
OperandValue::Ref(next(), Some(next()), self.layout.align.abi).store(bx, dst);
483483
},
484-
PassMode::Direct(_) | PassMode::Indirect { extra_attrs: None, .. } | PassMode::Cast(_) => {
484+
PassMode::Direct(_) | PassMode::Indirect { extra_attrs: None, .. } | PassMode::Cast(..) => {
485485
let next_arg = next();
486486
self.store(bx, next_arg, dst);
487487
},

0 commit comments

Comments
 (0)