| 1 |
(* loop-structure.sig |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies. |
| 4 |
* |
| 5 |
* This module is responsible for locating loop structures (intervals). |
| 6 |
* All loops have only one single entry (via the header) but |
| 7 |
* potentially multiple exits, i.e. the header dominates all nodes |
| 8 |
* within the loop. Other definitions are used for ``loops'' and ``headers'' |
| 9 |
* in the literature. We choose a structural definition that has nicer |
| 10 |
* properties. |
| 11 |
* |
| 12 |
* -- Allen |
| 13 |
*) |
| 14 |
|
| 15 |
signature LOOP_STRUCTURE = |
| 16 |
sig |
| 17 |
|
| 18 |
structure Dom : DOMINATOR_TREE |
| 19 |
structure GI : GRAPH_IMPLEMENTATION |
| 20 |
|
| 21 |
(* |
| 22 |
* DEF: An edge i -> j is a backedge iff j dom i. |
| 23 |
* Here, j is the header, and i -> j \in backedges(j) |
| 24 |
* A loop is identified by its header h. |
| 25 |
*) |
| 26 |
datatype ('n,'e,'g) loop = |
| 27 |
LOOP of { nesting : int, |
| 28 |
header : Graph.node_id, |
| 29 |
loop_nodes : Graph.node_id list, |
| 30 |
backedges : 'e Graph.edge list, |
| 31 |
exits : 'e Graph.edge list |
| 32 |
} |
| 33 |
|
| 34 |
type ('n,'e,'g) loop_info |
| 35 |
|
| 36 |
type ('n,'e,'g) loop_structure = |
| 37 |
(('n,'e,'g) loop,unit, ('n,'e,'g) loop_info) Graph.graph |
| 38 |
|
| 39 |
val dom : ('n,'e,'g) loop_structure -> |
| 40 |
('n,'e,'g) Dom.dominator_tree |
| 41 |
|
| 42 |
(* O(n+e) *) |
| 43 |
val loop_structure : ('n,'e,'g) Dom.dominator_tree -> |
| 44 |
('n,'e,'g) loop_structure |
| 45 |
|
| 46 |
(* return an array mapping node id -> nesting level *) |
| 47 |
val nesting_level : ('n,'e,'g) loop_structure -> Graph.node_id Array.array |
| 48 |
|
| 49 |
(* return an array mapping node id -> header that it belongs to *) |
| 50 |
val header : ('n,'e,'g) loop_structure -> Graph.node_id Array.array |
| 51 |
|
| 52 |
(* given a header, return the set of entry edges into the loop *) |
| 53 |
val entryEdges : ('n,'e,'g) loop_structure -> Graph.node_id -> |
| 54 |
'e Graph.edge list |
| 55 |
|
| 56 |
end |
| 57 |
|