| 1 |
(* |
| 2 |
* This module manages the spill/reload process. |
| 3 |
* |
| 4 |
* -- Allen |
| 5 |
*) |
| 6 |
signature RA_SPILL = |
| 7 |
sig |
| 8 |
|
| 9 |
structure I : INSTRUCTIONS |
| 10 |
structure G : RA_GRAPH (* = RAGraph *) |
| 11 |
where type C.CellSet.cellset = RAGraph.C.CellSet.cellset |
| 12 |
and type 'a C.ColorTable.hash_table = 'a RAGraph.C.ColorTable.hash_table |
| 13 |
and type 'a C.HashTable.hash_table = 'a RAGraph.C.HashTable.hash_table |
| 14 |
and type C.SortedCells.sorted_cells = RAGraph.C.SortedCells.sorted_cells |
| 15 |
and type C.cell = RAGraph.C.cell |
| 16 |
and type C.cellColor = RAGraph.C.cellColor |
| 17 |
and type C.cellkind = RAGraph.C.cellkind |
| 18 |
and type C.cellkindDesc = RAGraph.C.cellkindDesc |
| 19 |
and type C.cellkindInfo = RAGraph.C.cellkindInfo |
| 20 |
and type 'a PPtHashTable.hash_table = 'a RAGraph.PPtHashTable.hash_table |
| 21 |
and type 'a SpillLocHashTable.hash_table = 'a RAGraph.SpillLocHashTable.hash_table |
| 22 |
and type interferenceGraph = RAGraph.interferenceGraph |
| 23 |
and type move = RAGraph.move |
| 24 |
and type moveKind = RAGraph.moveKind |
| 25 |
and type moveStatus = RAGraph.moveStatus |
| 26 |
and type node = RAGraph.node |
| 27 |
and type nodeStatus = RAGraph.nodeStatus |
| 28 |
and type spillLoc = RAGraph.spillLoc |
| 29 |
and type trailInfo = RAGraph.trailInfo |
| 30 |
structure C : CELLS |
| 31 |
(* sharing I.C = C *) |
| 32 |
|
| 33 |
structure CB : CELLS_BASIS (* = CellsBasis *) |
| 34 |
where type CellSet.cellset = CellsBasis.CellSet.cellset |
| 35 |
and type 'a ColorTable.hash_table = 'a CellsBasis.ColorTable.hash_table |
| 36 |
and type 'a HashTable.hash_table = 'a CellsBasis.HashTable.hash_table |
| 37 |
and type SortedCells.sorted_cells = CellsBasis.SortedCells.sorted_cells |
| 38 |
and type cell = CellsBasis.cell |
| 39 |
and type cellColor = CellsBasis.cellColor |
| 40 |
and type cellkind = CellsBasis.cellkind |
| 41 |
and type cellkindDesc = CellsBasis.cellkindDesc |
| 42 |
and type cellkindInfo = CellsBasis.cellkindInfo |
| 43 |
type copyInstr = |
| 44 |
(CB.cell list * CB.cell list) * I.instruction -> I.instruction list |
| 45 |
|
| 46 |
(* |
| 47 |
* Spill the value associated with reg into spillLoc. |
| 48 |
* All definitions of instr should be renamed to a new temporary newReg. |
| 49 |
*) |
| 50 |
type spill = |
| 51 |
{instr : I.instruction, (* instruction where spill is to occur *) |
| 52 |
reg : CB.cell, (* register to spill *) |
| 53 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 54 |
kill : bool, (* can we kill the current node? *) |
| 55 |
annotations : Annotations.annotations ref (* annotations *) |
| 56 |
} -> |
| 57 |
{code : I.instruction list, (* instruction + spill code *) |
| 58 |
proh : CB.cell list, (* prohibited from future spilling *) |
| 59 |
newReg : CB.cell option (* the spilled value is available here *) |
| 60 |
} |
| 61 |
|
| 62 |
(* Spill the register src into spillLoc. |
| 63 |
* The value is originally from register reg. |
| 64 |
*) |
| 65 |
type spillSrc = |
| 66 |
{src : CB.cell, (* register to spill from *) |
| 67 |
reg : CB.cell, (* the register *) |
| 68 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 69 |
annotations : Annotations.annotations ref (* annotations *) |
| 70 |
} -> I.instruction list (* spill code *) |
| 71 |
|
| 72 |
(* |
| 73 |
* Spill the temporary associated with a copy into spillLoc |
| 74 |
*) |
| 75 |
type spillCopyTmp = |
| 76 |
{copy : I.instruction, (* copy to spill *) |
| 77 |
reg : CB.cell, (* the register *) |
| 78 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 79 |
annotations : Annotations.annotations ref (* annotations *) |
| 80 |
} -> I.instruction (* spill code *) |
| 81 |
|
| 82 |
(* |
| 83 |
* Reload the value associated with reg from spillLoc. |
| 84 |
* All uses of instr should be renamed to a new temporary newReg. |
| 85 |
*) |
| 86 |
type reload = |
| 87 |
{instr : I.instruction, (* instruction where spill is to occur *) |
| 88 |
reg : CB.cell, (* register to spill *) |
| 89 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 90 |
annotations : Annotations.annotations ref (* annotations *) |
| 91 |
} -> |
| 92 |
{code : I.instruction list, (* instr + reload code *) |
| 93 |
proh : CB.cell list, (* prohibited from future spilling *) |
| 94 |
newReg : CB.cell option (* the reloaded value is here *) |
| 95 |
} |
| 96 |
|
| 97 |
(* |
| 98 |
* Rename all uses fromSrc to toSrc |
| 99 |
*) |
| 100 |
type renameSrc = |
| 101 |
{instr : I.instruction, (* instruction where spill is to occur *) |
| 102 |
fromSrc : CB.cell, (* register to rename *) |
| 103 |
toSrc : CB.cell (* register to rename to *) |
| 104 |
} -> |
| 105 |
{code : I.instruction list, (* renamed instr *) |
| 106 |
proh : CB.cell list, (* prohibited from future spilling *) |
| 107 |
newReg : CB.cell option (* the renamed value is here *) |
| 108 |
} |
| 109 |
|
| 110 |
(* Reload the register dst from spillLoc. |
| 111 |
* The value is originally from register reg. |
| 112 |
*) |
| 113 |
type reloadDst = |
| 114 |
{dst : CB.cell, (* register to reload to *) |
| 115 |
reg : CB.cell, (* the register *) |
| 116 |
spillLoc : G.spillLoc, (* logical spill location *) |
| 117 |
annotations : Annotations.annotations ref (* annotations *) |
| 118 |
} -> I.instruction list (* reload code *) |
| 119 |
|
| 120 |
(* |
| 121 |
* The following function rewrites an instruction and insert |
| 122 |
* spill and reload code around it. The list of spill and reload |
| 123 |
* registers may have duplicates. |
| 124 |
*) |
| 125 |
val spillRewrite : |
| 126 |
{ graph : G.interferenceGraph, |
| 127 |
spill : spill, |
| 128 |
spillSrc : spillSrc, |
| 129 |
spillCopyTmp : spillCopyTmp, |
| 130 |
reload : reload, |
| 131 |
reloadDst : reloadDst, |
| 132 |
renameSrc : renameSrc, |
| 133 |
copyInstr : copyInstr, |
| 134 |
cellkind : CB.cellkind, |
| 135 |
spillSet : CB.cell list G.PPtHashTable.hash_table, |
| 136 |
reloadSet : CB.cell list G.PPtHashTable.hash_table, |
| 137 |
killSet : CB.cell list G.PPtHashTable.hash_table |
| 138 |
} -> |
| 139 |
{ pt : G.programPoint, (* starting program pt *) |
| 140 |
annotations : Annotations.annotations ref, (* annotations *) |
| 141 |
instrs : I.instruction list (* instructions to spill *) |
| 142 |
} -> |
| 143 |
I.instruction list (* instruction sequence after rewriting *) |
| 144 |
(* Note, instructions are in reverse order *) |
| 145 |
|
| 146 |
end |