| 1 |
(* cfgExpandCopies.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2001 Bell Labs, Lucent Technologies |
| 4 |
* |
| 5 |
* This module expands all parallel copies into normal instructions |
| 6 |
*) |
| 7 |
|
| 8 |
functor CFGExpandCopies |
| 9 |
(structure CFG : CONTROL_FLOW_GRAPH |
| 10 |
structure Shuffle : SHUFFLE (* where I = CFG.I *) |
| 11 |
where type I.addressing_mode = CFG.I.addressing_mode |
| 12 |
and type I.ea = CFG.I.ea |
| 13 |
and type I.instr = CFG.I.instr |
| 14 |
and type I.instruction = CFG.I.instruction |
| 15 |
and type I.operand = CFG.I.operand |
| 16 |
) : CFG_OPTIMIZATION = |
| 17 |
struct |
| 18 |
structure CFG = CFG |
| 19 |
structure I = CFG.I |
| 20 |
|
| 21 |
val name = "expand copies" |
| 22 |
|
| 23 |
fun run (cfg as Graph.GRAPH graph) = let |
| 24 |
fun expand(I.COPY{k, dst, src, tmp, ...}) = let |
| 25 |
val shuffle = |
| 26 |
case k |
| 27 |
of CellsBasis.GP => Shuffle.shuffle |
| 28 |
| CellsBasis.FP => Shuffle.shufflefp |
| 29 |
| _ => MLRiscErrorMsg.error ("CFGExpandCopies", "shuffle") |
| 30 |
in shuffle{dst=dst, src=src, tmp=tmp} |
| 31 |
end |
| 32 |
| expand(I.ANNOTATION{i,a}) = |
| 33 |
map (fn i => I.ANNOTATION{i=i, a=a}) (expand i) |
| 34 |
| expand i = [i] |
| 35 |
|
| 36 |
fun expandInstrs(_, CFG.BLOCK{insns, ...}) = |
| 37 |
insns := |
| 38 |
List.foldr |
| 39 |
(fn (i, rest) => List.revAppend(expand(i), rest)) |
| 40 |
[] |
| 41 |
(!insns) |
| 42 |
in |
| 43 |
#forall_nodes graph expandInstrs; |
| 44 |
cfg |
| 45 |
end |
| 46 |
end |