public class ControlFlowGraph
extends java.lang.Object
BlockContainer at the start of block transforms
(before loop detection)
Created by covers1624 on 19/4/21.
| Modifier and Type | Field and Description |
|---|---|
ControlFlowNode[] |
cfg
Nodes array, indexed by original block index.
|
BlockContainer |
container
The container for which the
ControlFlowGraph was created. |
java.util.BitSet |
directExits
directExits.get(i) == true if cfg[i] directly contains a
branch/leave instruction leaving container. |
java.util.Map<Block,ControlFlowNode> |
nodes
A map of
Block to ControlFlowNode. |
java.util.BitSet |
reachableExits
reachableExits.get(i) == true if there is a path from cfg[i]
to a node not dominated by cfg[i], or if there is a path from cfg[i]
to a branch/leave instruction leaving the container. |
| Constructor and Description |
|---|
ControlFlowGraph(BlockContainer container)
Constructs a control flow graph for the blocks in the given block container.
|
| Modifier and Type | Method and Description |
|---|---|
ControlFlowNode |
getNode(Block block)
Gets the control flow node for the block.
|
boolean |
hasDirectExit(ControlFlowNode node)
Gets whether the control flow node directly contains a branch/leave instruction
exiting the container.
|
boolean |
hasReachableExit(ControlFlowNode node)
Returns true if there is a control flow path from
node to one of the following:
- Branch or leave instruction leaving this.container. |
void |
resetVisited()
Resets all
ControlFlowNode.visited flags for all nodes in this graph. |
public final BlockContainer container
ControlFlowGraph was created.
This may differ from the container currently holding a block, because a transform could have moved the block since the CFG was created.
public final ControlFlowNode[] cfg
Originally cfg[i].block == container.blocks.get(i)
but may have since been moved/reordered by transforms.
public final java.util.Map<Block,ControlFlowNode> nodes
Block to ControlFlowNode.
Unlike the cfg array, this can be used to discover control flow nodes even after blocks were moved/reordered by transforms.
public final java.util.BitSet directExits
directExits.get(i) == true if cfg[i] directly contains a
branch/leave instruction leaving container.public final java.util.BitSet reachableExits
reachableExits.get(i) == true if there is a path from cfg[i]
to a node not dominated by cfg[i], or if there is a path from cfg[i]
to a branch/leave instruction leaving the container.public ControlFlowGraph(BlockContainer container)
Return statements, exceptions, or branches leaving the block container are not modeled by the control flow graph.
container - The container.public ControlFlowNode getNode(Block block)
Precondition: the block belonged to the container at the start of the block transforms
(where the control flow graph was created).
block - The block to get the ControlFlowNode for.public boolean hasReachableExit(ControlFlowNode node)
node to one of the following:
- Branch or leave instruction leaving this.container.
- Branch instruction within this container to another node that is not dominated by node.
If this function returns false, the only way control flow can leave the set of nodes
dominated by node is by executing a return; or throw; instruction.
node - The node to check.public boolean hasDirectExit(ControlFlowNode node)
node - The node to check.public void resetVisited()
ControlFlowNode.visited flags for all nodes in this graph.