public class LTDominators extends Stack<BasicBlock>
Sources: TOPLAS article, Muchnick book
The current implementation (4/25/00) does not include the EXIT node in any solution despite the fact that it is part of the CFG (it has incoming edges). This is to be compatible with the old code.
Modifier and Type | Field and Description |
---|---|
private ControlFlowGraph |
cfg
a convenient place to locate the cfg to avoid passing it internally
|
(package private) static boolean |
DEBUG |
protected int |
DFSCounter
a counter for assigning DFS numbers
|
private boolean |
forward
Indicates whether we perform the algorithm over the CFG or
the reverse CFG, i.e., whether we are computing dominators or
post-dominators.
|
private IR |
ir |
private Map<BasicBlock,LTDominatorInfo> |
ltDominators |
private BasicBlock[] |
vertex
a mapping from DFS number to their basic blocks
|
Constructor and Description |
---|
LTDominators(IR ir,
boolean forward)
The constructor, called by the perform method
|
Modifier and Type | Method and Description |
---|---|
protected void |
analyze(IR ir) |
static void |
approximate(IR ir,
boolean forward)
Compute approximate dominator/post dominator without unfactoring
exception handlers.
|
private void |
checkReachability(IR ir)
Checks that all nodes were reached.
|
private void |
compress(BasicBlock block)
This recursive method performs the path compression
|
private void |
DFS() |
protected void |
DFS(BasicBlock block)
The non-recursive depth-first numbering code called from Step 1.
|
private BasicBlock |
EVAL(BasicBlock block)
This method inspects the passed block and returns the following:
block, if block is a root of a tree in the forest
any vertex, u !
|
private BasicBlock |
getAncestor(BasicBlock block) |
private BasicBlock |
getChild(BasicBlock block) |
private BasicBlock |
getDom(BasicBlock block) |
private BasicBlock |
getFirstNode()
Get the first node, either entry or exit
depending on which way we are viewing the graph
|
(package private) LTDominatorInfo |
getInfo(BasicBlock bb) |
private BasicBlock |
getLabel(BasicBlock block) |
private Enumeration<BasicBlock> |
getNextNodes(BasicBlock block) |
private BasicBlock |
getParent(BasicBlock block) |
private Enumeration<BasicBlock> |
getPrevNodes(BasicBlock block) |
private int |
getSemi(BasicBlock block) |
private int |
getSize(BasicBlock block) |
private void |
LINK(BasicBlock block1,
BasicBlock block2)
Adds edge (block1, block2) to the forest maintained as an auxiliary
data structure.
|
static void |
perform(IR ir,
boolean forward,
boolean unfactor)
The entry point for this phase
|
private void |
printDFSNumbers()
Print the result of the DFS numbering performed in Step 1
|
private void |
printNextNodes(BasicBlock block)
Print the "next" nodes (either out or in) for the passed block
depending on which way we are viewing the graph
|
private void |
printResults(IR ir)
Print the nodes that dominate each basic block
|
private void |
step1()
The goal of this step is to perform a DFS numbering on the CFG,
starting at the root.
|
private void |
step2()
This is the heart of the algorithm.
|
private void |
step3()
This final step sets the final dominator information.
|
compare, copy, empty, getTOS, isEmpty, iterator, peek, pop, push, shallowCopy, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
static final boolean DEBUG
private final boolean forward
protected int DFSCounter
private BasicBlock[] vertex
private final ControlFlowGraph cfg
private Map<BasicBlock,LTDominatorInfo> ltDominators
LTDominators(IR ir, boolean forward)
ir
- the governing IRforward
- Should we compute regular dominators, or post-dominators?public static void perform(IR ir, boolean forward, boolean unfactor)
ir
- the IRforward
- Should we compute regular dominators, or post-dominators?unfactor
- Should we unfactor the CFG?public static void approximate(IR ir, boolean forward)
ir
- the IRforward
- Should we compute regular dominators, or post-dominators?private void checkReachability(IR ir)
ir
- the governing IRprivate void step1()
private void DFS()
private BasicBlock getFirstNode()
private void printNextNodes(BasicBlock block)
block
- the basic block of interestprivate Enumeration<BasicBlock> getNextNodes(BasicBlock block)
block
- the basic block of interestprivate Enumeration<BasicBlock> getPrevNodes(BasicBlock block)
block
- the basic block of interestprotected void DFS(BasicBlock block)
block
- the basic block to processprivate void step2()
private BasicBlock EVAL(BasicBlock block)
See TOPLAS 1(1), July 1979, p 128 for details.
block
- the block to evaluateprivate void compress(BasicBlock block)
block
- the block of interestprivate void LINK(BasicBlock block1, BasicBlock block2)
block1
- a basic block corresponding to the source of the new edgeblock2
- a basic block corresponding to the source of the new edgeprivate void step3()
private BasicBlock getDom(BasicBlock block)
block
- the block whose dominator is of interestprivate BasicBlock getParent(BasicBlock block)
block
- the block whose parent is of interestprivate BasicBlock getAncestor(BasicBlock block)
block
- the block whose ancestor is of interestprivate BasicBlock getLabel(BasicBlock block)
block
- the block whose label is of interestnull
if the block is
null
private int getSemi(BasicBlock block)
block
- the block whose semidominator is of interestprivate int getSize(BasicBlock block)
block
- block the block whose size is of interestnull
private BasicBlock getChild(BasicBlock block)
block
- the block whose child is of interestprivate void printResults(IR ir)
ir
- the IRprivate void printDFSNumbers()
LTDominatorInfo getInfo(BasicBlock bb)