import Outputable
import Data.List
-import Data.Maybe
-- | Spill all these virtual regs to memory
:: Instruction instr
=> [LiveCmmTop instr] -- ^ the code
-> UniqSet Int -- ^ available stack slots
- -> UniqSet Reg -- ^ the regs to spill
+ -> UniqSet VirtualReg -- ^ the regs to spill
-> UniqSM
([LiveCmmTop instr] -- code will spill instructions
, UniqSet Int -- left over slots
=> UniqFM Int
-> LiveInstr instr -> SpillM [LiveInstr instr]
--- | The thing we're spilling shouldn't already have spill or reloads in it
-regSpill_instr _ SPILL{}
- = panic "regSpill_instr: unexpected SPILL"
-
-regSpill_instr _ RELOAD{}
- = panic "regSpill_instr: unexpected RELOAD"
-
-
-regSpill_instr _ li@(Instr _ Nothing)
+regSpill_instr _ li@(LiveInstr _ Nothing)
= do return [li]
regSpill_instr regSlotMap
- (Instr instr (Just _))
+ (LiveInstr instr (Just _))
= do
-- work out which regs are read and written in this instr
let RU rlRead rlWritten = regUsageOfInstr instr
-- final code
let instrs' = prefixes
- ++ [Instr instr3 Nothing]
+ ++ [LiveInstr instr3 Nothing]
++ postfixes
return
{ stateSpillSL = addToUFM_C accSpillSL (stateSpillSL s) reg (reg, 0, 1) }
return ( instr'
- , ( [RELOAD slot nReg]
+ , ( [LiveInstr (RELOAD slot nReg) Nothing]
, []) )
| otherwise = panic "RegSpill.spillRead: no slot defined for spilled reg"
return ( instr'
, ( []
- , [SPILL nReg slot]))
+ , [LiveInstr (SPILL nReg slot) Nothing]))
| otherwise = panic "RegSpill.spillWrite: no slot defined for spilled reg"
{ stateSpillSL = addToUFM_C accSpillSL (stateSpillSL s) reg (reg, 1, 1) }
return ( instr'
- , ( [RELOAD slot nReg]
- , [SPILL nReg slot]))
+ , ( [LiveInstr (RELOAD slot nReg) Nothing]
+ , [LiveInstr (SPILL nReg slot) Nothing]))
| otherwise = panic "RegSpill.spillModify: no slot defined for spilled reg"
patchInstr reg instr
= do nUnique <- newUnique
- let nReg = renameVirtualReg nUnique reg
+ let nReg = case reg of
+ RegVirtual vr -> RegVirtual (renameVirtualReg nUnique vr)
+ RegReal{} -> panic "RegAlloc.Graph.Spill.patchIntr: not patching real reg"
let instr' = patchReg1 reg nReg instr
return (instr', nReg)