| 1 |
(* |
| 2 |
* This module counts the number of copies (in bytes) |
| 3 |
* generated after register allocation. Mainly useful for fine-tuning. |
| 4 |
*) |
| 5 |
functor CFGCountCopies |
| 6 |
( structure CFG : CONTROL_FLOW_GRAPH |
| 7 |
structure InsnProps : INSN_PROPERTIES (* where I = CFG.I *) |
| 8 |
where type I.addressing_mode = CFG.I.addressing_mode |
| 9 |
and type I.ea = CFG.I.ea |
| 10 |
and type I.instr = CFG.I.instr |
| 11 |
and type I.instruction = CFG.I.instruction |
| 12 |
and type I.operand = CFG.I.operand |
| 13 |
structure SdiJumps : SDI_JUMPS (* where I = CFG.I *) |
| 14 |
where type I.addressing_mode = CFG.I.addressing_mode |
| 15 |
and type I.ea = CFG.I.ea |
| 16 |
and type I.instr = CFG.I.instr |
| 17 |
and type I.instruction = CFG.I.instruction |
| 18 |
and type I.operand = CFG.I.operand |
| 19 |
) : CFG_OPTIMIZATION = |
| 20 |
struct |
| 21 |
structure CFG = CFG |
| 22 |
structure G = Graph |
| 23 |
|
| 24 |
val name = "count copies" |
| 25 |
|
| 26 |
val copies = MLRiscControl.mkCounter ("copies", "copy count") |
| 27 |
|
| 28 |
fun run (cfg as G.GRAPH graph) = let |
| 29 |
val blocks = map #2 (#nodes graph ()) |
| 30 |
fun loc _ = 0 |
| 31 |
fun count(CFG.BLOCK{insns, ...}, n) = let |
| 32 |
fun scan([], n) = n |
| 33 |
| scan(i::is, n) = |
| 34 |
if InsnProps.moveInstr i then |
| 35 |
scan(is, n + SdiJumps.sdiSize(i, loc, 0)) |
| 36 |
else scan(is, n) |
| 37 |
in scan(!insns, n) |
| 38 |
end |
| 39 |
in |
| 40 |
copies := !copies + foldr count 0 blocks; |
| 41 |
cfg |
| 42 |
end |
| 43 |
end |