Skip to content

Commit 56e2a43

Browse files
authored
regalloc: removes map from RegAllocFunction (#2240)
This improves the compilation slightly as below: ### wazero compiled as a wasip1 ``` goos: darwin goarch: arm64 pkg: github.com/tetratelabs/wazero │ old_zig.txt │ new_zig.txt │ │ sec/op │ sec/op vs base │ Compilation-10 2.227 ± 0% 2.184 ± 1% -1.96% (p=0.001 n=7) │ old_zig.txt │ new_zig.txt │ │ B/op │ B/op vs base │ Compilation-10 337.2Mi ± 0% 337.3Mi ± 0% +0.02% (p=0.001 n=7) │ old_zig.txt │ new_zig.txt │ │ allocs/op │ allocs/op vs base │ Compilation-10 593.5k ± 0% 592.9k ± 0% -0.10% (p=0.001 n=7) ``` ### Zig stdlib ``` goos: darwin goarch: arm64 pkg: github.com/tetratelabs/wazero │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ Compilation-10 4.371 ± 1% 4.329 ± 0% -0.96% (p=0.001 n=7) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ Compilation-10 599.3Mi ± 0% 599.3Mi ± 0% -0.00% (p=0.002 n=7) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ Compilation-10 287.9k ± 0% 287.9k ± 0% ~ (p=0.053 n=7) ``` Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent 981e71d commit 56e2a43

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

internal/engine/wazevo/backend/regalloc.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type (
3535
iter int
3636
reversePostOrderBlocks []RegAllocBlock[I, m]
3737
// labelToRegAllocBlockIndex maps label to the index of reversePostOrderBlocks.
38-
labelToRegAllocBlockIndex map[Label]int
38+
labelToRegAllocBlockIndex [] /* Label to */ int
3939
loopNestingForestRoots []ssa.BasicBlock
4040
}
4141

@@ -56,10 +56,9 @@ type (
5656
// NewRegAllocFunction returns a new RegAllocFunction.
5757
func NewRegAllocFunction[I regalloc.InstrConstraint, M RegAllocFunctionMachine[I]](m M, ssb ssa.Builder, c Compiler) *RegAllocFunction[I, M] {
5858
return &RegAllocFunction[I, M]{
59-
m: m,
60-
ssb: ssb,
61-
c: c,
62-
labelToRegAllocBlockIndex: make(map[Label]int),
59+
m: m,
60+
ssb: ssb,
61+
c: c,
6362
}
6463
}
6564

@@ -74,6 +73,9 @@ func (f *RegAllocFunction[I, M]) AddBlock(sb ssa.BasicBlock, l Label, begin, end
7473
end: end,
7574
id: int(sb.ID()),
7675
})
76+
if len(f.labelToRegAllocBlockIndex) <= int(l) {
77+
f.labelToRegAllocBlockIndex = append(f.labelToRegAllocBlockIndex, make([]int, int(l)-len(f.labelToRegAllocBlockIndex)+1)...)
78+
}
7779
f.labelToRegAllocBlockIndex[l] = i
7880
}
7981

0 commit comments

Comments
 (0)