Skip to content

Commit

Permalink
pulley: Add macro instructions for function prologue/epilogue
Browse files Browse the repository at this point in the history
This commit adds two new instructions to Pulley to combine the
operations of setting up a frame, allocating stack, and saving clobbered
registers. This is all combined into a single instruction which is
relatively large but is much smaller than each of these individual
operations exploded out.

This is a size win on `spidermonkey.cwasm` by about 1M and locally in a
small `fib.wat` test this is also a good speedup by reducing the number
of instructions executed.
  • Loading branch information
alexcrichton committed Dec 19, 2024
1 parent 320f9f3 commit c75876c
Show file tree
Hide file tree
Showing 9 changed files with 358 additions and 151 deletions.
3 changes: 3 additions & 0 deletions cranelift/bitset/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,17 @@ pub trait ScalarBitSetStorage:
macro_rules! impl_storage {
( $int:ty ) => {
impl ScalarBitSetStorage for $int {
#[inline]
fn leading_zeros(self) -> u8 {
u8::try_from(self.leading_zeros()).unwrap()
}

#[inline]
fn trailing_zeros(self) -> u8 {
u8::try_from(self.trailing_zeros()).unwrap()
}

#[inline]
fn count_ones(self) -> u8 {
u8::try_from(self.count_ones()).unwrap()
}
Expand Down
19 changes: 18 additions & 1 deletion cranelift/codegen/meta/src/pulley.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ impl Inst<'_> {
Operand::Binop { dst, src1, src2 }
}
("dst", ty) => Operand::Writable { name, ty },
(name, "RegSet < XReg >") => Operand::Normal {
name,
ty: "XRegSet",
},
(name, ty) => Operand::Normal { name, ty },
})
.chain(if self.name.contains("Trap") {
Expand Down Expand Up @@ -120,10 +124,17 @@ pub fn generate_rust(filename: &str, out_dir: &Path) -> Result<(), Error> {
if i > 0 {
format_string.push_str(",");
}

if ty == "XRegSet" {
format_string.push_str(" {");
format_string.push_str(name);
format_string.push_str(":?}");
continue;
}

format_string.push_str(" {");
format_string.push_str(name);
format_string.push_str("}");

if ty.contains("Reg") {
if name == "dst" {
locals.push_str(&format!("let {name} = reg_name(*{name}.to_reg());\n"));
Expand Down Expand Up @@ -176,6 +187,12 @@ pub fn generate_rust(filename: &str, out_dir: &Path) -> Result<(), Error> {
let mut defs = Vec::new();
for op in inst.operands() {
match op {
// `{Push,Pop}FrameSave` doesn't participate in register allocation.
Operand::Normal {
name: _,
ty: "XRegSet",
} if *name == "PushFrameSave" || *name == "PopFrameSave" => {}

Operand::Normal { name, ty } => {
if ty.contains("Reg") {
uses.push(name);
Expand Down
Loading

0 comments on commit c75876c

Please sign in to comment.