Class FlowGraph
java.lang.Object
EDU.purdue.cs.bloat.util.Graph
EDU.purdue.cs.bloat.cfg.FlowGraph
FlowGraph constructs and represents a Control Flow Graph (CFG) used for
analyzing a method. It consists of the basic blocks of a method.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic booleanstatic booleanstatic final intstatic intstatic final intstatic booleanFields inherited from class Graph
edgeModCount, nodeModCount, removingEdge, removingNode, revRootEdgeModCount, rootEdgeModCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an edge between two nodes in this graph.intReturns the type of a given block.Returns theBlocks in this CFG that begin exception handlers.voidcommit()Commit changes back to the method editor.domChildren(Block block) Returns the blocks that a given block dominates.domFrontier(Block block) Returns the dominance frontier of a given block.Returns the Block that dominates a given block.handlers()Returns all of the Handler objects in this CFG.Returns A Map mapping the first block in an exception handler to its Handler object.init()Returns the initialization block.voidSets up the control flow graph.iteratedDomFrontier(Collection blocks) Returns the iterated dominance frontiers for several basic blocks.iteratedPdomFrontier(Collection blocks) Returns the iterated postdominance frontier for several basic blocks.Returns the Subroutine whose entry block is labeled by a given Label.intReturns the depth of the loop in which a block is contained.loopHeader(Block block) Returns the loop header of the loop containing a given block.intReturns the level of the loop containing a given block.loopTree()Returns the loop tree for the method modeled by this flow graph.intReturns the maximum loop depth (also the maximum loop height) in the control flow graph.method()Returns the method editor for the method modeled by this graph.newBlock()Returns a new Block with the next available Label.pdomChildren(Block block) Returns the postdominator children of a given block.pdomFrontier(Block block) Returns the postdominance frontier of a given block.pdomParent(Block block) Returns the postdominator parent of a given block.Returns the blocks in the flow graph sorted in post-order.preOrder()Returns the blocks in the flow graph sorted in pre-order.voidprint()voidprint(PrintStream out) voidprint(PrintWriter out) Prints the graph.voidvoidprintGraph(PrintStream out) Creates a graphical description of the CFG in the dot language.voidprintGraph(PrintWriter out) voidprintGraph(PrintWriter out, String name) voidremoveEdge(GraphNode v, GraphNode w) Removes an edge from the graph and performs the necessary cleanup.voidremoveNode(Object key) Removes a node (a Block) from the graph.voidremoveSub(Subroutine sub) Removes a subroutine from this method.roots()sink()Returns the sink block.source()Returns the "Enter" block of this CFG.Returns all of the Subroutines in the method modeled by this FlowGraph.toString()Returns a brief textual description of this FlowGraph, namely the name of the method it represents.trace()Returns the basic blocks contained in this CFG in trace order.voidvisit(TreeVisitor visitor) voidvisitChildren(TreeVisitor visitor) Visit each node (block) in this CFG in pre-order.Methods inherited from class Graph
addNode, getNode, hasEdge, hasNode, isAncestorToDescendent, keySet, nodes, postOrderIndex, preds, preOrderIndex, removeUnreachable, size, succs
-
Field Details
-
PEEL_NO_LOOPS
public static final int PEEL_NO_LOOPS- See Also:
-
PEEL_ALL_LOOPS
public static final int PEEL_ALL_LOOPS- See Also:
-
PEEL_LOOPS_LEVEL
public static int PEEL_LOOPS_LEVEL -
DEBUG
public static boolean DEBUG -
DB_GRAPHS
public static boolean DB_GRAPHS -
PRINT_GRAPH
public static boolean PRINT_GRAPH
-
-
Constructor Details
-
FlowGraph
Constructor.- Parameters:
method- The method to create the CFG for.
-
-
Method Details
-
maxLoopDepth
public int maxLoopDepth()Returns the maximum loop depth (also the maximum loop height) in the control flow graph. -
initialize
public void initialize()Sets up the control flow graph. Computes the dominators and the dominance frontier, cleans up the tree, works with the loops, inserts stores to aid copy and constant propagation as well as code generation. -
loopTree
Returns the loop tree for the method modeled by this flow graph. The loop tree represents the nesting of the loops in a method. The procedure is at the root of the loop tree. Nested loops are represented by a parent and child relationship. -
removeSub
Removes a subroutine from this method.- Parameters:
sub- The subroutine to remove.
-
addEdge
-
removeEdge
Removes an edge from the graph and performs the necessary cleanup.- Overrides:
removeEdgein classGraph- Parameters:
v- Node at which edge to be removed originates.w- Node at which edge to be removed terminates.
-
newBlock
Returns a new Block with the next available Label. -
labelSub
Returns the Subroutine whose entry block is labeled by a given Label. -
subroutines
Returns all of the Subroutines in the method modeled by this FlowGraph. -
print
-
print
Prints the graph.- Parameters:
out- The writer to which to print.
-
printGraph
public void printGraph() -
print
public void print() -
printGraph
Creates a graphical description of the CFG in the dot language. The name of the generated file is the name of the method modeled by this CFG followed by a number and the ".dot" postfix. For more information about dot and tools that use it see:http://www.research.att.com/sw/tools/graphviz/
-
printGraph
-
printGraph
-
visitChildren
Visit each node (block) in this CFG in pre-order. -
visit
-
method
Returns the method editor for the method modeled by this graph. -
trace
Returns the basic blocks contained in this CFG in trace order. Trace order implies that basic blocks that end with a conditional jump are followed by their false branch and, where possible, that blocks that end in an unconditional jump are followed by the block that is the target of the unconditional branch.The trace does not contain the source and the sink blocks.
- Returns:
- The basic Blocks in this CFG.
-
commit
public void commit()Commit changes back to the method editor. -
source
Returns the "Enter" block of this CFG. That is, the block through which all paths enter. -
init
Returns the initialization block. -
sink
Returns the sink block. That is, the block through which all paths exit. -
iteratedDomFrontier
Returns the iterated dominance frontiers for several basic blocks.- See Also:
-
iteratedPdomFrontier
Returns the iterated postdominance frontier for several basic blocks.- See Also:
-
roots
-
reverseRoots
- Overrides:
reverseRootsin classGraph- Returns:
- A Collection containing only the sink block.
- See Also:
-
removeNode
Removes a node (a Block) from the graph.- Overrides:
removeNodein classGraph- Parameters:
key- Block to remove
-
handlersMap
Returns A Map mapping the first block in an exception handler to its Handler object.- See Also:
-
handlers
Returns all of the Handler objects in this CFG. -
catchBlocks
Returns theBlocks in this CFG that begin exception handlers. -
domChildren
Returns the blocks that a given block dominates. -
domParent
-
blockType
Returns the type of a given block. A block's type is one of Block.NON_HEADER, Block.IRREDUCIBLE, or Block.REDUCIBLE. -
loopDepth
Returns the depth of the loop in which a block is contained. The block must be contained in a loop. The procedure has depth 0. A loop (while, for, etc.) at the procedure level has depth 1. Depth increases as loops are nested.- Parameters:
block- A block whose depth we are interested in.- See Also:
-
loopLevel
Returns the level of the loop containing a given block. The innermost loops have level 0. The level increases as you go outward to higher loop nestings. For any given loop, the level is the maximum possible.procedure() { // Depth 0, Level 2 (max possible) while() { // Depth 1, Level 1 while() { // Depth 2, Level 0 } } while() { // Depth 1, Level 0 } }- Parameters:
block- A block whose loop level we want to know. This block must be contained in a loop.
-
loopHeader
-
preOrder
-
postOrder
-
pdomChildren
Returns the postdominator children of a given block.- See Also:
-
pdomParent
-
domFrontier
Returns the dominance frontier of a given block.- See Also:
-
pdomFrontier
Returns the postdominance frontier of a given block.- See Also:
-
toString
-