| 1 |
functor SpillTable |
| 2 |
(val architecture : string |
| 3 |
val initialSpillOffset : int |
| 4 |
val spillAreaSz : int |
| 5 |
) : |
| 6 |
sig |
| 7 |
|
| 8 |
val architecture : string |
| 9 |
val beginRA : unit -> unit |
| 10 |
val get : RAGraph.spillLoc -> int |
| 11 |
val getF : RAGraph.spillLoc -> int |
| 12 |
|
| 13 |
end = |
| 14 |
struct |
| 15 |
|
| 16 |
structure G = RAGraph |
| 17 |
|
| 18 |
fun error msg = MLRiscErrorMsg.error(architecture^".SpillTable",msg) |
| 19 |
|
| 20 |
val itow = Word.fromInt |
| 21 |
|
| 22 |
val architecture = architecture |
| 23 |
|
| 24 |
exception RegSpills and FregSpills |
| 25 |
val spillOffset = ref initialSpillOffset |
| 26 |
val regspills : int G.SpillLocHashTable.hash_table = |
| 27 |
G.SpillLocHashTable.mkTable(0,RegSpills) |
| 28 |
val fregspills : int G.SpillLocHashTable.hash_table = |
| 29 |
G.SpillLocHashTable.mkTable(0,FregSpills) |
| 30 |
val lookupReg = G.SpillLocHashTable.lookup regspills |
| 31 |
val enterReg = G.SpillLocHashTable.insert regspills |
| 32 |
val lookupFreg = G.SpillLocHashTable.lookup fregspills |
| 33 |
val enterFreg = G.SpillLocHashTable.insert fregspills |
| 34 |
|
| 35 |
fun beginRA() = |
| 36 |
((* Reset the regspills/fregspills map by need. *) |
| 37 |
if !spillOffset = initialSpillOffset then () |
| 38 |
else (G.SpillLocHashTable.clear regspills; |
| 39 |
G.SpillLocHashTable.clear fregspills |
| 40 |
) |
| 41 |
; |
| 42 |
spillOffset := initialSpillOffset |
| 43 |
) |
| 44 |
|
| 45 |
fun newOffset offset = |
| 46 |
if offset >= spillAreaSz then error "spill area too small" |
| 47 |
else spillOffset := offset |
| 48 |
|
| 49 |
(* Get spill location for integer registers *) |
| 50 |
fun get loc = |
| 51 |
lookupReg loc handle _ => |
| 52 |
let val offset = !spillOffset |
| 53 |
in newOffset(offset+4); |
| 54 |
enterReg (loc,offset); |
| 55 |
offset |
| 56 |
end |
| 57 |
|
| 58 |
(* Get spill location for floating point registers *) |
| 59 |
fun getF loc = |
| 60 |
lookupFreg loc handle _ => |
| 61 |
let val offset = !spillOffset |
| 62 |
val aligned = Word.toIntX (Word.andb(itow (offset+7), itow ~8)) |
| 63 |
in |
| 64 |
newOffset(aligned+8); |
| 65 |
enterFreg (loc, aligned); |
| 66 |
aligned |
| 67 |
end |
| 68 |
|
| 69 |
end |