1.1.1
Description of file here.
Calculates dominanace frontiers from a dominator tree.
Find dominance frontiers
Find dominance frontiers
Find dominance frontiers
Utilities for graph manipulation.
Array<Array<number>>
:
Array<Array<number>>
:
}
Array<Array<number>>
:
}
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.
any
:
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.
Array<number>
:
An array of depth (i.e. level) numbers
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.
Returns a DJ-graph which is a graph that consts of the dominator tree and select join edges from the input graph.
Utilities for working with dominators and their frontiers.
Type: object
Type: object
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.
((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}
:
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( ', ' )}` );
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.
Array
:
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.
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.
Array<number>
:
A list of all node sin the DF of the input set
Loops through each strict dominator of the given node.
DOMINATORS UP
(any)
(any)
This will visit the dominators starting with the to
node and moving up the idom tree
until it gets to the root.
This will return all strict dominators for the given node. Same as dominators
but
excluding the given node.
(number)
Array<number>
:
This returns a list of all dominators for the given node, including the node itself since a node always dominates itself.
(any)
Array<number>
:
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.
(boolean | Array<number>)
:
DOMINATES DOWN
(any)
(any)
This is the same as the strictlyDominates()
function but includes the given node.
(boolean | Array<number>)
:
Thie loops through all nodes strictly dominated by the given node.
Thie loops through all nodes strictly dominated by the given node, including the node itself.
DOMINANCE FRONTIER DOWN
(any)
(any)
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.
Returns the dominanace frontier of a given node.
(number)
Array<number>
:
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.
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:
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.
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 ];
}
}
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
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
Array<number>
: