21 |
|
|
22 |
fun inc (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1) |
fun inc (IL.V{useCnt, ...}) = (useCnt := !useCnt + 1) |
23 |
fun dec (IL.V{useCnt, ...}) = (useCnt := !useCnt - 1) |
fun dec (IL.V{useCnt, ...}) = (useCnt := !useCnt - 1) |
|
fun setBinding (IL.V{bind, ...}, vb) = bind := vb |
|
24 |
|
|
25 |
fun init (IL.Program{globalInit, initially, strands, ...}) = let |
fun init (IL.Program{globalInit, initially, strands, ...}) = let |
26 |
fun clearVar (IL.V{useCnt, ...}) = useCnt := 0 |
fun clearVar (IL.V{useCnt, ...}) = useCnt := 0 |
53 |
* is used to count the live variables at exits, since the context affects the |
* is used to count the live variables at exits, since the context affects the |
54 |
* treatment of these. |
* treatment of these. |
55 |
*) |
*) |
|
(* FIXME: setting the binding here is probably redundant, since the mk functions do it too! *) |
|
56 |
fun incNode exitCount (IL.ND{kind, ...}) = (case kind |
fun incNode exitCount (IL.ND{kind, ...}) = (case kind |
57 |
of IL.JOIN{phis, ...} => let |
of IL.JOIN{phis, ...} => let |
58 |
fun f (y, xs) = ( |
fun f (y, xs) = incList xs |
|
setBinding (y, IL.VB_PHI xs); |
|
|
incList xs) |
|
59 |
in |
in |
60 |
List.app f (!phis) |
List.app f (!phis) |
61 |
end |
end |
62 |
| IL.COND{cond, ...} => inc cond |
| IL.COND{cond, ...} => inc cond |
63 |
| IL.ASSIGN{stm = (y, rhs), ...} => ( |
| IL.ASSIGN{stm = (y, rhs), ...} => IL.RHS.app inc rhs |
64 |
setBinding (y, IL.VB_RHS rhs); |
| IL.MASSIGN{stm = (ys, rator, xs), ...} => List.app inc xs |
|
IL.RHS.app inc rhs) |
|
|
| IL.MASSIGN{stm = (ys, rator, xs), ...} => let |
|
|
fun setB (_, []) = () |
|
|
| setB (i, x::xs) = ( |
|
|
setBinding (x, IL.VB_MULTIOP(i, rator, xs)); |
|
|
setB (i+1, xs)) |
|
|
in |
|
|
setB (0, ys); |
|
|
List.app inc xs |
|
|
end |
|
65 |
| IL.NEW{args, ...} => incList args |
| IL.NEW{args, ...} => incList args |
66 |
| IL.SAVE{rhs, ...} => inc rhs |
| IL.SAVE{rhs, ...} => inc rhs |
67 |
| IL.EXIT{live, ...} => exitCount live |
| IL.EXIT{live, ...} => exitCount live |
69 |
(* end case *)) |
(* end case *)) |
70 |
(* increment the counts of variables used in the initially code *) |
(* increment the counts of variables used in the initially code *) |
71 |
fun incInitially (IL.Initially{create, rangeInit, iters, ...}) = let |
fun incInitially (IL.Initially{create, rangeInit, iters, ...}) = let |
72 |
fun incIter (param, lo, hi) = ( |
fun incIter (param, lo, hi) = (inc lo; inc hi) |
|
setBinding (param, IL.VB_PARAM); (* QUESTION: should there be a special kind for this? *) |
|
|
inc lo; inc hi) |
|
73 |
in |
in |
74 |
IL.CFG.apply (incNode (fn live => incList live)) rangeInit; |
IL.CFG.apply (incNode (fn live => incList live)) rangeInit; |
75 |
List.app incIter iters; |
List.app incIter iters; |
81 |
fun incMethod (IL.Method{body, ...}) = |
fun incMethod (IL.Method{body, ...}) = |
82 |
IL.CFG.apply (incNode (fn live => incList live)) body |
IL.CFG.apply (incNode (fn live => incList live)) body |
83 |
in |
in |
|
List.app (fn x => setBinding(x, IL.VB_PARAM)) params; |
|
84 |
IL.CFG.apply (incNode (fn live => incList live)) stateInit; |
IL.CFG.apply (incNode (fn live => incList live)) stateInit; |
85 |
List.app incMethod methods |
List.app incMethod methods |
86 |
end |
end |