52 |
} |
} |
53 |
| COND of { |
| COND of { |
54 |
pred : node ref, |
pred : node ref, |
55 |
cond : var, |
cond : var ref, (* the variable being tested (we use a ref to allow rewriting) *) |
56 |
trueBranch : node ref, |
trueBranch : node ref, |
57 |
falseBranch : node ref |
falseBranch : node ref |
58 |
} |
} |
62 |
phis : phi list ref, (* phi nodes (as in JOIN) *) |
phis : phi list ref, (* phi nodes (as in JOIN) *) |
63 |
mask : bool list ref, (* true for incoming fake edges *) |
mask : bool list ref, (* true for incoming fake edges *) |
64 |
var : var, (* the loop variable *) |
var : var, (* the loop variable *) |
65 |
src : var, (* the source of values being iterated over *) |
src : var ref, (* the source of values being iterated over *) |
66 |
bodyEntry : node ref, (* the loop body entry node *) |
bodyEntry : node ref, (* the loop body entry node *) |
67 |
bodyExit : node ref, (* the loop body exit node *) |
bodyExit : node ref, (* the loop body exit node *) |
68 |
succ : node ref (* the loop-exit edge *) |
succ : node ref (* the loop-exit edge *) |
353 |
in |
in |
354 |
List.foldr (fn ((_, xs), ys) => add(xs, ys)) [] (!phis) |
List.foldr (fn ((_, xs), ys) => add(xs, ys)) [] (!phis) |
355 |
end |
end |
356 |
| COND{cond, ...} => [cond] |
| COND{cond, ...} => [!cond] |
357 |
| FOREACH{src, phis, ...} => let |
| FOREACH{src, phis, ...} => let |
358 |
fun add ([], ys) = ys |
fun add ([], ys) = ys |
359 |
| add (SOME x :: xs, ys) = add(xs, x::ys) |
| add (SOME x :: xs, ys) = add(xs, x::ys) |
360 |
| add (NONE :: xs, ys) = add(xs, ys) |
| add (NONE :: xs, ys) = add(xs, ys) |
361 |
in |
in |
362 |
List.foldr (fn ((_, xs), ys) => add(xs, ys)) [src] (!phis) |
List.foldr (fn ((_, xs), ys) => add(xs, ys)) [!src] (!phis) |
363 |
end |
end |
364 |
| ASSIGN{stm=(y, rhs), ...} => (case rhs |
| ASSIGN{stm=(y, rhs), ...} => (case rhs |
365 |
of GLOBAL _ => [] |
of GLOBAL _ => [] |
388 |
fun mkENTRY () = new (ENTRY{succ = ref dummy}) |
fun mkENTRY () = new (ENTRY{succ = ref dummy}) |
389 |
fun mkJOIN phis = new (JOIN{preds = ref [], mask = ref [], phis = ref phis, succ = ref dummy}) |
fun mkJOIN phis = new (JOIN{preds = ref [], mask = ref [], phis = ref phis, succ = ref dummy}) |
390 |
fun mkCOND cond = new (COND{ |
fun mkCOND cond = new (COND{ |
391 |
pred = ref dummy, cond = cond, |
pred = ref dummy, cond = ref cond, |
392 |
trueBranch = ref dummy, falseBranch = ref dummy |
trueBranch = ref dummy, falseBranch = ref dummy |
393 |
}) |
}) |
394 |
fun mkFOREACH (var, src) = ( |
fun mkFOREACH (var, src) = ( |
396 |
new (FOREACH{ |
new (FOREACH{ |
397 |
pred = ref dummy, |
pred = ref dummy, |
398 |
phis = ref [], mask = ref [], |
phis = ref [], mask = ref [], |
399 |
var = var, src = src, |
var = var, src = ref src, |
400 |
bodyEntry = ref dummy, |
bodyEntry = ref dummy, |
401 |
bodyExit = ref dummy, |
bodyExit = ref dummy, |
402 |
succ = ref dummy |
succ = ref dummy |
535 |
(*DEBUG*)handle ex => ( |
(*DEBUG*)handle ex => ( |
536 |
print(concat["error in addEdge(", toString nd1, ",", toString nd2, ")\n"]); |
print(concat["error in addEdge(", toString nd1, ",", toString nd2, ")\n"]); |
537 |
raise ex) |
raise ex) |
538 |
|
(* FIXME: the names replaceInEdge and replaceOutEdge are backwards! *) |
539 |
(* replace the edge src-->oldDst by the edge src-->dst *) |
(* replace the edge src-->oldDst by the edge src-->dst *) |
540 |
fun replaceInEdge {src, oldDst, dst} = ( |
fun replaceInEdge {src, oldDst, dst} = ( |
541 |
(* first set the successor of src *) |
(* first set the successor of src *) |
551 |
| _ => setSucc (src, dst) |
| _ => setSucc (src, dst) |
552 |
(* end case *); |
(* end case *); |
553 |
(* then set the predecessor of dst *) |
(* then set the predecessor of dst *) |
554 |
setPred (dst, src)) |
case kind oldDst |
555 |
|
of FOREACH{bodyExit, pred, ...} => |
556 |
|
if same(!bodyExit, src) |
557 |
|
then setBodyExit (dst, src) |
558 |
|
else setPred (dst, src) |
559 |
|
| _ => setPred (dst, src) |
560 |
|
(* end case *)) |
561 |
(*DEBUG*)handle ex => ( |
(*DEBUG*)handle ex => ( |
562 |
print(concat["error in replaceInEdge(", toString src, ",", toString oldDst, ",", toString dst, ")\n"]); |
print(concat["error in replaceInEdge(", toString src, ",", toString oldDst, ",", toString dst, ")\n"]); |
563 |
raise ex) |
raise ex) |
681 |
in |
in |
682 |
preds := edit (!preds) |
preds := edit (!preds) |
683 |
end |
end |
684 |
|
| FOREACH{pred=pred', bodyExit, ...} => |
685 |
|
if Node.same(!pred', nd) |
686 |
|
then pred' := pred |
687 |
|
else bodyExit := pred |
688 |
| _ => Node.setPred (succ, pred) |
| _ => Node.setPred (succ, pred) |
689 |
(* end case *); |
(* end case *); |
690 |
(* replace the successor edge from pred to nd with an edge from pred to succ *) |
(* replace the successor edge from pred to nd with an edge from pred to succ *) |
694 |
* situation where both branches are the same node. |
* situation where both branches are the same node. |
695 |
*) |
*) |
696 |
if Node.same(!trueBranch, nd) |
if Node.same(!trueBranch, nd) |
697 |
then Node.setTrueBranch(pred, succ) |
then trueBranch := succ |
698 |
else (); |
else (); |
699 |
if Node.same(!falseBranch, nd) |
if Node.same(!falseBranch, nd) |
700 |
then Node.setFalseBranch(pred, succ) |
then falseBranch := succ |
701 |
else ()) |
else ()) |
702 |
|
| FOREACH{bodyEntry, succ=succ', ...} => |
703 |
|
if Node.same(!bodyEntry, nd) |
704 |
|
then bodyEntry := succ |
705 |
|
else succ' := succ |
706 |
| _ => Node.setSucc (pred, succ) |
| _ => Node.setSucc (pred, succ) |
707 |
(* end case *) |
(* end case *) |
708 |
end |
end |