Skip to content

Commit 9995367

Browse files
authored
regalloc: removes unnecessary Instruction.Uses (#2237)
This also early stops resetting IDedPool. ### Zig stdlib ``` goos: darwin goarch: arm64 pkg: github.com/tetratelabs/wazero │ old_zig.txt │ new_zig.txt │ │ sec/op │ sec/op vs base │ Compilation-10 4.540 ± 0% 4.380 ± 1% -3.51% (p=0.001 n=7) │ old_zig.txt │ new_zig.txt │ │ B/op │ B/op vs base │ Compilation-10 599.3Mi ± 0% 599.3Mi ± 0% ~ (p=0.383 n=7) │ old_zig.txt │ new_zig.txt │ │ allocs/op │ allocs/op vs base │ Compilation-10 288.0k ± 0% 288.0k ± 0% ~ (p=0.805 n=7) ``` ### wazero compiled as a wasip1 binary ``` goos: darwin goarch: arm64 pkg: github.com/tetratelabs/wazero │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ Compilation-10 2.264 ± 1% 2.224 ± 0% -1.80% (p=0.001 n=7) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ Compilation-10 337.3Mi ± 0% 337.3Mi ± 0% ~ (p=0.318 n=7) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ Compilation-10 593.7k ± 0% 593.6k ± 0% ~ (p=0.456 n=7) ``` Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
1 parent 0649820 commit 9995367

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

internal/engine/wazevo/backend/regalloc/regalloc.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ func (a *Allocator) allocBlock(f Function, blk Block) {
754754
killSet := a.reals[:0]
755755

756756
// Gather the set of registers that will be used in the current instruction.
757-
for _, use := range instr.Uses(&a.vs) {
757+
uses := instr.Uses(&a.vs)
758+
for _, use := range uses {
758759
if use.IsRealReg() {
759760
r := use.RealReg()
760761
currentUsedSet = currentUsedSet.add(r)
@@ -769,7 +770,7 @@ func (a *Allocator) allocBlock(f Function, blk Block) {
769770
}
770771
}
771772

772-
for i, use := range instr.Uses(&a.vs) {
773+
for i, use := range uses {
773774
if !use.IsRealReg() {
774775
vs := s.getVRegState(use.ID())
775776
killed := vs.lastUse == pc

internal/engine/wazevo/wazevoapi/pool.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type IDedPool[T any] struct {
6969

7070
// NewIDedPool returns a new IDedPool.
7171
func NewIDedPool[T any](resetFn func(*T)) IDedPool[T] {
72-
return IDedPool[T]{pool: NewPool[T](resetFn)}
72+
return IDedPool[T]{pool: NewPool[T](resetFn), maxIDEncountered: -1}
7373
}
7474

7575
// GetOrAllocate returns the T with the given id.
@@ -97,7 +97,7 @@ func (p *IDedPool[T]) Get(id int) *T {
9797
// Reset resets the pool.
9898
func (p *IDedPool[T]) Reset() {
9999
p.pool.Reset()
100-
for i := range p.idToItems {
100+
for i := 0; i <= p.maxIDEncountered; i++ {
101101
p.idToItems[i] = nil
102102
}
103103
p.maxIDEncountered = -1

0 commit comments

Comments
 (0)