Improved variable lifetime tracking

This commit is contained in:
2024-06-30 00:17:14 +02:00
parent 6e1af81733
commit 3fe2cd1da2
17 changed files with 114 additions and 31 deletions

View File

@ -2,6 +2,7 @@ package build
import (
"git.akyoto.dev/cli/q/src/build/asm"
"git.akyoto.dev/cli/q/src/build/config"
"git.akyoto.dev/cli/q/src/build/cpu"
)
@ -20,7 +21,7 @@ func (f *Function) SaveRegister(register cpu.Register) {
}
}
if variable == nil || variable.UsesRemaining == 0 {
if variable == nil || variable.Alive == 0 {
return
}
@ -30,6 +31,10 @@ func (f *Function) SaveRegister(register cpu.Register) {
panic("no free registers")
}
if config.Verbose {
f.Logf("moving %s from %s to %s (alive: %d)", variable.Name, variable.Register, newRegister, variable.Alive)
}
f.assembler.RegisterRegister(asm.MOVE, newRegister, register)
f.cpu.Free(register)
f.cpu.Use(newRegister)