Skip to content

Commit

Permalink
cranelift: Stop consuming allocations (#8581)
Browse files Browse the repository at this point in the history
The `next` and `next_writable` methods on `AllocationConsumer` are
identity functions now, so replace each call with its argument and then
clean up the resulting mess.

Most of this commit was generated with these commands:

- `git grep -lF allocs.next cranelift/codegen/src/isa/ |
   xargs sed -i 's/allocs\.next\(_writable\)\?//'`
- `cargo fix -p cranelift-codegen --features all-arch --allow-dirty --allow-staged`
- `git diff --name-only HEAD | xargs sed -i '/let \([^ ]*\) = \1;/d'`
- `cargo fmt`

I used sed to delete `allocs.next` but left the following parentheses
alone (since matching balanced parentheses is not a regular language).
Then I used `cargo fix` to remove those parentheses and also add
underscores to newly-unused `AllocationConsumer` arguments. Next I used
sed again to delete trivial assignments like `let x = x`, leaving more
complicated cases as future work to clean up, and finally `cargo fmt` to
delete blank lines and braces that are no longer necessary.

Last, I deleted the newly-unused definitions of `next` and
`next_writable` themselves.
  • Loading branch information
jameysharp authored May 8, 2024
1 parent 7f699b8 commit 3308a2b
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 726 deletions.
312 changes: 48 additions & 264 deletions cranelift/codegen/src/isa/aarch64/inst/emit.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion cranelift/codegen/src/isa/aarch64/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,6 @@ impl Inst {
// this logic between `emit()` and `show_rru()` -- a separate 1-to-N
// expansion stage (i.e., legalization, but without the slow edit-in-place
// of the existing legalization framework).
let rd = allocs.next_writable(rd);
let mem = mem.clone();
let (mem_insts, mem) = mem_finalize(None, &mem, I8, state);
let mut ret = String::new();
Expand Down
15 changes: 5 additions & 10 deletions cranelift/codegen/src/isa/aarch64/inst/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ fn show_reg(reg: Reg) -> String {
}
}

pub fn pretty_print_reg(reg: Reg, allocs: &mut AllocationConsumer) -> String {
let reg = allocs.next(reg);
pub fn pretty_print_reg(reg: Reg, _allocs: &mut AllocationConsumer) -> String {
show_reg(reg)
}

Expand Down Expand Up @@ -254,35 +253,31 @@ pub fn show_vreg_element(reg: Reg, idx: u8, size: ScalarSize) -> String {
format!("{}{}[{}]", s, suffix, idx)
}

pub fn pretty_print_ireg(reg: Reg, size: OperandSize, allocs: &mut AllocationConsumer) -> String {
let reg = allocs.next(reg);
pub fn pretty_print_ireg(reg: Reg, size: OperandSize, _allocs: &mut AllocationConsumer) -> String {
show_ireg_sized(reg, size)
}

pub fn pretty_print_vreg_scalar(
reg: Reg,
size: ScalarSize,
allocs: &mut AllocationConsumer,
_allocs: &mut AllocationConsumer,
) -> String {
let reg = allocs.next(reg);
show_vreg_scalar(reg, size)
}

pub fn pretty_print_vreg_vector(
reg: Reg,
size: VectorSize,
allocs: &mut AllocationConsumer,
_allocs: &mut AllocationConsumer,
) -> String {
let reg = allocs.next(reg);
show_vreg_vector(reg, size)
}

pub fn pretty_print_vreg_element(
reg: Reg,
idx: usize,
size: ScalarSize,
allocs: &mut AllocationConsumer,
_allocs: &mut AllocationConsumer,
) -> String {
let reg = allocs.next(reg);
show_vreg_element(reg, idx as u8, size)
}
5 changes: 1 addition & 4 deletions cranelift/codegen/src/isa/riscv64/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,10 +894,7 @@ pub fn reg_name(reg: Reg) -> String {

impl Inst {
fn print_with_state(&self, _state: &mut EmitState, allocs: &mut AllocationConsumer) -> String {
let format_reg = |reg: Reg, allocs: &mut AllocationConsumer| -> String {
let reg = allocs.next(reg);
reg_name(reg)
};
let format_reg = |reg: Reg, _allocs: &mut AllocationConsumer| -> String { reg_name(reg) };

let format_vec_amode = |amode: &VecAMode, _allocs: &mut AllocationConsumer| -> String {
match amode {
Expand Down
6 changes: 1 addition & 5 deletions cranelift/codegen/src/isa/s390x/inst/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,11 @@ impl Cond {
}

impl PrettyPrint for MemArg {
fn pretty_print(&self, _: u8, allocs: &mut AllocationConsumer) -> String {
fn pretty_print(&self, _: u8, _allocs: &mut AllocationConsumer) -> String {
match self {
&MemArg::BXD12 {
base, index, disp, ..
} => {
let base = allocs.next(base);
let index = allocs.next(index);
if base != zero_reg() {
if index != zero_reg() {
format!(
Expand All @@ -245,8 +243,6 @@ impl PrettyPrint for MemArg {
&MemArg::BXD20 {
base, index, disp, ..
} => {
let base = allocs.next(base);
let index = allocs.next(index);
if base != zero_reg() {
if index != zero_reg() {
format!(
Expand Down
Loading

0 comments on commit 3308a2b

Please sign in to comment.