| 1 |
(* |
| 2 |
* This is the signature of a dominator tree. |
| 3 |
* The dominator tree includes lots of query methods. |
| 4 |
* |
| 5 |
* -- Allen |
| 6 |
*) |
| 7 |
|
| 8 |
signature DOMINATOR_TREE = |
| 9 |
sig |
| 10 |
|
| 11 |
structure GI : GRAPH_IMPLEMENTATION |
| 12 |
|
| 13 |
exception Dominator |
| 14 |
|
| 15 |
type ('n,'e,'g) dom_info |
| 16 |
|
| 17 |
(* Dominator/postdominator trees *) |
| 18 |
type ('n,'e,'g) dominator_tree = |
| 19 |
('n,unit,('n,'e,'g) dom_info) Graph.graph |
| 20 |
type ('n,'e,'g) postdominator_tree = |
| 21 |
('n,unit,('n,'e,'g) dom_info) Graph.graph |
| 22 |
|
| 23 |
type node = Graph.node_id |
| 24 |
|
| 25 |
(* Compute the (post)dominator tree from a flowgraph *) |
| 26 |
val makeDominator : ('n,'e,'g) Graph.graph -> ('n,'e,'g) dominator_tree |
| 27 |
val makePostdominator : ('n,'e,'g) Graph.graph -> |
| 28 |
('n,'e,'g) postdominator_tree |
| 29 |
|
| 30 |
(* The following methods work on both dominator/postdominator trees. |
| 31 |
* When operating on a postdominator tree, the interpretation of these |
| 32 |
* methods are reversed in the obvious manner. |
| 33 |
*) |
| 34 |
|
| 35 |
(* Extract the original CFG *) |
| 36 |
val cfg : ('n,'e,'g) dominator_tree -> ('n,'e,'g) Graph.graph |
| 37 |
|
| 38 |
(* The height of the dominator tree *) |
| 39 |
val max_levels : ('n,'e,'g) dominator_tree -> int |
| 40 |
|
| 41 |
(* Return a map from node id -> level (level(root) = 0) *) |
| 42 |
val levelsMap : ('n,'e,'g) dominator_tree -> int Array.array |
| 43 |
|
| 44 |
(* Return a map from node id i -> the node_id j, |
| 45 |
* where j is the level 1 node that dominates i. |
| 46 |
* Special case: if i = ENTRY, then j = ENTRY. |
| 47 |
* This table is cached. |
| 48 |
*) |
| 49 |
val entryPos : ('n,'e,'g) dominator_tree -> int Array.array |
| 50 |
|
| 51 |
(* Return a map from node id -> immediate (post)dominator *) |
| 52 |
val idomsMap : ('n,'e,'g) dominator_tree -> int Array.array |
| 53 |
|
| 54 |
(* Immediately (post)dominates? *) |
| 55 |
val immediately_dominates : ('n,'e,'g) dominator_tree -> node * node -> bool |
| 56 |
|
| 57 |
(* (Post)dominates? *) |
| 58 |
val dominates : ('n,'e,'g) dominator_tree -> node * node -> bool |
| 59 |
|
| 60 |
(* Strictly (post)dominates? *) |
| 61 |
val strictly_dominates : ('n,'e,'g) dominator_tree -> node * node -> bool |
| 62 |
|
| 63 |
(* Immediate (post)dominator of a node (~1 if none) *) |
| 64 |
val idom : ('n,'e,'g) dominator_tree -> node -> node |
| 65 |
|
| 66 |
(* Nodes that the node immediately (post)dominates *) |
| 67 |
val idoms : ('n,'e,'g) dominator_tree -> node -> node list |
| 68 |
|
| 69 |
(* Nodes that the node (post)dominates (includes self) *) |
| 70 |
val doms : ('n,'e,'g) dominator_tree -> node -> node list |
| 71 |
|
| 72 |
(* Return the level of a node in the tree *) |
| 73 |
val level : ('n,'e,'g) dominator_tree -> node -> int |
| 74 |
|
| 75 |
(* Return the least common ancestor of a pair of nodes *) |
| 76 |
val lca : ('n,'e,'g) dominator_tree -> node * node -> node |
| 77 |
|
| 78 |
(* The following methods require both the dominator and postdominator trees. |
| 79 |
*) |
| 80 |
(* Are two nodes control equivalent? *) |
| 81 |
val control_equivalent : |
| 82 |
('n,'e,'g) dominator_tree * ('n,'e,'g) postdominator_tree -> |
| 83 |
node * node -> bool |
| 84 |
|
| 85 |
(* Compute the control equivalent partitions of a graph *) |
| 86 |
val control_equivalent_partitions : |
| 87 |
('n,'e,'g) dominator_tree * ('n,'e,'g) postdominator_tree -> |
| 88 |
node list list |
| 89 |
|
| 90 |
end |
| 91 |
|