| 1 |
functor RASpillTypes(I : INSTRUCTIONS) = |
| 2 |
struct |
| 3 |
|
| 4 |
structure G = RAGraph |
| 5 |
structure C = I.C |
| 6 |
structure CB = CellsBasis |
| 7 |
|
| 8 |
type copyInstr = |
| 9 |
(CB.cell list * CB.cell list) * I.instruction -> I.instruction list |
| 10 |
|
| 11 |
(* |
| 12 |
* Spill the value associated with reg into spillLoc. |
| 13 |
* All definitions of instr should be renamed to a new temporary newReg. |
| 14 |
*) |
| 15 |
type spill = |
| 16 |
{instr : I.instruction, (* instruction where spill is to occur *) |
| 17 |
reg : CB.cell, (* register to spill *) |
| 18 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 19 |
kill : bool, (* can we kill the current node? *) |
| 20 |
annotations : Annotations.annotations ref (* annotations *) |
| 21 |
} -> |
| 22 |
{code : I.instruction list, (* instruction + spill code *) |
| 23 |
proh : CB.cell list, (* prohibited from future spilling *) |
| 24 |
newReg : CB.cell option (* the spilled value is available here *) |
| 25 |
} |
| 26 |
|
| 27 |
(* Spill the register src into spillLoc. |
| 28 |
* The value is originally from register reg. |
| 29 |
*) |
| 30 |
type spillSrc = |
| 31 |
{src : CB.cell, (* register to spill from *) |
| 32 |
reg : CB.cell, (* the register *) |
| 33 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 34 |
annotations : Annotations.annotations ref (* annotations *) |
| 35 |
} -> I.instruction list (* spill code *) |
| 36 |
|
| 37 |
(* |
| 38 |
* Spill the temporary associated with a copy into spillLoc |
| 39 |
*) |
| 40 |
type spillCopyTmp = |
| 41 |
{copy : I.instruction, (* copy to spill *) |
| 42 |
reg : CB.cell, (* the register *) |
| 43 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 44 |
annotations : Annotations.annotations ref (* annotations *) |
| 45 |
} -> I.instruction (* spill code *) |
| 46 |
|
| 47 |
(* |
| 48 |
* Reload the value associated with reg from spillLoc. |
| 49 |
* All uses of instr should be renamed to a new temporary newReg. |
| 50 |
*) |
| 51 |
type reload = |
| 52 |
{instr : I.instruction, (* instruction where spill is to occur *) |
| 53 |
reg : CB.cell, (* register to spill *) |
| 54 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 55 |
annotations : Annotations.annotations ref (* annotations *) |
| 56 |
} -> |
| 57 |
{code : I.instruction list, (* instr + reload code *) |
| 58 |
proh : CB.cell list, (* prohibited from future spilling *) |
| 59 |
newReg : CB.cell option (* the reloaded value is here *) |
| 60 |
} |
| 61 |
|
| 62 |
(* |
| 63 |
* Rename all uses fromSrc to toSrc |
| 64 |
*) |
| 65 |
type renameSrc = |
| 66 |
{instr : I.instruction, (* instruction where spill is to occur *) |
| 67 |
fromSrc : CB.cell, (* register to rename *) |
| 68 |
toSrc : CB.cell (* register to rename to *) |
| 69 |
} -> |
| 70 |
{code : I.instruction list, (* renamed instr *) |
| 71 |
proh : CB.cell list, (* prohibited from future spilling *) |
| 72 |
newReg : CB.cell option (* the renamed value is here *) |
| 73 |
} |
| 74 |
|
| 75 |
(* Reload the register dst from spillLoc. |
| 76 |
* The value is originally from register reg. |
| 77 |
*) |
| 78 |
type reloadDst = |
| 79 |
{dst : CB.cell, (* register to reload to *) |
| 80 |
reg : CB.cell, (* the register *) |
| 81 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 82 |
annotations : Annotations.annotations ref (* annotations *) |
| 83 |
} -> I.instruction list (* reload code *) |
| 84 |
|
| 85 |
end |