52 |
end |
end |
53 |
(* increment the use counts of a list of variables *) |
(* increment the use counts of a list of variables *) |
54 |
val incList = List.app inc |
val incList = List.app inc |
55 |
(* increment the counts of the variables used in a node *) |
(* increment the counts of the variables used in a node. The exitCount function |
56 |
fun incNode (IL.ND{kind, ...}) = (case kind |
* is used to count the live variables at exits, since the context affects the |
57 |
|
* treatment of these. |
58 |
|
*) |
59 |
|
fun incNode exitCount (IL.ND{kind, ...}) = (case kind |
60 |
of IL.JOIN{phis, ...} => let |
of IL.JOIN{phis, ...} => let |
61 |
fun f (y, xs) = ( |
fun f (y, xs) = ( |
62 |
setBinding (y, IL.VB_PHI xs); |
setBinding (y, IL.VB_PHI xs); |
75 |
| (IL.CONS(_, args)) => incList args |
| (IL.CONS(_, args)) => incList args |
76 |
(* end case *)) |
(* end case *)) |
77 |
| IL.NEW{args, ...} => incList args |
| IL.NEW{args, ...} => incList args |
78 |
| IL.EXIT{kind, live, ...} => (case kind |
| IL.EXIT{live, ...} => exitCount live |
|
of ExitKind.RETURN => () (* don't count the live variables as uses *) |
|
|
| ExitKind.DIE => () |
|
|
| _ => incList live |
|
|
(* end case *)) |
|
79 |
| _ => () |
| _ => () |
80 |
(* end case *)) |
(* end case *)) |
81 |
(* increment the counts of variables used in the initially code *) |
(* increment the counts of variables used in the initially code *) |
84 |
setBinding (param, IL.VB_PARAM); (* QUESTION: should there be a special kind for this? *) |
setBinding (param, IL.VB_PARAM); (* QUESTION: should there be a special kind for this? *) |
85 |
inc lo; inc hi) |
inc lo; inc hi) |
86 |
in |
in |
87 |
IL.CFG.apply incNode rangeInit; |
IL.CFG.apply (incNode (fn live => incList live)) rangeInit; |
88 |
List.app incIter iters; |
List.app incIter iters; |
89 |
IL.CFG.apply incNode (#1 create); |
IL.CFG.apply (incNode (fn _ => ())) (#1 create); |
90 |
List.app inc (#3 create) |
List.app inc (#3 create) |
91 |
end |
end |
92 |
(* increment the counts of the variables used in a strand *) |
(* increment the counts of the variables used in a strand *) |
95 |
ListPair.app |
ListPair.app |
96 |
(fn (x, (_, x')) => IL.Var.setBinding(x, IL.VB_RHS(IL.VAR x'))) |
(fn (x, (_, x')) => IL.Var.setBinding(x, IL.VB_RHS(IL.VAR x'))) |
97 |
(stateIn, state); |
(stateIn, state); |
98 |
IL.CFG.apply incNode body) |
IL.CFG.apply (incNode (fn live => incList live)) body) |
99 |
in |
in |
100 |
List.app (fn x => setBinding(x, IL.VB_PARAM)) params; |
List.app (fn x => setBinding(x, IL.VB_PARAM)) params; |
101 |
List.app (inc o #2) state; (* state variables are implicitly used *) |
IL.CFG.apply (incNode (fn live => incList live)) stateInit; |
|
IL.CFG.apply incNode stateInit; |
|
102 |
List.app incMethod methods |
List.app incMethod methods |
103 |
end |
end |
104 |
in |
in |
107 |
clearInitially initially; |
clearInitially initially; |
108 |
List.app clearStrand strands; |
List.app clearStrand strands; |
109 |
(* then count uses *) |
(* then count uses *) |
110 |
IL.CFG.apply incNode globalInit; |
IL.CFG.apply (incNode (fn _ => ())) globalInit; |
111 |
incInitially initially; |
incInitially initially; |
112 |
List.app incStrand strands |
List.app incStrand strands |
113 |
end |
end |