Graphity for TypeScript 3.0.0
    Preparing search index...

    The dominators of a graph with one or more entries, such as the control flow of a method, given by the immediate dominator of every node.

    A node d dominates a node n if every path from an entry to n passes through d; every node dominates itself. The immediate dominator of n is the dominator closest to n other than n itself. The immediate dominators form the dominator tree, which Graphs.dominatorTree returns as a graph. Several entries act like one virtual root above all of them. A node that only this virtual root dominates, such as an entry, has no immediate dominator and is a root of the dominator tree, which is then a forest. A node that no entry reaches has no immediate dominator either; Dominators.isReachable tells the two apart.

    Whether one node dominates another is an ancestor query on the dominator tree. Ancestry.of answers it in O(log nodeCount) and PreorderAncestry in O(1). The analysis follows the edges against their direction, so it takes a BiAdjacentGraph. Here, the dominators of the basic blocks of the method load from its entry, and whether body and then dominate next:

    const dominators = Dominators.of(BiAdjacentGraph.of(cfg), entry);
    // 2 - the block body
    const idom = dominators.immediateDominatorOf(next);
    const dominance = Ancestry.of(dominators);
    const bodyDominatesNext = dominance.isAncestorOf(body, next); // true
    const thenDominatesNext = dominance.isAncestorOf(then, next); // false

    The post-dominators are the dominators of the transposed graph, with the exits as entries. A node p post-dominates n if every path from n to an exit passes through p. Here, next is the first block that every path from body to the exit of load passes through:

    const postDominators = Dominators.of(BiAdjacentGraph.of(cfg).transposed(), exit);
    const join = postDominators.immediateDominatorOf(body); // 4 - the block next

    A node from which no exit can be reached, such as one in an endless loop, has no post-dominator, unless an extra exit with an edge from that loop is added to the graph first.

    Uses the algorithm of Lengauer and Tarjan, without recursion. Dominance frontiers and control dependence are in the package @kobayami/graphity-controlflow.

    Instances are immutable.

    Memory: 4 x nodeCount bytes and 1 bit per node, plus the graph, which stays reachable as long as the dominators are.

    Index
    • Returns the immediate dominator of node, or -1 if it has none.

      A node has none if it is an entry, if only the virtual root above several entries dominates it, or if no entry reaches it.

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns number

      immediate dominator, or -1

      RangeError if node is out of range

    • Returns whether node is reachable from an entry.

      Time: O(1).

      Parameters

      • node: number

        node ID in 0..nodeCount-1

      Returns boolean

      true if a path leads from an entry to node

      RangeError if node is out of range

    • Returns the dominators of graph with the single entry entry. Equivalent to of(graph, [entry]).

      Time: O((nodeCount + edgeCount) log nodeCount). Memory: 4 x nodeCount bytes and 1 bit per node for the result; while it runs, up to 32 x nodeCount bytes more.

      Parameters

      Returns Dominators

      the dominators

      RangeError if entry is out of range

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

    • Returns the dominators of graph with the given entries.

      Several entries act like one virtual root above all of them, as the class documentation describes. Their order does not matter. An entry given twice counts once, and with no entries, no node is reachable.

      Time: O(number of entries + (nodeCount + edgeCount) log nodeCount). Memory: 4 x nodeCount bytes and 1 bit per node for the result; while it runs, up to 32 x nodeCount bytes more.

      Parameters

      Returns Dominators

      the dominators

      RangeError if an entry is out of range

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