Whether the graph is reducible: whether every loop has its header as its only entry (Java:
isReducible()).
The loops of a reducible graph are its natural loops. A node counts only if the entries reach it.
Time: O(1).
The number of loops (Java: loopCount()).
Time: O(1).
Returns the body of loop: its nodes and those of the loops nested in it.
The nodes come in this order: first the header, then, in ascending order, the other nodes whose
innermost loop is loop, then the nodes of the nested loops in the same form, loop after loop
in ID order.
The result is a view of this forest's own array, not a copy, and must not be modified (Java: an unmodifiable view). All bodies share the array, so a node is stored once, however deeply its loop is nested.
Time: O(1).
loop ID in 0..loopCount-1
node IDs of the body
Returns the entries of loop, in ascending order.
These are the nodes of the loop with an in-node outside the loop, and the entries of the graph that lie in the loop. An in-node counts only if the entries of the graph reach it. A loop that can only be entered through its header has the header as its only entry.
The result is a view of this forest's own array, not a copy.
Time: O(entriesOf(loop).size).
loop ID in 0..loopCount-1
entry node IDs
StaticofReturns the loop nesting forest of graph with one entry. Equivalent to of(graph, [entry]).
Time: as for the form with a list of entries. Memory: as for the form with a list of entries.
the control-flow graph
node ID in 0..nodeCount-1
the loop nesting forest
Returns the loop nesting forest of graph with the given entries.
The entries work as in Dominators.of: an
entry given twice counts once, and with no entries, no node is reachable, so there is no loop.
Their order matters here: it decides which node of an irreducible loop the search reaches
first, and so which node is its header.
Time: O(number of entries + (nodeCount + edgeCount) log nodeCount) on a reducible graph. On an irreducible graph, an edge costs one more step for every loop it enters other than through the header. Memory: the result, as given in the class documentation; while it runs, about 45 x nodeCount + 4 x edgeCount bytes more, plus 28 bytes per loop and 12 bytes per entry of a loop.
the control-flow graph
node IDs in 0..nodeCount-1, in the order the search takes them
the loop nesting forest
The loop nesting forest of a control-flow graph: its loops, how they nest and where each of them is entered, irreducible loops included.
A loop has a header, through which it is normally entered, and a body: the header, the other nodes of the loop and those of the loops nested in it. Loops.of finds the loops from the entry of the graph - here, the loop of a method
loadaround its blockthen, from its control flowcfgand its entry blockentry:The forest is defined on every graph, reducible or not, over the nodes that the entries reach:
Uses Havlak's algorithm, without recursion. On a reducible graph, the loops are the natural loops. An irreducible loop is a cycle that can be entered at more than one node, as
goto, bytecode or generated state machines produce it. It is one loop with several entries, and which of them is the header depends on the order of the search. An entry of the graph that lies in a loop is an entry of that loop. A node with a self-loop is the header of a loop of its own, unless it already is the header of a larger one. Nodes that no entry reaches are in no loop.Loops have IDs
0..loopCount-1, in preorder of the forest: a loop has a smaller ID than the loops nested in it, which follow it as one range of IDs. Going through the IDs downwards visits the inner loops first.Like
Dominators, the analysis follows edges against their direction and so takes aBiAdjacentGraph; the same graph serves both. Instances are immutable.Memory: 4 x nodeCount bytes, plus 4 bytes per node in a loop, 24 bytes per loop and 4 bytes per entry of a loop.