initial CSR cost
calculate LiveInterval weight and hints
allocate physical registers
select or split
PhysReg = tryAssign
tryAssign
for all physical registers, Matrix->checkInterference until find a physical register no interfere
if no physical register or the physical register is hint register
return the physical register
if there is hint register for the virtual register
if the hint register can be evicted
evicInterference
for all RegUnit of the physical register
collect interfering LiveInterval
for all interfering LiveInterval
Matrix->unassign(LiveInterval)
NewVRegs.push_back(LiveInterval->reg)
return the hint register
Cost = getCostPerUse(PhysReg)
if Cost == 0
return PhysReg
CheapReg = tryEvict(Cost)
return CheapReg ? CheapReg : PhysReg
if PhysReg is unused callee saved register
CSRReg = tryAssignCSRFirstTime
if Stage == RS_Spill and VirtReg.isSpillable
SA->analyze
if calcSpillCost >= CSRCost
return PhysReg
CostPerUseLimit = 1
return 0
if Stage == RS_Split
SA->analyze
BestCand = calculateRegionSplitCost
if BestCand == NoCand
return PhysReg
doRegionSplit
return 0
return PhysReg
if CSRReg
return CSRReg
return PhysReg
Stage = getStage
Stage != RS_Split
PhysReg = tryEvict
for all physical registers under OrderLimit
if getCostPerUse(PhysReg) >= CostPerUseLimit
continue
if CostPerUseLimit == 1 and PhysReg is unused callee saved register
continue
if the PhysReg can not be evicted
continue
BestPhys = PhysReg
if PhysReg is hint register
break
if BestPhys == 0
return 0
evictInterference
return BestPhys
if PhysReg
if Hint
SetOfBrokenHints.insert
return PhysReg
Stage < RS_Split
setStage(RS_Split)
NewVRegs.push_back(VirtReg)
return 0
Stage >= RS_Done
tryLastChanceRecoloring
FixedRegisters.insert(VirtReg.reg)
for all PhysRegs in order
if Matrix->checkInterference > IK_VirtReg
continue
if it may not recolor all interferences (collect recoloring candidates)
mayRecolorAllInterferences
continue
for all recoloring candidates
enqueue to RecoloringQueue
keep old PhysReg for the virtual registers (backup for restore if failed)
Matrix->unassign
Matrix->assign(VirtReg, PhysReg)
if tryRecoloringCandidates
tryRecoloringCandidates
for all LiveInterval in RecoloringQueue
PhysReg = selectOrSplitImpl(Depth + 1)
if PhysReg == ~0u or PhysReg == 0
return false
Matrix->assign(LiveInterval, PhysReg)
FixedRegisters.insert
return true
Matrix->unassign(VirtReg)
return PhysReg
restore original PhysReg
return ~0u
return
PhysReg = trySplit
trySplit
if Stage >= RS_Spill
return 0
if LiveInterval is in one MBB
SA->analyze
PhysReg = tryLocalSplit
if PhysReg
return PhysReg
return tryInstructionSplit
SA->analyze
if SA->didRepairRange
Matrix->invalidateVirtRegs
PhysReg = tryAssign
if PhysReg
return PhysReg
if Stage < RS_Split2
PhysReg = tryRegionSplit
if PhysReg
return PhysReg
return tryBlockSplit
if PhysReg
return PhysReg
spill
setStage(RS_Done)
return 0
try hint recoloring