Created
October 21, 2019 13:09
-
-
Save tyfkda/82eed77d97b80c6a69415a88e3549948 to your computer and use it in GitHub Desktop.
Linear scan register allocation algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LinearScanRegisterAllocation | |
active <- {} | |
foreach live interval i, in order of increasing start point | |
ExpireOldIntervals(i) | |
if length(active) == R then | |
SpillAtInterval(i) | |
else | |
register[i] <- a register removed from pool of free registers | |
add i to active, sorted by increasing end point | |
ExpireOldIntervals(i) | |
foreach interval j in active, in order of increasing end point | |
if endpoint[j] >= startpoint[i] then # > が正しい気がする。 | |
return | |
remove j from active | |
add register[j] to pool of free registers | |
SpillAtInterval(i) | |
spill <- last interval in active | |
if endpoint[spill] > endpoint[i] then | |
register[i] <- register[spill] | |
location[spill] <- new stack location | |
remove spill from active | |
add i to active, sorted by increasing end point | |
else | |
location[i] <- new stack location |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment