Reduce sig data size by changing sized spaces (#5402)

* Reduce sig sizes

* Fix test

* Change compute_args_loc to return u32
This commit is contained in:
Timothy Chen
2022-12-12 07:32:30 +08:00
committed by GitHub
parent 244dce93f6
commit 8035945502
5 changed files with 43 additions and 41 deletions

View File

@@ -29,7 +29,7 @@ pub(crate) type AArch64Caller = Caller<AArch64MachineDeps>;
/// This is the limit for the size of argument and return-value areas on the
/// stack. We place a reasonable limit here to avoid integer overflow issues
/// with 32-bit arithmetic: for now, 128 MB.
static STACK_ARG_RET_SIZE_LIMIT: u64 = 128 * 1024 * 1024;
static STACK_ARG_RET_SIZE_LIMIT: u32 = 128 * 1024 * 1024;
impl Into<AMode> for StackAMode {
fn into(self) -> AMode {
@@ -94,7 +94,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
args_or_rets: ArgsOrRets,
add_ret_area_ptr: bool,
mut args: ArgsAccumulator<'_>,
) -> CodegenResult<(i64, Option<usize>)>
) -> CodegenResult<(u32, Option<usize>)>
where
I: IntoIterator<Item = &'a ir::AbiParam>,
{
@@ -116,7 +116,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
let mut next_xreg = 0;
let mut next_vreg = 0;
let mut next_stack: u64 = 0;
let mut next_stack: u32 = 0;
let (max_per_class_reg_vals, mut remaining_reg_vals) = match args_or_rets {
ArgsOrRets::Args => (8, 16), // x0-x7 and v0-v7
@@ -152,13 +152,13 @@ impl ABIMachineSpec for AArch64MachineDeps {
if let ir::ArgumentPurpose::StructArgument(size) = param.purpose {
assert_eq!(args_or_rets, ArgsOrRets::Args);
let offset = next_stack as i64;
let size = size as u64;
let size = size;
assert!(size % 8 == 0, "StructArgument size is not properly aligned");
next_stack += size;
args.push(ABIArg::StructArg {
pointer: None,
offset,
size,
size: size as u64,
purpose: param.purpose,
});
continue;
@@ -282,7 +282,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
// Spill to the stack
// Compute the stack slot's size.
let size = (ty_bits(param.value_type) / 8) as u64;
let size = (ty_bits(param.value_type) / 8) as u32;
let size = if is_apple_cc
|| (call_conv.extends_wasmtime() && args_or_rets == ArgsOrRets::Rets)
@@ -308,7 +308,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
// Build the stack locations from each slot
.scan(next_stack, |next_stack, ty| {
let slot_offset = *next_stack as i64;
*next_stack += (ty_bits(ty) / 8) as u64;
*next_stack += (ty_bits(ty) / 8) as u32;
Some((ty, slot_offset))
})
@@ -358,7 +358,7 @@ impl ABIMachineSpec for AArch64MachineDeps {
return Err(CodegenError::ImplLimitExceeded);
}
Ok((next_stack as i64, extra_arg))
Ok((next_stack, extra_arg))
}
fn fp_to_arg_offset(_call_conv: isa::CallConv, _flags: &settings::Flags) -> i64 {

View File

@@ -35,7 +35,7 @@ pub(crate) type Riscv64ABICaller = Caller<Riscv64MachineDeps>;
/// This is the limit for the size of argument and return-value areas on the
/// stack. We place a reasonable limit here to avoid integer overflow issues
/// with 32-bit arithmetic: for now, 128 MB.
static STACK_ARG_RET_SIZE_LIMIT: u64 = 128 * 1024 * 1024;
static STACK_ARG_RET_SIZE_LIMIT: u32 = 128 * 1024 * 1024;
/// Riscv64-specific ABI behavior. This struct just serves as an implementation
/// point for the trait; it is never actually instantiated.
@@ -63,7 +63,7 @@ impl ABIMachineSpec for Riscv64MachineDeps {
args_or_rets: ArgsOrRets,
add_ret_area_ptr: bool,
mut args: ArgsAccumulator<'_>,
) -> CodegenResult<(i64, Option<usize>)>
) -> CodegenResult<(u32, Option<usize>)>
where
I: IntoIterator<Item = &'a ir::AbiParam>,
{
@@ -78,14 +78,14 @@ impl ABIMachineSpec for Riscv64MachineDeps {
let mut next_x_reg = x_start;
let mut next_f_reg = f_start;
// Stack space.
let mut next_stack: u64 = 0;
let mut next_stack: u32 = 0;
let mut return_one_register_used = false;
for param in params {
if let ir::ArgumentPurpose::StructArgument(size) = param.purpose {
let offset = next_stack;
assert!(size % 8 == 0, "StructArgument size is not properly aligned");
next_stack += size as u64;
next_stack += size;
args.push(ABIArg::StructArg {
pointer: None,
offset: offset as i64,
@@ -135,7 +135,7 @@ impl ABIMachineSpec for Riscv64MachineDeps {
//
// Note that in all cases 16-byte stack alignment happens
// separately after all args.
let size = (reg_ty.bits() / 8) as u64;
let size = reg_ty.bits() / 8;
let size = if args_or_rets == ArgsOrRets::Rets && call_conv.extends_wasmtime() {
size
} else {
@@ -181,13 +181,13 @@ impl ABIMachineSpec for Riscv64MachineDeps {
} else {
None
};
next_stack = align_to(next_stack, Self::stack_align(call_conv) as u64);
next_stack = align_to(next_stack, Self::stack_align(call_conv));
// To avoid overflow issues, limit the arg/return size to something
// reasonable -- here, 128 MB.
if next_stack > STACK_ARG_RET_SIZE_LIMIT {
return Err(CodegenError::ImplLimitExceeded);
}
CodegenResult::Ok((next_stack as i64, pos))
CodegenResult::Ok((next_stack, pos))
}
fn fp_to_arg_offset(_call_conv: isa::CallConv, _flags: &settings::Flags) -> i64 {

View File

@@ -184,7 +184,7 @@ fn get_vecreg_for_ret(idx: usize) -> Option<Reg> {
/// This is the limit for the size of argument and return-value areas on the
/// stack. We place a reasonable limit here to avoid integer overflow issues
/// with 32-bit arithmetic: for now, 128 MB.
static STACK_ARG_RET_SIZE_LIMIT: u64 = 128 * 1024 * 1024;
static STACK_ARG_RET_SIZE_LIMIT: u32 = 128 * 1024 * 1024;
/// The size of the register save area
pub static REG_SAVE_AREA_SIZE: u32 = 160;
@@ -228,17 +228,17 @@ impl ABIMachineSpec for S390xMachineDeps {
args_or_rets: ArgsOrRets,
add_ret_area_ptr: bool,
mut args: ArgsAccumulator<'_>,
) -> CodegenResult<(i64, Option<usize>)>
) -> CodegenResult<(u32, Option<usize>)>
where
I: IntoIterator<Item = &'a ir::AbiParam>,
{
let mut next_gpr = 0;
let mut next_fpr = 0;
let mut next_vr = 0;
let mut next_stack: u64 = 0;
let mut next_stack: u32 = 0;
if args_or_rets == ArgsOrRets::Args {
next_stack = REG_SAVE_AREA_SIZE as u64;
next_stack = REG_SAVE_AREA_SIZE;
}
// In the SystemV ABI, the return area pointer is the first argument,
@@ -307,7 +307,7 @@ impl ABIMachineSpec for S390xMachineDeps {
} else {
// Compute size. Every argument or return value takes a slot of
// at least 8 bytes, except for return values in the Wasmtime ABI.
let size = (ty_bits(param.value_type) / 8) as u64;
let size = (ty_bits(param.value_type) / 8) as u32;
let slot_size = if call_conv.extends_wasmtime() && args_or_rets == ArgsOrRets::Rets
{
size
@@ -401,11 +401,11 @@ impl ABIMachineSpec for S390xMachineDeps {
match arg {
ABIArg::StructArg { offset, size, .. } => {
*offset = next_stack as i64;
next_stack += *size;
next_stack += *size as u32;
}
ABIArg::ImplicitPtrArg { offset, ty, .. } => {
*offset = next_stack as i64;
next_stack += (ty_bits(*ty) / 8) as u64;
next_stack += (ty_bits(*ty) / 8) as u32;
}
_ => {}
}
@@ -417,7 +417,7 @@ impl ABIMachineSpec for S390xMachineDeps {
return Err(CodegenError::ImplLimitExceeded);
}
Ok((next_stack as i64, extra_arg))
Ok((next_stack, extra_arg))
}
fn fp_to_arg_offset(_call_conv: isa::CallConv, _flags: &settings::Flags) -> i64 {

View File

@@ -18,7 +18,7 @@ use std::convert::TryFrom;
/// This is the limit for the size of argument and return-value areas on the
/// stack. We place a reasonable limit here to avoid integer overflow issues
/// with 32-bit arithmetic: for now, 128 MB.
static STACK_ARG_RET_SIZE_LIMIT: u64 = 128 * 1024 * 1024;
static STACK_ARG_RET_SIZE_LIMIT: u32 = 128 * 1024 * 1024;
/// Support for the x64 ABI from the callee side (within a function body).
pub(crate) type X64Callee = Callee<X64ABIMachineSpec>;
@@ -87,7 +87,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
args_or_rets: ArgsOrRets,
add_ret_area_ptr: bool,
mut args: ArgsAccumulator<'_>,
) -> CodegenResult<(i64, Option<usize>)>
) -> CodegenResult<(u32, Option<usize>)>
where
I: IntoIterator<Item = &'a ir::AbiParam>,
{
@@ -95,7 +95,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
let mut next_gpr = 0;
let mut next_vreg = 0;
let mut next_stack: u64 = 0;
let mut next_stack: u32 = 0;
let mut next_param_idx = 0; // Fastcall cares about overall param index
if args_or_rets == ArgsOrRets::Args && is_fastcall {
@@ -110,13 +110,13 @@ impl ABIMachineSpec for X64ABIMachineSpec {
for param in params {
if let ir::ArgumentPurpose::StructArgument(size) = param.purpose {
let offset = next_stack as i64;
let size = size as u64;
let size = size;
assert!(size % 8 == 0, "StructArgument size is not properly aligned");
next_stack += size;
args.push(ABIArg::StructArg {
pointer: None,
offset,
size,
size: size as u64,
purpose: param.purpose,
});
continue;
@@ -197,7 +197,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
//
// Note that in all cases 16-byte stack alignment happens
// separately after all args.
let size = (reg_ty.bits() / 8) as u64;
let size = reg_ty.bits() / 8;
let size = if args_or_rets == ArgsOrRets::Rets && call_conv.extends_wasmtime() {
size
} else {
@@ -251,7 +251,7 @@ impl ABIMachineSpec for X64ABIMachineSpec {
return Err(CodegenError::ImplLimitExceeded);
}
Ok((next_stack as i64, extra_arg))
Ok((next_stack, extra_arg))
}
fn fp_to_arg_offset(_call_conv: isa::CallConv, _flags: &settings::Flags) -> i64 {