A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
cranelift: store Args/Rets pairs in Box<[T]> instead of Vec (#15197)
KutluhanETH56ef38d8df37
diff --git a/cranelift/codegen/src/isa/aarch64/abi.rs b/cranelift/codegen/src/isa/aarch64/abi.rsindex afdcddb61d..accd28cc1d 100644--- a/cranelift/codegen/src/isa/aarch64/abi.rs+++ b/cranelift/codegen/src/isa/aarch64/abi.rs@@ -502,11 +502,11 @@ impl ABIMachineSpec for AArch64MachineDeps {Inst::gen_extend(to_reg, from_reg, op, to)}- fn gen_args(args: Vec<ArgPair>) -> Inst {+ fn gen_args(args: Box<[ArgPair]>) -> Inst {Inst::Args { args }}- fn gen_rets(rets: Vec<RetPair>) -> Inst {+ fn gen_rets(rets: Box<[RetPair]>) -> Inst {Inst::Rets { rets }}diff --git a/cranelift/codegen/src/isa/aarch64/inst.isle b/cranelift/codegen/src/isa/aarch64/inst.isleindex 0686a81cbe..4987856eca 100644--- a/cranelift/codegen/src/isa/aarch64/inst.isle+++ b/cranelift/codegen/src/isa/aarch64/inst.isle@@ -911,11 +911,11 @@;; A pseudo-instruction that captures register arguments in vregs.(Args- (args VecArgPair))+ (args BoxedSliceArgPair));; A pseudo-instruction that moves vregs to return registers.(Rets- (rets VecRetPair))+ (rets BoxedSliceRetPair));; ---- branches (exactly one must appear at end of BB) ----diff --git a/cranelift/codegen/src/isa/aarch64/lower/isle.rs b/cranelift/codegen/src/isa/aarch64/lower/isle.rsindex a289b06acf..0ff4e3d390 100644--- a/cranelift/codegen/src/isa/aarch64/lower/isle.rs+++ b/cranelift/codegen/src/isa/aarch64/lower/isle.rs@@ -41,7 +41,7 @@ type BoxReturnCallInfo = Box<ReturnCallInfo<ExternalName>>;type BoxReturnCallIndInfo = Box<ReturnCallInfo<Reg>>;type VecMachLabel = Vec<MachLabel>;type BoxExternalName = Box<ExternalName>;-type VecArgPair = Vec<ArgPair>;+type BoxedSliceArgPair = Box<[ArgPair]>;type BoxAtomicCAS128Args = Box<AtomicCAS128Args>;/// The main entry point for lowering with ISLE.diff --git a/cranelift/codegen/src/isa/pulley_shared/abi.rs b/cranelift/codegen/src/isa/pulley_shared/abi.rsindex 410dfe3f6b..b7cfdbf7b0 100644--- a/cranelift/codegen/src/isa/pulley_shared/abi.rs+++ b/cranelift/codegen/src/isa/pulley_shared/abi.rs@@ -10,6 +10,7 @@ use crate::{settings,};use alloc::borrow::ToOwned;+use alloc::boxed::Box;use alloc::vec::Vec;use core::marker::PhantomData;use cranelift_bitset::ScalarBitSet;@@ -216,11 +217,11 @@ wherespecified}- fn gen_args(args: Vec<ArgPair>) -> Self::I {+ fn gen_args(args: Box<[ArgPair]>) -> Self::I {Inst::Args { args }.into()}- fn gen_rets(rets: Vec<RetPair>) -> Self::I {+ fn gen_rets(rets: Box<[RetPair]>) -> Self::I {Inst::Rets { rets }.into()}diff --git a/cranelift/codegen/src/isa/pulley_shared/inst.isle b/cranelift/codegen/src/isa/pulley_shared/inst.isleindex e9a63e1703..1fab35b693 100644--- a/cranelift/codegen/src/isa/pulley_shared/inst.isle+++ b/cranelift/codegen/src/isa/pulley_shared/inst.isle@@ -13,10 +13,10 @@;;;; Pseudo-Instructions ;;;;;; A pseudo-instruction that captures register arguments in vregs.- (Args (args VecArgPair))+ (Args (args BoxedSliceArgPair));; A pseudo-instruction that moves vregs to return registers.- (Rets (rets VecRetPair))+ (Rets (rets BoxedSliceRetPair))(DummyUse (reg Reg))diff --git a/cranelift/codegen/src/isa/pulley_shared/lower/isle.rs b/cranelift/codegen/src/isa/pulley_shared/lower/isle.rsindex 3068fb1137..b7d60e8a75 100644--- a/cranelift/codegen/src/isa/pulley_shared/lower/isle.rs+++ b/cranelift/codegen/src/isa/pulley_shared/lower/isle.rs@@ -27,8 +27,8 @@ use regalloc2::PReg;use smallvec::SmallVec;type Unit = ();-type VecArgPair = Vec<ArgPair>;-type VecRetPair = Vec<RetPair>;+type BoxedSliceArgPair = Box<[ArgPair]>;+type BoxedSliceRetPair = Box<[RetPair]>;type BoxCallInfo = Box<CallInfo<PulleyCall>>;type BoxCallIndInfo = Box<CallInfo<XReg>>;type BoxCallIndirectHostInfo = Box<CallInfo<ExternalName>>;diff --git a/cranelift/codegen/src/isa/riscv64/abi.rs b/cranelift/codegen/src/isa/riscv64/abi.rsindex b9dae93527..755849d40a 100644--- a/cranelift/codegen/src/isa/riscv64/abi.rs+++ b/cranelift/codegen/src/isa/riscv64/abi.rs@@ -230,11 +230,11 @@ impl ABIMachineSpec for Riscv64MachineDeps {specified}- fn gen_args(args: Vec<ArgPair>) -> Inst {+ fn gen_args(args: Box<[ArgPair]>) -> Inst {Inst::Args { args }}- fn gen_rets(rets: Vec<RetPair>) -> Inst {+ fn gen_rets(rets: Box<[RetPair]>) -> Inst {Inst::Rets { rets }}diff --git a/cranelift/codegen/src/isa/riscv64/inst.isle b/cranelift/codegen/src/isa/riscv64/inst.isleindex 2c9e70fd4f..0d5f6bf0de 100644--- a/cranelift/codegen/src/isa/riscv64/inst.isle+++ b/cranelift/codegen/src/isa/riscv64/inst.isle@@ -96,11 +96,11 @@;; A pseudo-instruction that captures register arguments in vregs.(Args- (args VecArgPair))+ (args BoxedSliceArgPair));; A pseudo-instruction that moves vregs to return registers.(Rets- (rets VecRetPair))+ (rets BoxedSliceRetPair))(Ret)diff --git a/cranelift/codegen/src/isa/riscv64/lower/isle.rs b/cranelift/codegen/src/isa/riscv64/lower/isle.rsindex 52e610a9b2..d545e96580 100644--- a/cranelift/codegen/src/isa/riscv64/lower/isle.rs+++ b/cranelift/codegen/src/isa/riscv64/lower/isle.rs@@ -32,7 +32,7 @@ type BoxReturnCallInfo = Box<ReturnCallInfo<ExternalName>>;type BoxReturnCallIndInfo = Box<ReturnCallInfo<Reg>>;type BoxExternalName = Box<ExternalName>;type VecMachLabel = Vec<MachLabel>;-type VecArgPair = Vec<ArgPair>;+type BoxedSliceArgPair = Box<[ArgPair]>;pub(crate) struct RV64IsleContext<'a, 'b, I, B>wherediff --git a/cranelift/codegen/src/isa/s390x/abi.rs b/cranelift/codegen/src/isa/s390x/abi.rsindex be945f22d5..c78ca27478 100644--- a/cranelift/codegen/src/isa/s390x/abi.rs+++ b/cranelift/codegen/src/isa/s390x/abi.rs@@ -145,6 +145,7 @@ use crate::isa::unwind::UnwindInst;use crate::machinst::*;use crate::settings;use alloc::borrow::ToOwned;+use alloc::boxed::Box;use alloc::vec::Vec;use regalloc2::{MachineEnv, PRegSet};use smallvec::{SmallVec, smallvec};@@ -504,11 +505,11 @@ impl ABIMachineSpec for S390xMachineDeps {}}- fn gen_args(args: Vec<ArgPair>) -> Inst {+ fn gen_args(args: Box<[ArgPair]>) -> Inst {Inst::Args { args }}- fn gen_rets(rets: Vec<RetPair>) -> Inst {+ fn gen_rets(rets: Box<[RetPair]>) -> Inst {Inst::Rets { rets }}diff --git a/cranelift/codegen/src/isa/s390x/inst.isle b/cranelift/codegen/src/isa/s390x/inst.isleindex ac1fad486a..486b06ff11 100644--- a/cranelift/codegen/src/isa/s390x/inst.isle+++ b/cranelift/codegen/src/isa/s390x/inst.isle@@ -947,11 +947,11 @@;; A pseudo-instruction that captures register arguments in vregs.(Args- (args VecArgPair))+ (args BoxedSliceArgPair));; A pseudo-instruction that moves vregs to return registers.(Rets- (rets VecRetPair))+ (rets BoxedSliceRetPair));; ---- branches (exactly one must appear at end of BB) ----diff --git a/cranelift/codegen/src/isa/s390x/lower/isle.rs b/cranelift/codegen/src/isa/s390x/lower/isle.rsindex 3a75e36de3..c0caa003d9 100644--- a/cranelift/codegen/src/isa/s390x/lower/isle.rs+++ b/cranelift/codegen/src/isa/s390x/lower/isle.rs@@ -36,7 +36,7 @@ type BoxExternalName = Box<ExternalName>;type BoxSymbolReloc = Box<SymbolReloc>;type VecMInst = Vec<MInst>;type VecMInstBuilder = Cell<Vec<MInst>>;-type VecArgPair = Vec<ArgPair>;+type BoxedSliceArgPair = Box<[ArgPair]>;/// The main entry point for lowering with ISLE.pub(crate) fn lower(diff --git a/cranelift/codegen/src/isa/x64/abi.rs b/cranelift/codegen/src/isa/x64/abi.rsindex e4818f06b2..618906239e 100644--- a/cranelift/codegen/src/isa/x64/abi.rs+++ b/cranelift/codegen/src/isa/x64/abi.rs@@ -466,11 +466,11 @@ impl ABIMachineSpec for X64ABIMachineSpec {}}- fn gen_args(args: Vec<ArgPair>) -> Inst {+ fn gen_args(args: Box<[ArgPair]>) -> Inst {Inst::Args { args }}- fn gen_rets(rets: Vec<RetPair>) -> Inst {+ fn gen_rets(rets: Box<[RetPair]>) -> Inst {Inst::Rets { rets }}diff --git a/cranelift/codegen/src/isa/x64/inst.isle b/cranelift/codegen/src/isa/x64/inst.isleindex ec2fe71e0a..d4748bc878 100644--- a/cranelift/codegen/src/isa/x64/inst.isle+++ b/cranelift/codegen/src/isa/x64/inst.isle@@ -111,11 +111,11 @@;; A pseudo-instruction that captures register arguments in vregs.(Args- (args VecArgPair))+ (args BoxedSliceArgPair));; A pseudo-instruction that moves vregs to return registers.(Rets- (rets VecRetPair))+ (rets BoxedSliceRetPair));; Stack switching(StackSwitchBasic (store_context_ptr Gpr)diff --git a/cranelift/codegen/src/isa/x64/lower/isle.rs b/cranelift/codegen/src/isa/x64/lower/isle.rsindex f0a43025f1..cf6310bdf2 100644--- a/cranelift/codegen/src/isa/x64/lower/isle.rs+++ b/cranelift/codegen/src/isa/x64/lower/isle.rs@@ -33,7 +33,7 @@ type BoxCallInfo = Box<CallInfo<ExternalName>>;type BoxCallIndInfo = Box<CallInfo<RegMem>>;type BoxReturnCallInfo = Box<ReturnCallInfo<ExternalName>>;type BoxReturnCallIndInfo = Box<ReturnCallInfo<Reg>>;-type VecArgPair = Vec<ArgPair>;+type BoxedSliceArgPair = Box<[ArgPair]>;type BoxAtomic128RmwSeqArgs = Box<Atomic128RmwSeqArgs>;type BoxAtomic128XchgSeqArgs = Box<Atomic128XchgSeqArgs>;diff --git a/cranelift/codegen/src/machinst/abi.rs b/cranelift/codegen/src/machinst/abi.rsindex da2cef54d5..d7d52c5f82 100644--- a/cranelift/codegen/src/machinst/abi.rs+++ b/cranelift/codegen/src/machinst/abi.rs@@ -118,7 +118,7 @@ use smallvec::smallvec;pub type SmallInstVec<I> = SmallVec<[I; 4]>;/// A type used by backends to track argument-binding info in the "args"-/// pseudoinst. The pseudoinst holds a vec of `ArgPair` structs.+/// pseudoinst. The pseudoinst holds a boxed slice of `ArgPair` structs.#[derive(Clone, Debug)]pub struct ArgPair {/// The vreg that is defined by this args pseudoinst.@@ -129,7 +129,7 @@ pub struct ArgPair {}/// A type used by backends to track return register binding info in the "ret"-/// pseudoinst. The pseudoinst holds a vec of `RetPair` structs.+/// pseudoinst. The pseudoinst holds a boxed slice of `RetPair` structs.#[derive(Clone, Debug)]pub struct RetPair {/// The vreg that is returned by this pseudionst.@@ -438,11 +438,11 @@ pub trait ABIMachineSpec {/// Generate an "args" pseudo-instruction to capture input args in/// registers.- fn gen_args(args: Vec<ArgPair>) -> Self::I;+ fn gen_args(args: Box<[ArgPair]>) -> Self::I;/// Generate a "rets" pseudo-instruction that moves vregs to return/// registers.- fn gen_rets(rets: Vec<RetPair>) -> Self::I;+ fn gen_rets(rets: Box<[RetPair]>) -> Self::I;/// Generate an add-with-immediate. Note that even if this uses a scratch/// register, it must satisfy two requirements:@@ -1837,7 +1837,7 @@ impl<M: ABIMachineSpec> Callee<M> {}/// Generate a return instruction.- pub fn gen_rets(&self, rets: Vec<RetPair>) -> M::I {+ pub fn gen_rets(&self, rets: Box<[RetPair]>) -> M::I {M::gen_rets(rets)}@@ -2269,7 +2269,9 @@ impl<M: ABIMachineSpec> Callee<M> {// establishes live-ranges for in-register arguments and// constrains them at the start of the function to the// locations defined by the ABI.- Some(M::gen_args(core::mem::take(&mut self.reg_args)))+ Some(M::gen_args(+ core::mem::take(&mut self.reg_args).into_boxed_slice(),+ ))} else {None}diff --git a/cranelift/codegen/src/machinst/isle.rs b/cranelift/codegen/src/machinst/isle.rsindex b0aaa1f879..04ea2b17fc 100644--- a/cranelift/codegen/src/machinst/isle.rs+++ b/cranelift/codegen/src/machinst/isle.rs@@ -19,7 +19,7 @@ pub type ValueArray2 = [Value; 2];pub type ValueArray3 = [Value; 3];pub type BlockArray2 = [BlockCall; 2];pub type WritableReg = Writable<Reg>;-pub type VecRetPair = Vec<RetPair>;+pub type BoxedSliceRetPair = Box<[RetPair]>;pub type VecMask = Vec<u8>;pub type ValueRegs = crate::machinst::ValueRegs<Reg>;pub type WritableValueRegs = crate::machinst::ValueRegs<WritableReg>;diff --git a/cranelift/codegen/src/machinst/lower.rs b/cranelift/codegen/src/machinst/lower.rsindex 5aaee74d3e..e152cdcb6b 100644--- a/cranelift/codegen/src/machinst/lower.rs+++ b/cranelift/codegen/src/machinst/lower.rs@@ -613,7 +613,7 @@ impl<'func, I: VCodeInst> Lower<'func, I> {}}- let inst = self.abi().gen_rets(out_rets);+ let inst = self.abi().gen_rets(out_rets.into_boxed_slice());self.emit(inst);}diff --git a/cranelift/codegen/src/prelude_lower.isle b/cranelift/codegen/src/prelude_lower.isleindex a439dc592e..7222a6a947 100644--- a/cranelift/codegen/src/prelude_lower.isle+++ b/cranelift/codegen/src/prelude_lower.isle@@ -218,8 +218,8 @@(type ExternalName (primitive ExternalName))(type BoxExternalName (primitive BoxExternalName))(type RelocDistance extern (enum (Near) (Far)))-(type VecArgPair extern (enum))-(type VecRetPair extern (enum))+(type BoxedSliceArgPair extern (enum))+(type BoxedSliceRetPair extern (enum))(type CallArgList (primitive CallArgList))(type CallRetList (primitive CallRetList))(type MachLabelSlice extern (enum))