diff --git a/cranelift/codegen/src/isa/aarch64/abi.rs b/cranelift/codegen/src/isa/aarch64/abi.rs index e57866c307..524740d45b 100644 --- a/cranelift/codegen/src/isa/aarch64/abi.rs +++ b/cranelift/codegen/src/isa/aarch64/abi.rs @@ -212,7 +212,7 @@ impl ABIMachineSpec for AArch64MachineDeps { let upper_reg = xreg(next_xreg + 1); ret.push(ABIArg::Slots { - slots: vec![ + slots: smallvec![ ABIArgSlot::Reg { reg: lower_reg.to_real_reg().unwrap(), ty: param.value_type, diff --git a/cranelift/codegen/src/isa/x64/abi.rs b/cranelift/codegen/src/isa/x64/abi.rs index 9202e2c82f..abe6a576bb 100644 --- a/cranelift/codegen/src/isa/x64/abi.rs +++ b/cranelift/codegen/src/isa/x64/abi.rs @@ -125,7 +125,7 @@ impl ABIMachineSpec for X64ABIMachineSpec { ); } - let mut slots = vec![]; + let mut slots = ABIArgSlotVec::new(); for (rc, reg_ty) in rcs.iter().zip(reg_tys.iter()) { let intreg = *rc == RegClass::Int; let nextreg = if intreg { diff --git a/cranelift/codegen/src/machinst/abi_impl.rs b/cranelift/codegen/src/machinst/abi_impl.rs index dd2e860386..cd304ca478 100644 --- a/cranelift/codegen/src/machinst/abi_impl.rs +++ b/cranelift/codegen/src/machinst/abi_impl.rs @@ -153,6 +153,11 @@ impl ABIArgSlot { } } +/// A vector of `ABIArgSlot`s. Inline capacity for one element because basically +/// 100% of values use one slot. Only `i128`s need multiple slots, and they are +/// super rare (and never happen with Wasm). +pub type ABIArgSlotVec = SmallVec<[ABIArgSlot; 1]>; + /// An ABIArg is composed of one or more parts. This allows for a CLIF-level /// Value to be passed with its parts in more than one location at the ABI /// level. For example, a 128-bit integer may be passed in two 64-bit registers, @@ -169,7 +174,7 @@ pub enum ABIArg { /// parts used to store a value of this type. Slots { /// Slots, one per register part. - slots: Vec, + slots: ABIArgSlotVec, /// Purpose of this arg. purpose: ir::ArgumentPurpose, }, @@ -206,7 +211,7 @@ impl ABIArg { purpose: ir::ArgumentPurpose, ) -> ABIArg { ABIArg::Slots { - slots: vec![ABIArgSlot::Reg { reg, ty, extension }], + slots: smallvec![ABIArgSlot::Reg { reg, ty, extension }], purpose, } } @@ -219,7 +224,7 @@ impl ABIArg { purpose: ir::ArgumentPurpose, ) -> ABIArg { ABIArg::Slots { - slots: vec![ABIArgSlot::Stack { + slots: smallvec![ABIArgSlot::Stack { offset, ty, extension,