public class SSACFG extends Object implements ControlFlowGraph<SSAInstruction,ISSABasicBlock>
ControlFlowGraph
which stores the structure. This decision from 2004 may have been
premature optimization, left over from a world where IR
s and related structures were long-lived. In today's system, they
are cached and reconstituted by SSACache
. Perhaps we should just extend AbstractCFG
and not worry so much about
space.
As the current implementation stands, the delegate graph stores the graph structure, and this class additionally stores
SSACFG.BasicBlock
s and the SSAInstruction
array.Modifier and Type | Class and Description |
---|---|
class |
SSACFG.BasicBlock
A Basic Block in an SSA IR
|
class |
SSACFG.ExceptionHandlerBasicBlock |
Modifier and Type | Field and Description |
---|---|
protected AbstractCFG<IInstruction,IBasicBlock<IInstruction>> |
delegate
A delegate CFG, pre-built, which stores the graph structure of this CFG.
|
protected SSAInstruction[] |
instructions
The "normal" instructions which constitute the SSA form.
|
protected IMethod |
method
The
IMethod this ControlFlowGraph represents |
Constructor and Description |
---|
SSACFG(IMethod method,
AbstractCFG cfg,
SSAInstruction[] instructions) |
Modifier and Type | Method and Description |
---|---|
void |
addEdge(ISSABasicBlock src,
ISSABasicBlock dst) |
void |
addNode(ISSABasicBlock n)
add a node to this graph
|
boolean |
containsNode(ISSABasicBlock N) |
SSACFG.BasicBlock |
entry()
Return the entry basic block in the CFG
|
boolean |
equals(Object o) |
SSACFG.BasicBlock |
exit() |
SSACFG.BasicBlock |
getBasicBlock(int bb) |
SSACFG.BasicBlock |
getBlockForInstruction(int instructionIndex)
Get the basic block an instruction belongs to.
|
BitVector |
getCatchBlocks() |
Collection<ISSABasicBlock> |
getExceptionalPredecessors(ISSABasicBlock b)
The order of blocks returned should be arbitrary but deterministic.
|
List<ISSABasicBlock> |
getExceptionalSuccessors(ISSABasicBlock b)
The order of blocks returned must indicate the exception-handling scope.
|
SSAInstruction[] |
getInstructions()
NB: Use iterators such as IR.iterateAllInstructions() instead of this method.
|
int |
getMaxNumber() |
IMethod |
getMethod() |
SSACFG.BasicBlock |
getNode(int number) |
Collection<ISSABasicBlock> |
getNormalPredecessors(ISSABasicBlock b)
The order of blocks returned should be arbitrary but deterministic.
|
Collection<ISSABasicBlock> |
getNormalSuccessors(ISSABasicBlock b)
The order of blocks returned should be arbitrary but deterministic.
|
int |
getNumber(ISSABasicBlock b) |
int |
getNumberOfNodes() |
int |
getPredNodeCount(ISSABasicBlock b)
Return the number of
immediate predecessor nodes of n |
IntSet |
getPredNodeNumbers(ISSABasicBlock node) |
Iterator<ISSABasicBlock> |
getPredNodes(ISSABasicBlock b)
Return an
Iterator over the immediate predecessor nodes of n
This method never returns null . |
int |
getProgramCounter(int index)
TODO: move this into IR?
|
int |
getSuccNodeCount(ISSABasicBlock b)
Return the number of
immediate successor nodes of this Node in the Graph |
IntSet |
getSuccNodeNumbers(ISSABasicBlock b) |
Iterator<ISSABasicBlock> |
getSuccNodes(ISSABasicBlock b)
Return an Iterator over the immediate successor nodes of n
|
boolean |
hasEdge(ISSABasicBlock src,
ISSABasicBlock dst) |
boolean |
hasExceptionalEdge(SSACFG.BasicBlock src,
SSACFG.BasicBlock dest)
has exceptional edge src -> dest
|
int |
hashCode() |
boolean |
hasNormalEdge(SSACFG.BasicBlock src,
SSACFG.BasicBlock dest)
has normal edge src -> dest
|
boolean |
isCatchBlock(int i)
is the given i a catch block?
|
Iterator<ISSABasicBlock> |
iterateNodes(IntSet s) |
Iterator<ISSABasicBlock> |
iterator() |
void |
removeAllIncidentEdges(ISSABasicBlock node) |
void |
removeEdge(ISSABasicBlock src,
ISSABasicBlock dst) |
void |
removeIncomingEdges(ISSABasicBlock node) |
void |
removeNode(ISSABasicBlock n)
remove a node from this graph
|
void |
removeNodeAndEdges(ISSABasicBlock N)
remove a node and all its incident edges
|
void |
removeOutgoingEdges(ISSABasicBlock node) |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
protected final SSAInstruction[] instructions
SSAPhiInstruction
s, which dwell in
SSACFG.BasicBlock
s instead.protected final IMethod method
IMethod
this ControlFlowGraph
representsprotected final AbstractCFG<IInstruction,IBasicBlock<IInstruction>> delegate
public SSACFG(IMethod method, AbstractCFG cfg, SSAInstruction[] instructions)
IllegalArgumentException
- if method is nullpublic SSACFG.BasicBlock getBlockForInstruction(int instructionIndex)
getBlockForInstruction
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
instructionIndex
- an instruction indexpublic SSAInstruction[] getInstructions()
getInstructions
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
public BitVector getCatchBlocks()
getCatchBlocks
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
public boolean isCatchBlock(int i)
public SSACFG.BasicBlock entry()
ControlFlowGraph
entry
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
public SSACFG.BasicBlock exit()
exit
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
public int getNumber(ISSABasicBlock b) throws IllegalArgumentException
getNumber
in interface NumberedNodeManager<ISSABasicBlock>
IllegalArgumentException
public SSACFG.BasicBlock getNode(int number)
getNode
in interface NumberedNodeManager<ISSABasicBlock>
public int getMaxNumber()
getMaxNumber
in interface NumberedNodeManager<ISSABasicBlock>
public Iterator<ISSABasicBlock> iterator()
iterator
in interface NodeManager<ISSABasicBlock>
iterator
in interface Iterable<ISSABasicBlock>
Iterator
of the nodes in this graphpublic int getNumberOfNodes()
getNumberOfNodes
in interface NodeManager<ISSABasicBlock>
public Iterator<ISSABasicBlock> getPredNodes(ISSABasicBlock b) throws IllegalArgumentException
EdgeManager
Iterator
over the immediate predecessor nodes of n
This method never returns null
.getPredNodes
in interface EdgeManager<ISSABasicBlock>
Iterator
over the immediate predecessor nodes of this Node.IllegalArgumentException
public int getPredNodeCount(ISSABasicBlock b) throws IllegalArgumentException
EdgeManager
immediate predecessor
nodes of ngetPredNodeCount
in interface EdgeManager<ISSABasicBlock>
IllegalArgumentException
public Iterator<ISSABasicBlock> getSuccNodes(ISSABasicBlock b) throws IllegalArgumentException
EdgeManager
This method never returns null
.
getSuccNodes
in interface EdgeManager<ISSABasicBlock>
IllegalArgumentException
public int getSuccNodeCount(ISSABasicBlock b) throws IllegalArgumentException
EdgeManager
immediate successor
nodes of this Node in the GraphgetSuccNodeCount
in interface EdgeManager<ISSABasicBlock>
IllegalArgumentException
public void addNode(ISSABasicBlock n) throws UnsupportedOperationException
NodeManager
addNode
in interface NodeManager<ISSABasicBlock>
UnsupportedOperationException
public void addEdge(ISSABasicBlock src, ISSABasicBlock dst) throws UnsupportedOperationException
addEdge
in interface EdgeManager<ISSABasicBlock>
UnsupportedOperationException
public void removeEdge(ISSABasicBlock src, ISSABasicBlock dst) throws UnsupportedOperationException
removeEdge
in interface EdgeManager<ISSABasicBlock>
UnsupportedOperationException
public void removeAllIncidentEdges(ISSABasicBlock node) throws UnsupportedOperationException
removeAllIncidentEdges
in interface EdgeManager<ISSABasicBlock>
UnsupportedOperationException
public void removeNodeAndEdges(ISSABasicBlock N) throws UnsupportedOperationException
Graph
removeNodeAndEdges
in interface Graph<ISSABasicBlock>
UnsupportedOperationException
- if the graph implementation does not allow removalpublic void removeNode(ISSABasicBlock n) throws UnsupportedOperationException
NodeManager
removeNode
in interface NodeManager<ISSABasicBlock>
UnsupportedOperationException
public int getProgramCounter(int index)
ControlFlowGraph
getProgramCounter
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
index
- an instruction indexpublic boolean containsNode(ISSABasicBlock N)
containsNode
in interface NodeManager<ISSABasicBlock>
public IMethod getMethod()
getMethod
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
public List<ISSABasicBlock> getExceptionalSuccessors(ISSABasicBlock b)
ControlFlowGraph
getExceptionalSuccessors
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
public Collection<ISSABasicBlock> getExceptionalPredecessors(ISSABasicBlock b)
ControlFlowGraph
getExceptionalPredecessors
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
public boolean hasExceptionalEdge(SSACFG.BasicBlock src, SSACFG.BasicBlock dest)
IllegalArgumentException
- if dest is nullpublic boolean hasNormalEdge(SSACFG.BasicBlock src, SSACFG.BasicBlock dest)
IllegalArgumentException
- if dest is nullpublic Collection<ISSABasicBlock> getNormalSuccessors(ISSABasicBlock b)
ControlFlowGraph
getNormalSuccessors
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
public Collection<ISSABasicBlock> getNormalPredecessors(ISSABasicBlock b)
ControlFlowGraph
getNormalPredecessors
in interface ControlFlowGraph<SSAInstruction,ISSABasicBlock>
public Iterator<ISSABasicBlock> iterateNodes(IntSet s)
iterateNodes
in interface NumberedNodeManager<ISSABasicBlock>
public void removeIncomingEdges(ISSABasicBlock node) throws UnsupportedOperationException
removeIncomingEdges
in interface EdgeManager<ISSABasicBlock>
UnsupportedOperationException
public void removeOutgoingEdges(ISSABasicBlock node) throws UnsupportedOperationException
removeOutgoingEdges
in interface EdgeManager<ISSABasicBlock>
UnsupportedOperationException
public boolean hasEdge(ISSABasicBlock src, ISSABasicBlock dst) throws UnimplementedError
hasEdge
in interface EdgeManager<ISSABasicBlock>
UnimplementedError
public IntSet getSuccNodeNumbers(ISSABasicBlock b) throws IllegalArgumentException
getSuccNodeNumbers
in interface NumberedEdgeManager<ISSABasicBlock>
IllegalArgumentException
public IntSet getPredNodeNumbers(ISSABasicBlock node) throws UnimplementedError
getPredNodeNumbers
in interface NumberedEdgeManager<ISSABasicBlock>
UnimplementedError
public SSACFG.BasicBlock getBasicBlock(int bb)