wazevo(regalloc): removes unnecessary validation pass (#1788)

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Takeshi Yoneda
2023-10-16 16:26:50 +09:00
committed by GitHub
parent 9dff143c57
commit 14bea4ffdb
2 changed files with 10 additions and 16 deletions

View File

@@ -30,18 +30,6 @@ func (a *Allocator) assignRegistersPerBlock(f Function, blk Block, vRegIDToNode
}
func (a *Allocator) assignRegistersPerInstr(f Function, pc programCounter, instr Instr, vRegIDToNode []*node, liveNodes []liveNodeInBlock) {
if wazevoapi.RegAllocValidationEnabled {
// Check if the liveNodes are sorted by the start program counter.
for i := 1; i < len(liveNodes); i++ {
n, m := liveNodes[i-1], liveNodes[i]
if n.n.ranges[n.rangeIndex].begin > m.n.ranges[m.rangeIndex].begin {
panic(fmt.Sprintf("BUG: liveNodes are not sorted by the start program counter: %d > %d",
n.n.ranges[n.rangeIndex].begin, m.n.ranges[m.rangeIndex].begin,
))
}
}
}
if indirect := instr.IsIndirectCall(); instr.IsCall() || indirect {
// Only take care of non-real VRegs (e.g. VReg.IsRealReg() == false) since
// the real VRegs are already placed in the right registers at this point.

View File

@@ -24,14 +24,20 @@ func (a *Allocator) buildNeighborsByLiveNodes(lives []liveNodeInBlock) {
for i, src := range lives[:len(lives)-1] {
srcRange := &src.n.ranges[src.rangeIndex]
for _, dst := range lives[i+1:] {
if dst == src || dst.n == src.n {
srcN, dstN := src.n, dst.n
if dst == src || dstN == srcN {
panic(fmt.Sprintf("BUG: %s and %s are the same node", src.n.v, dst.n.v))
}
dstRange := &dst.n.ranges[dst.rangeIndex]
if src.n.v.RegType() == dst.n.v.RegType() && // Interfere only if they are the same type.
if dstRange.begin > srcRange.end {
// liveNodes are sorted by the start program counter, so we can break here.
break
}
if srcN.v.RegType() == dstN.v.RegType() && // Interfere only if they are the same type.
srcRange.intersects(dstRange) {
src.n.neighbors = append(src.n.neighbors, dst.n)
dst.n.neighbors = append(dst.n.neighbors, src.n)
srcN.neighbors = append(srcN.neighbors, dst.n)
dstN.neighbors = append(dstN.neighbors, src.n)
}
}
}