Skip to content

regalloc: simplifies livenessAnalysis/finalizeStartReg #2256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions internal/engine/wazevo/backend/regalloc/regalloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,15 @@ const (
// The algorithm here is described in https://pfalcon.github.io/ssabook/latest/book-full.pdf Chapter 9.2.
func (a *Allocator) livenessAnalysis(f Function) {
s := &a.state
for blk := f.PostOrderBlockIteratorBegin(); blk != nil; blk = f.PostOrderBlockIteratorNext() { // Order doesn't matter.

for blk := f.PostOrderBlockIteratorBegin(); blk != nil; blk = f.PostOrderBlockIteratorNext() {
// We should gather phi value data.
for _, p := range blk.BlockParams(&a.vs) {
vs := s.getVRegState(p.ID())
vs.isPhi = true
vs.defBlk = blk
}
}

for blk := f.PostOrderBlockIteratorBegin(); blk != nil; blk = f.PostOrderBlockIteratorNext() {
blkID := blk.ID()
info := a.getOrAllocateBlockState(blkID)

Expand Down Expand Up @@ -587,15 +585,14 @@ func (a *Allocator) updateLiveInVRState(liveness *blockState) {

func (a *Allocator) finalizeStartReg(blk Block) {
bID := blk.ID()
liveness := a.getOrAllocateBlockState(bID)
s := &a.state
currentBlkState := a.getOrAllocateBlockState(bID)
if currentBlkState.startFromPredIndex > -1 {
return
}

s.currentBlockID = bID
a.updateLiveInVRState(liveness)
a.updateLiveInVRState(currentBlkState)

preds := blk.Preds()
var predState *blockState
Expand Down Expand Up @@ -624,7 +621,7 @@ func (a *Allocator) finalizeStartReg(blk Block) {
s.useRealReg(u.RealReg(), u)
}
currentBlkState.startFromPredIndex = 0
} else if predState != nil {
} else {
if wazevoapi.RegAllocLoggingEnabled {
fmt.Printf("allocating blk%d starting from blk%d (on index=%d) \n",
bID, blk.Pred(currentBlkState.startFromPredIndex).ID(), currentBlkState.startFromPredIndex)
Expand Down
Loading