Description of file here.

Author: Julian Jensen <jjdanois@gmail.com>
Since: 1.0.0

Calculates dominanace frontiers from a dominator tree.

Author: Julian Jensen <jjdanois@gmail.com>
Since: 1.0.0

check

Find dominance frontiers

check(vertices: Array<Array<number>>, idoms: Array<number?>)
Parameters
vertices (Array<Array<number>>)
idoms (Array<number?>)

frontiers_from_preds

Find dominance frontiers

frontiers_from_preds(preds: Array<Array<number>>, idoms: Array<number?>)
Parameters
preds (Array<Array<number>>)
idoms (Array<number?>)

frontiers_from_succs

Find dominance frontiers

frontiers_from_succs(succs: Array<Array<number>>, idoms: Array<number?>)
Parameters
succs (Array<Array<number>>)
idoms (Array<number?>)

Utilities for graph manipulation.

Author: Julian Jensen <jjdanois@gmail.com>

normalize

normalize
Parameters
nodes (Array<(Array<number> | number)>)
Returns
Array<Array<number>>:

condRefToSelf

condRefToSelf
Parameters
seed (Array<Array<number>>)
chk (function (number): boolean? = twoOrMore)
dest (Array<Array<number>>? = arrayOfArrays(seed))
Returns
Array<Array<number>>: }

simpleRefToSelf

simpleRefToSelf
Parameters
seed (Array<Array<number>>)
dest (Array<Array<number>>? = arrayOfArrays(seed))
Returns
Array<Array<number>>: }

create_j_edges

This will create and return the J-edges of a graph. The J-edges, or Join edges, make up one-half of the DJ-graph. For more information read the documentation for the DJ-graph.

You need only pass the nodes of the graph to this function. The rest of the parameters are optional and will be computed if not provided. I allow the options to pass them in case you already have them calculated from elsewhere, just to make things a bit faster. If no arguments are provided other than the basic vertices, it will compute the immediate dominators, create the dominator tree, and compute the levels, and discard all of those results. Not a big deal unless you're dealing with very large graphs, in which case you should calculate those separately and provide them as inputs here.

create_j_edges(_nodes: Array<Array<number>>, domLevels: Array<number>?, domTree: Array<Array<number>>?, idoms: Array<number>?): any
Parameters
_nodes (Array<Array<number>>) An array of arrays of successors indices, as always
domLevels (Array<number>?) The levels (or depth) of the nodes in the dominator tree
domTree (Array<Array<number>>?) The dominator tree in the standard format, same as _nodes
idoms (Array<number>?) The immediate dominators
Returns
any:

create_levels

Calculate the level of each node in terms of how many edges it takes to reach the root. For the sake of simplicity, this uses a BFS to compute depth values.

create_levels(nodes: Array<Array<number>>): Array<number>
Parameters
nodes (Array<Array<number>>) The graph
Returns
Array<number>: An array of depth (i.e. level) numbers

create_nodes

A convenience method. It returns an array of object, one for each nodes in the graph, and in that order, that holds most of the information you could want for working with graphs.

Specifically, each node looks as descibed in the typedef for GraphNode.

create_nodes(_nodes: Array<Array<number>>, idoms: Array<number>?)
Parameters
_nodes (Array<Array<number>>) The usual graph nodes
idoms (Array<number>?) The immediate dominators, if not provided, they will be computed

create_dj_graph

Returns a DJ-graph which is a graph that consts of the dominator tree and select join edges from the input graph.

create_dj_graph(nodes: Array<Array<number>>, idoms: Array<number>?, domTree: Array<Array<number>>?)
Parameters
nodes (Array<Array<number>>) Graph in the usual format
idoms (Array<number>?) Immediate dominators, if omiteed, they will be computed
domTree (Array<Array<number>>?) Dominator tree, it omitted, will be computed

Utilities for working with dominators and their frontiers.

Author: Julian Jensen <jjdanois@gmail.com>
Since: 1.0.0

GraphNode

GraphNode

Type: object

Properties
id (number) : The index of this node in the original array
succs (Array<number>) : The successor node indices
preds (Array<number>) : The predecessor node indices
domSuccs (Array<number>) : The dominator tree successor indices
idom (number) : The immediate dominator and, of course, dominator tree predecessor
level (number) : The depth (or level) of the vertex
domLevel (number) : The depth in the dominator tree
jSuccs (Array<number>) : The successor J-edges, if any, of this node
jPreds (Array<number>) : The predecessor J-edges, if any, of this node

DomWalkerOptions

DomWalkerOptions

Type: object

Properties
nodes (Array<Array<number>>)
idoms (Array<number?>?)
domTree (Array<Array<number>>?)
jEdges (Array<Array<number>>?)
frontiers (Array<Array<number>>?)
djGraph (Array<Array<Array<number>>>?)
domLevels (Array<number>?)

make_dom

This will associated a graph with a number of useful utility functions. It will return an object with a variety of functions that operate on the graphs.

