| 1 |
(* |
| 2 |
* This updated signature describes the abstractions on ``cells'', which |
| 3 |
* denote storage cells in the machine architecture. |
| 4 |
* |
| 5 |
* Allen Leung (12/2/00) |
| 6 |
*) |
| 7 |
signature CELLS_BASIS = |
| 8 |
sig |
| 9 |
type sz = int (* width in bits *) |
| 10 |
type cell_id = int (* unique cell identifier *) |
| 11 |
type register_id = int (* register id *) |
| 12 |
type register_num = int (* register number *) |
| 13 |
(* Note: register_id and register_num should probably be made into |
| 14 |
* different datatypes with different tags, but FLINT currently boxes |
| 15 |
* such objects. |
| 16 |
*) |
| 17 |
|
| 18 |
datatype cellkindInfo = INFO of {name:string, nickname:string} |
| 19 |
datatype cellkindDesc = |
| 20 |
DESC of |
| 21 |
{kind : cellkind, |
| 22 |
counter : int ref, |
| 23 |
dedicated : int ref, |
| 24 |
(* It is sometimes desirable to allocate dedicated |
| 25 |
* pseudo registers that will get rewritten to something else, |
| 26 |
* e.g., the virtual frame pointer. |
| 27 |
* Since these registers are never assigned a register by |
| 28 |
* the register allocator, a limited number of these kinds |
| 29 |
* of registers may be generated. |
| 30 |
*) |
| 31 |
low : int, |
| 32 |
high : int, |
| 33 |
toString : register_id -> string, |
| 34 |
toStringWithSize : register_id * sz -> string, |
| 35 |
defaultValues : (register_id * int) list, |
| 36 |
physicalRegs : cell Array.array ref, |
| 37 |
zeroReg : register_id option |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
(* Cellkind denotes the types of storage cells. |
| 42 |
* This definition is further augumented by architecture specific |
| 43 |
* cells descriptions. Type cellkind is an equality type. |
| 44 |
*) |
| 45 |
and cellkind = |
| 46 |
GP (* general purpose register *) |
| 47 |
| FP (* floating point register *) |
| 48 |
| CC (* condition code register *) |
| 49 |
|
| 50 |
| MEM (* memory *) |
| 51 |
| CTRL (* control dependence *) |
| 52 |
|
| 53 |
| MISC_KIND of cellkindInfo ref (* client defined *) |
| 54 |
|
| 55 |
|
| 56 |
(* |
| 57 |
* A cell is a stateful object reprensenting a storage cell in a |
| 58 |
* processor. Cells are partitioned into their kinds, such as |
| 59 |
* GP (general purpose, i.e., integer, registers), * FP |
| 60 |
* (floating point registers) etc. Each cell has an unique cell_id |
| 61 |
* that determines its identity. Its attributes include |
| 62 |
* |
| 63 |
* 1. its color, and |
| 64 |
* 2. other client defined properties, |
| 65 |
* which is represented as a property list of annotations. |
| 66 |
* |
| 67 |
* Note that cell_id and color are two distinct concepts; for example, |
| 68 |
* two different cells may have the same color. |
| 69 |
* |
| 70 |
* Type cell is not an equality type. We provide the function |
| 71 |
* sameCell for testing for object identity, and the function |
| 72 |
* sameColor for testing for color identity. For most things, |
| 73 |
* sameColor is the right function to use. |
| 74 |
*) |
| 75 |
and cell = |
| 76 |
CELL of {id : cell_id, |
| 77 |
col : cellColor ref, |
| 78 |
desc : cellkindDesc, |
| 79 |
an : Annotations.annotations ref |
| 80 |
} |
| 81 |
and cellColor = |
| 82 |
MACHINE of register_id |
| 83 |
| PSEUDO |
| 84 |
| ALIASED of cell |
| 85 |
| SPILLED |
| 86 |
|
| 87 |
(* |
| 88 |
* Basic functions on cellkinds |
| 89 |
*) |
| 90 |
val cellkindToString : cellkind -> string (* name *) |
| 91 |
val cellkindToNickname : cellkind -> string (* abbreviation *) |
| 92 |
val newCellKind : {name:string,nickname:string} -> cellkind |
| 93 |
|
| 94 |
(* |
| 95 |
* Basic functions on cells. |
| 96 |
* All functions marked with +++ implicitly chases aliases. |
| 97 |
* |
| 98 |
* Function register_id returns the current color of a node. |
| 99 |
* The color of a pseudo register is the same as its cell_id. |
| 100 |
* A spilled node is given a color of ~1, so all spilled nodes have |
| 101 |
* the same color. |
| 102 |
* |
| 103 |
* NOTE: distinction between registerId and registerNum: |
| 104 |
* Function register_id returns register_id. |
| 105 |
* Physical registers in distinct |
| 106 |
* cell classes are given disjoint register_ids. So for example, |
| 107 |
* the register id for r0 and f0 in the Alpha are different. |
| 108 |
* |
| 109 |
* The function, registerNum, on the other hand, returns a |
| 110 |
* register number of a cell that starts from 0 for physical registers. |
| 111 |
* So registerNum r0 = registerNum f0 = 0. It behaves the same |
| 112 |
* as registerId in other cases. |
| 113 |
* |
| 114 |
* The function physicalRegisterNum is the same as registerNum, |
| 115 |
* except that it is an error to call it on a pseudo or spilled cell. |
| 116 |
* As a rule, use registerId whenever possible. Function registerNum |
| 117 |
* is used only if you have to deal with machine encoding. |
| 118 |
*) |
| 119 |
val cellId : cell -> cell_id (* return cell id *) |
| 120 |
val cellkind : cell -> cellkind (* return cellkind *) |
| 121 |
val isConst : cell -> bool |
| 122 |
val annotations : cell -> Annotations.annotations ref |
| 123 |
val sameCell : cell * cell -> bool (* object identity *) |
| 124 |
val sameKind : cell * cell -> bool (* same cellkind? *) |
| 125 |
val chase : cell -> cell (* chase aliases +++ *) |
| 126 |
val sameAliasedCell : cell * cell -> bool (* chase aliases +++ *) |
| 127 |
val hashCell : cell -> word |
| 128 |
val registerId : cell -> register_id (* +++ *) |
| 129 |
val registerNum : cell -> register_num (* +++ *) |
| 130 |
val physicalRegisterNum : cell -> int (* +++ *) |
| 131 |
val sameColor : cell * cell -> bool (* color identity +++ *) |
| 132 |
val compareColor : cell * cell -> order (* +++ *) |
| 133 |
val toString : cell -> string (* pretty print a cell +++ *) |
| 134 |
val toStringWithSize : cell * sz -> string (* +++ *) |
| 135 |
|
| 136 |
(* Set the color of the 'from' cell to be the same as |
| 137 |
* the 'to' cell. The 'from' cell MUST be a pseudo register, |
| 138 |
* and cannot be of kind CONST. |
| 139 |
*) |
| 140 |
val setAlias : {from: cell, to: cell} -> unit (* +++ *) |
| 141 |
|
| 142 |
(* |
| 143 |
* The following abstraction represents a set of cells |
| 144 |
* indexed by colors. When two or more cells with the same color |
| 145 |
* exists, we arbitrarily choose a representative. |
| 146 |
* WARNING: while using sorted_cells it is important not to |
| 147 |
* update the colors in the elements, or you'll get wrong results. |
| 148 |
*) |
| 149 |
structure SortedCells : |
| 150 |
sig |
| 151 |
type sorted_cells |
| 152 |
val empty : sorted_cells |
| 153 |
val enter : cell * sorted_cells -> sorted_cells |
| 154 |
val rmv : cell * sorted_cells -> sorted_cells |
| 155 |
val member : cell * sorted_cells -> bool |
| 156 |
val eq : sorted_cells * sorted_cells -> bool |
| 157 |
val notEq : sorted_cells * sorted_cells -> bool |
| 158 |
val uniq : cell list -> sorted_cells |
| 159 |
val difference : sorted_cells * sorted_cells -> sorted_cells |
| 160 |
val intersect : sorted_cells * sorted_cells -> sorted_cells |
| 161 |
val union : sorted_cells * sorted_cells -> sorted_cells |
| 162 |
val return : sorted_cells -> cell list |
| 163 |
val isEmpty : sorted_cells -> bool |
| 164 |
val emptyIntersection : sorted_cells * sorted_cells -> bool |
| 165 |
val nonEmptyIntersection : sorted_cells * sorted_cells -> bool |
| 166 |
end |
| 167 |
|
| 168 |
(* |
| 169 |
* Hash table indexed by cell id. |
| 170 |
* IMPORTANT: this table is not indexed by color! |
| 171 |
*) |
| 172 |
structure HashTable : MONO_HASH_TABLE where type Key.hash_key = cell |
| 173 |
|
| 174 |
(* |
| 175 |
* Hash table indexed by cell color. |
| 176 |
* IMPORTANT: this table is indexed by color! |
| 177 |
* ALSO: DO NOT change the colors of the cells while using this table! |
| 178 |
*) |
| 179 |
structure ColorTable : MONO_HASH_TABLE where type Key.hash_key = cell |
| 180 |
|
| 181 |
(* |
| 182 |
* Cell set represents a map from cellkind to sorted_cells. |
| 183 |
*) |
| 184 |
structure CellSet : |
| 185 |
sig |
| 186 |
type cellset |
| 187 |
(* cellset functions *) |
| 188 |
val empty : cellset |
| 189 |
val add : cell * cellset -> cellset |
| 190 |
val rmv : cell * cellset -> cellset |
| 191 |
val get : cellkindDesc -> cellset -> cell list |
| 192 |
val update : cellkindDesc -> cellset * cell list -> cellset |
| 193 |
val map : {from:cell, to:cell} -> cellset -> cellset |
| 194 |
|
| 195 |
(* convert cellset into a list of cells *) |
| 196 |
val toCellList : cellset -> cell list |
| 197 |
|
| 198 |
(* pretty printing *) |
| 199 |
val toString : cellset -> string |
| 200 |
end |
| 201 |
|
| 202 |
(* |
| 203 |
* These annotations adds extra definitions and uses to an instruction |
| 204 |
*) |
| 205 |
exception DEF_USE of {cellkind:cellkind, defs:cell list, uses:cell list} |
| 206 |
val DEFUSE : {cellkind:cellkind, defs:cell list, uses:cell list} |
| 207 |
Annotations.property |
| 208 |
|
| 209 |
(* Internal use for alias analysis; don't use! *) |
| 210 |
val mem : register_id -> cell |
| 211 |
|
| 212 |
(* Internal use only! *) |
| 213 |
val show : cellkindDesc -> register_id -> string |
| 214 |
val showWithSize : cellkindDesc -> register_id * sz -> string |
| 215 |
|
| 216 |
val array0 : cell Array.array |
| 217 |
end |
| 218 |
|