Graphity for TypeScript 3.0.0
    Preparing search index...

    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 load around its block then, from its control flow cfg and its entry block entry:

    // The basic blocks of load are the nodes 0..5 of cfg: entry, header, body, then,
    // next, exit.

    // Find the loops of load, from its entry block.
    const loops = Loops.of(BiAdjacentGraph.of(cfg), entry);

    // Find the loop around the block then, with its header and its body.
    const loop = loops.innermostLoopOf(then); // 0 - the for loop, the only loop
    const header = loops.headerOf(loop); // 1 - the block header
    // [1, 2, 3, 4] - header, body, then and next
    const blocks = loops.bodyOf(loop);

    The forest is defined on every graph, reducible or not, over the nodes that the entries reach:

    • The outermost loops are the strongly connected components that contain at least one edge.
    • The header of a loop is the node of its component that a depth-first search from the entries reaches first. The search takes the entries in list order and the out-nodes of a node in ascending order.
    • Without the edges that lead into the header from inside the component, the rest of it breaks up into the nested loops, by the same rule.

    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 a BiAdjacentGraph; 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.

    Index
    • get isReducible(): boolean

      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).

      Returns boolean

    • 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).

      Parameters

      • loop: number

        loop ID in 0..loopCount-1

      Returns Int32Array

      node IDs of the body

      RangeError if loop is out of range

    • 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).

      Parameters

      • loop: number

        loop ID in 0..loopCount-1

      Returns SortedIntView

      entry node IDs

      RangeError if loop is out of range

    • Returns the header of loop.

      Time: O(1).

      Parameters

      • loop: number

        loop ID in 0..loopCount-1

      Returns number

      header node ID

      RangeError if loop is out of range

    • Returns the innermost loop that contains node, or -1 if it lies in no loop.

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns number

      loop ID, or -1

      RangeError if node is out of range

    • Returns whether node lies in loop, directly or in a loop nested in it.

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      • loop: number

        loop ID in 0..loopCount-1

      Returns boolean

      true if the node is in the loop

      RangeError if node or loop is out of range

    • Returns the loop depth of node: the number of loops that contain it. A node in no loop has loop depth 0.

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns number

      loop depth

      RangeError if node is out of range

    • Returns the loop that immediately encloses loop, or -1 for an outermost loop.

      Time: O(1).

      Parameters

      • loop: number

        loop ID in 0..loopCount-1

      Returns number

      enclosing loop ID, smaller than loop, or -1

      RangeError if loop is out of range

    • Returns 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.

      Parameters

      • graph: BiAdjacentGraph

        the control-flow graph

      • entry: number

        node ID in 0..nodeCount-1

      Returns Loops

      the loop nesting forest

      RangeError if entry is out of range

      Error if graph has more than 2^30 - 6 nodes

    • 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.

      Parameters

      • graph: BiAdjacentGraph

        the control-flow graph

      • entries: IntList

        node IDs in 0..nodeCount-1, in the order the search takes them

      Returns Loops

      the loop nesting forest

      RangeError if an entry is out of range

      Error if graph has more than 2^30 - 6 nodes