You might notice that many of these functions I took from the WebKit dominators.h file, which I really liked, and, although I re-wrote the code completely (obviously, since it was in C++), I decided to keep their comments with a few small alterations or corrections. I decided to not use their iterated dominance frontier code, because it was as efficient as it could be. Instead, I implemented one that uses a DJ-graph that I found in Chapter 4 of "The SSA Book," called "Advanced Contruction Algorithms for SSA" by D. Das, U. Ramakrishna, V. Sreedhar. That book doesn't seem to be published or, if it has, I've missed it. You can build the book yourself, supposedly, (I couldn't make that work, though) from here: SSA Book or you can probably find a PDF version of it somewhere on the web, which is what I did.

make_dom(opts: (DomWalkerOptions | Array<Array<number>>)): {forStrictDominators: forStrictDominators, forDominators: forDominators, strictDominators: strictDominators, dominators: dominators, forStrictlyDominates: forStrictlyDominates, forDominates: forDominates, strictlyDominates: strictlyDominates, dominates: dominates, forDominanceFrontier: forDominanceFrontier, dominanceFrontier: dominanceFrontier, forIteratedDominanceFrontier: forIteratedDominanceFrontier, forPrunedIteratedDominanceFrontier: forPrunedIteratedDominanceFrontier, iterated_dominance_frontier: iterated_dominance_frontier, iteratedDominanceFrontier: iteratedDominanceFrontier}
Parameters
Returns
{forStrictDominators: forStrictDominators, forDominators: forDominators, strictDominators: strictDominators, dominators: dominators, forStrictlyDominates: forStrictlyDominates, forDominates: forDominates, strictlyDominates: strictlyDominates, dominates: dominates, forDominanceFrontier: forDominanceFrontier, dominanceFrontier: dominanceFrontier, forIteratedDominanceFrontier: forIteratedDominanceFrontier, forPrunedIteratedDominanceFrontier: forPrunedIteratedDominanceFrontier, iterated_dominance_frontier: iterated_dominance_frontier, iteratedDominanceFrontier: iteratedDominanceFrontier}:
Example
const myGraph = make_dom( graph );

myGraph.forStrictDominators( n => console.log( `${n} is a strict dominator of 9` ), 9 );
if ( myGraph.strictlyDominates( 7, 9 ) )
    console.log( `7 strictly dominates 9` );
console.log( `Node at index 7 strictly dominates these: ${myGraph.strictlyDominates( 7 ).join( ', ' )}` );
console.log( `The strict dominators of 7 are ${myGraph.strictDominators( 7 ).join( ', ' )}` );

alternative_idf

This calculates the iterated dominance frontier quickest of all but requires that you have already computed the dominance frontier for each individual node. If you call this without frontiers being set, it will calculate all of them the first time.

alternative_idf(defs: Array<number>): Array
Parameters
defs (Array<number>)
Returns
Array:

forIteratedDominanceFrontier

Same as iteratedDominanceFrontier( defs ) except it doesn't return anything but will invoke the callback as it discovers each node in the iterated dominance frontier.

forIteratedDominanceFrontier(fn: function (number): any, defs: Array<number>)
Parameters
fn (function (number): any) A callback function with one argument, a node in the DF of the input list
defs (Array<number>) A list of definition nodes

iteratedDominanceFrontier

Given a list of definition nodes, let's call them start nodes, this will return the dominance frontier of those nodes. If you're doing SSA, this would be where you'd want to place phi-functions when building a normal SSA tree. To create a pruned or minimal tree, you'd probably have to discard some of these but it makes for a starting point.

iteratedDominanceFrontier(defs: Array<number>): Array<number>
Parameters
defs (Array<number>) A list of definition nodes
Returns
Array<number>: A list of all node sin the DF of the input set

forStrictDominators

Loops through each strict dominator of the given node.

forStrictDominators(fn: function (number), to: number)
Parameters
fn (function (number))
to (number)

forStrictDominators


DOMINATORS UP


forStrictDominators(fn: any, to: any)
Parameters
fn (any)
to (any)

forDominators

This will visit the dominators starting with the to node and moving up the idom tree until it gets to the root.

forDominators(fn: function (number), to: number)
Parameters
fn (function (number))
to (number)

strictDominators

This will return all strict dominators for the given node. Same as dominators but excluding the given node.

strictDominators(to: number): Array<number>
Parameters
to (number)
Returns
Array<number>:

dominators

This returns a list of all dominators for the given node, including the node itself since a node always dominates itself.

dominators(block: any): Array<number>
Parameters
block (any)
Returns
Array<number>:

strictlyDominates

This will return one of two things. If call with two node numbers, it will return a boolean indicating if the first node strictly dominates the second node.

If called with only one node number then it will create a list of all nodes strictly dominated by the given node.

strictlyDominates(from: number, to: number?): (boolean | Array<number>)
Parameters
from (number)
to (number?)
Returns
(boolean | Array<number>):

strictlyDominates


DOMINATES DOWN


strictlyDominates(from: any, to: any)
Parameters
from (any)
to (any)

dominates

This is the same as the strictlyDominates() function but includes the given node.

dominates(from: number, to: number?): (boolean | Array<number>)
Parameters
from (number)
to (number?)
Returns
(boolean | Array<number>):

forStrictlyDominates

Thie loops through all nodes strictly dominated by the given node.

forStrictlyDominates(fn: function, from: number, notStrict: boolean?)
Parameters
fn (function)
from (number)
notStrict (boolean? = false) =false]

