From 8cacbc3a7e1d696a06efd0c3be2468572a5a6235 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 7 Jun 2024 13:43:07 -0700 Subject: [PATCH] regalloc: removes unnecessary Instruction.Uses This also early stops resetting IDedPool Signed-off-by: Takeshi Yoneda --- internal/engine/wazevo/backend/regalloc/regalloc.go | 5 +++-- internal/engine/wazevo/wazevoapi/pool.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/engine/wazevo/backend/regalloc/regalloc.go b/internal/engine/wazevo/backend/regalloc/regalloc.go index 731426fc71..eacb6a7ef9 100644 --- a/internal/engine/wazevo/backend/regalloc/regalloc.go +++ b/internal/engine/wazevo/backend/regalloc/regalloc.go @@ -754,7 +754,8 @@ func (a *Allocator) allocBlock(f Function, blk Block) { killSet := a.reals[:0] // Gather the set of registers that will be used in the current instruction. - for _, use := range instr.Uses(&a.vs) { + uses := instr.Uses(&a.vs) + for _, use := range uses { if use.IsRealReg() { r := use.RealReg() currentUsedSet = currentUsedSet.add(r) @@ -769,7 +770,7 @@ func (a *Allocator) allocBlock(f Function, blk Block) { } } - for i, use := range instr.Uses(&a.vs) { + for i, use := range uses { if !use.IsRealReg() { vs := s.getVRegState(use.ID()) killed := vs.lastUse == pc diff --git a/internal/engine/wazevo/wazevoapi/pool.go b/internal/engine/wazevo/wazevoapi/pool.go index 3149fdc9e1..313e34f9ae 100644 --- a/internal/engine/wazevo/wazevoapi/pool.go +++ b/internal/engine/wazevo/wazevoapi/pool.go @@ -69,7 +69,7 @@ type IDedPool[T any] struct { // NewIDedPool returns a new IDedPool. func NewIDedPool[T any](resetFn func(*T)) IDedPool[T] { - return IDedPool[T]{pool: NewPool[T](resetFn)} + return IDedPool[T]{pool: NewPool[T](resetFn), maxIDEncountered: -1} } // GetOrAllocate returns the T with the given id. @@ -97,7 +97,7 @@ func (p *IDedPool[T]) Get(id int) *T { // Reset resets the pool. func (p *IDedPool[T]) Reset() { p.pool.Reset() - for i := range p.idToItems { + for i := 0; i <= p.maxIDEncountered; i++ { p.idToItems[i] = nil } p.maxIDEncountered = -1