forDominates

Thie loops through all nodes strictly dominated by the given node, including the node itself.

forDominates(fn: function, from: number)
Parameters
fn (function)
from (number)

forDominanceFrontier


DOMINANCE FRONTIER DOWN


forDominanceFrontier(fn: any, from: any)
Parameters
fn (any)
from (any)

forDominanceFrontier

Paraphrasing from Dominator (graph theory):

"The dominance frontier of a block 'from' is the set of all blocks 'to' such that 'from' dominates an immediate predecessor of 'to', but 'from' does not strictly dominate 'to'."

A useful corner case to remember: a block may be in its own dominance frontier if it has a loop edge to itself, since it dominates itself and so it dominates its own immediate predecessor, and a block never strictly dominates itself.

forDominanceFrontier(fn: function, from: number)
Parameters
fn (function)
from (number)

dominanceFrontier

Returns the dominanace frontier of a given node.

dominanceFrontier(from: number): Array<number>
Parameters
from (number)
Returns
Array<number>:

forPrunedIteratedDominanceFrontier

This is a close relative of forIteratedDominanceFrontier(), which allows the given predicate function to return false to indicate that we don't wish to consider the given block. Useful for computing pruned SSA form.

forPrunedIteratedDominanceFrontier(fn: function, from: Array<number>)
Parameters
fn (function)
from (Array<number>)

See README.md for details

For the sake of completeness, below is the fast balanaced version of link, which is not included in the current module code for two reasons:

  1. The LT algorithm with this LINK only becomes faster than the normal implementation when we're dealing with 10s or 100s of thousands of nodes, in which cases you shouldn't be using JavaScript anyway.
  2. I don't have test graph large enough to get proper coverage so, since it's not really useful, I decided to remove it.

This implementation uses arrays rather then an object. That's how I originally implemented this algorithm but that makes it incompatible with the current implementation. I won't convert it since it's not used, however, because it is interesting, I've included it here, for interested parties, of which there will probably be at least zero but not more.

Author: Julian Jensen <jjdanois@gmail.com>
Since: 1.0.0
Example
balanced_link = ( w ) => {
        let s = w,
            v = parent[ w ];

        do
        {
            let cs  = child[ s ],
                bcs = cs !== null ? best[ cs ] : null;

            if ( cs !== null && semi[ best[ w ] ] < semi[ bcs ] )
            {
                let ccs  = child[ cs ],
                    ss   = size[ s ],
                    scs  = size[ cs ],
                    sccs = ccs !== null ? size[ ccs ] : 0;

                if ( ss - scs >= scs - sccs )
                    child[ s ] = ccs;
                else
                {
                    size[ cs ] = ss;
                    ancestor[ s ] = cs;
                    s = cs;
                }
            }
            else
                break;
        }
        while ( true );

        best[ s ] = best[ w ];
        if ( size[ v ] < size[ w ] )
        {
            let t = s;
            s = child[ v ];
            child[ v ] = t;
        }
        size[ v ] = size[ v ] + size[ w ];
        while ( s !== null )
        {
            ancestor[ s ] = v;
            s = child[ s ];
        }
    }

lt

lt(nodes: Array<Array<number>>, startIndex: number, flat: boolean)
Parameters
nodes (Array<Array<number>>)
startIndex (number = 0)
flat (boolean = true)

Implements a near-linear time iterative dominator generator based on this paper: (A Simple, Fast Dominance Algorithm)[https://www.cs.rice.edu/~keith/Embed/dom.pdf] Citation: Cooper, Keith & Harvey, Timothy & Kennedy, Ken. (2006). A Simple, Fast Dominance Algorithm. Rice University, CS Technical Report 06-33870

Author: Julian Jensen <jjdanois@gmail.com>

iterative

Implements a near-linear time iterative dominator generator based on this paper: (A Simple, Fast Dominance Algorithm)[https://www.cs.rice.edu/~keith/Embed/dom.pdf] Citation: Cooper, Keith & Harvey, Timothy & Kennedy, Ken. (2006). A Simple, Fast Dominance Algorithm. Rice University, CS Technical Report 06-33870

iterative(succs: Array<(Array<number> | number)>, startIndex: number, flat: boolean): Array<number>
Parameters
succs (Array<(Array<number> | number)>)
startIndex (number = 0)
flat (boolean = true)
Returns
Array<number>:

nsuccs

nsuccs