|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object scale.common.Root scale.score.Note scale.score.chords.Chord
public abstract class Chord
This class represents nodes in a CFG.
$Id: Chord.java,v 1.137 2007-10-04 19:58:22 burrill Exp $
Copyright 2008 by the
Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.
The Chord class has derived classes which are dependent on the number of out-going CFG edges. Chord nodes have no out-going data edges. This class handles the in-coming CFG edges. The derived classes must handle the out-going CFG edges.
Field Summary | |
---|---|
protected int |
lineNumber
The source line number. |
Constructor Summary | |
---|---|
protected |
Chord()
|
Method Summary | |
---|---|
void |
addInCfgEdge(Chord node)
Add an in-coming CFG edge. |
void |
changeInDataEdge(Expr oldExpr,
Expr newExpr)
This method changes an incoming data edge to point to a new expression. |
abstract void |
changeOutCfgEdge(Chord oldEdge,
Chord newEdge)
Change the out-going CFG edge indicated by the position to the new edge. |
void |
changeParentOutCfgEdge(Chord newEdge)
Change all my predecessors to point to another CFG node. |
abstract void |
clearEdge(int edge)
Clear the marker associated with the specified out-going CFG edge. |
abstract void |
clearEdgeMarkers()
Clear all the markers. |
abstract Chord |
copy()
Make a copy of this CFG node with the same out-going CFG edges. |
void |
copySourceLine(Chord from)
Copy the source line information. |
static int |
deadCFGNodes()
Return the current number of dead nodes removed because they were not reachable. |
static int |
deletedCFGNodes()
Return the current number of dead nodes removed. |
void |
deleteInCfgEdge(Chord node)
Remove an in-coming CFG edge. |
abstract void |
deleteInDataEdges()
Remove all the in-coming data edges. |
abstract void |
deleteOutCfgEdges()
Remove all the out-going CFG edges. |
abstract boolean |
edgeMarked(int edge)
Return the marker associated with the specified out-going CFG edge. |
int |
executionOrder(Chord n)
Determine the execution ordering of the two CFG nodes. |
void |
expungeFromCfg()
Remove myself from the CFG. |
void |
extractFromCfg()
Remove myself from the CFG but preserve me for future use. |
LoopExitChord |
findLoopExit(LoopHeaderChord header)
Return the LoopExitChord instance, for the
specified loop, that is reachable from this CFG node. |
Vector<PhiExprChord> |
findPhiChords()
Return a vector of all of the phi chords in
the basic block starting at this node. |
Chord |
firstInBasicBlock()
Return the first CFG node in this basic block. |
CallExpr |
getCall(boolean ignorePure)
Return the call expression or null if none. |
abstract Vector<Declaration> |
getDeclList()
Return a vector of all declarations referenced in this CFG node or null . |
Expr |
getDefExpr()
If this CFG node results in a variable being given a new value, return the Expr instance
that specifies the variable. |
DColor |
getDisplayColorHint()
Return a String specifying the color to use for
coloring this node in a graphical display. |
java.lang.String |
getDisplayLabel()
Return a String suitable for labeling this node in a
graphical display. |
DShape |
getDisplayShapeHint()
Return a String specifying a shape to use when
drawing this node in a graphical display. |
abstract Vector<Expr> |
getExprList()
Return a vector of all Expr
instances in this CFG node or null . |
Chord |
getFirstInCfgEdge()
Return the predecessor node. |
Chord |
getInCfgEdge()
Return the predecessor node. |
Chord |
getInCfgEdge(int i)
Return the i-th predecessor node. |
Chord[] |
getInCfgEdgeArray()
Use this method when you may be modifying an in-coming CFG edge to this CFG node while iterating over the in-coming edges. |
Expr |
getInDataEdge(int i)
Return the specified in-coming data edge. |
Expr[] |
getInDataEdgeArray()
Use this method when you may be modifying an in-coming data edge to this expression while iterating over the in-coming edges. |
int |
getLabel()
Return the integer associated with a CFG node. |
abstract Vector<LoadExpr> |
getLoadExprList()
Return a vector of all LoadExpr
instances in this CFG node or null . |
LoopHeaderChord |
getLoopHeader()
Return the LoopHeaderChord object for the
loop that contains this node. |
LoopHeaderChord |
getLoopHeader(int limit)
Return the LoopHeaderChord object for the
loop that contains this node. |
int |
getLoopNumber()
|
abstract Chord |
getNextChord()
Return the next CFG node in the CFG. |
abstract Chord |
getOutCfgEdge(int i)
Return the specified out-going CFG edge. |
abstract Chord[] |
getOutCfgEdgeArray()
Use this method when you may be modifying an out-going CFG edge from this CFG node while iterating over the out-going edges. |
int |
getSourceLineNumber()
Return the source line number associated with this node or -1 if not known. |
static int |
gotoCFGNodes()
Return the current number of GotoChord nodes removed. |
boolean |
inBasicBlock(Chord first)
Return true if this CFG node is in the basic block specified by first. |
int |
indexOfInCfgEdge(Chord in)
Return the index of the specified in-coming CFG edge. |
abstract int |
indexOfOutCfgEdge(Chord to,
int skip)
This routine is needed because it is possible for more than one out-going CFG edge from a CFG node to go the the same CFG node. |
void |
insertAfterOutCfg(Chord newChord,
Chord outEdge)
Insert a new node between me and my out-going CFG edges. |
void |
insertBeforeInCfg(SequentialChord newChord)
Insert a new node before me in the CFG. |
boolean |
isAssignChord()
Return true if this node holds an expression that represents an assignment statement. |
boolean |
isBranch()
Return true if this CFG node may have multiple out-going CFG edges. |
boolean |
isExprChord()
Return true if this is an ExprChord instance. |
boolean |
isFirstInBasicBlock()
Return true if this CFG node is the start of a basic block. |
abstract boolean |
isLastInBasicBlock()
Return true if this is the last CFG node in this basic block. |
boolean |
isLoopExit()
Return true if this CFG node is a LoopExitChord instance. |
boolean |
isLoopHeader()
Return true if this CFG node is a LoopHeaderChord instance. |
boolean |
isLoopPreHeader()
Return true if this CFG node is a LoopPreHeaderChord instance. |
boolean |
isLoopTail()
Return true if this CFG node is a LoopTailChord instance. |
boolean |
isMarker()
Return true if this is a marker CFG node. |
boolean |
isPhiExpr()
Return true if this CFG node is a PhiExprChord instance. |
boolean |
isSequential()
Return true if this is a SequentialChord instance. |
boolean |
isSpecial()
Return true if this is CFG node was added for the convenience of the compiler and does not correspond to actual source code in the user program. |
Chord |
lastInBasicBlock()
Return the last CFG node in this basic block. |
abstract void |
linkSubgraph(HashMap<Chord,Chord> nm)
Link a new CFG node that contains old links. |
void |
linkTo(Chord child)
Link child to parent if it's a SequentialChord instance and not a BranchChord instance or EndChord instance. |
void |
loopClean()
Eliminate associated loop information. |
abstract void |
markEdge(int edge)
Set the marker associated with the specified out-going CFG edge. |
static void |
nextVisit()
Set up for a new CFG traversal - that is, use the next color value. |
int |
nthIndexOfInCfgEdge(Chord in,
int n)
Return the index of the nth occurrence of the specified in-coming CFG edge. |
static int |
nullCFGNodes()
Return the current number of null nodes removed. |
int |
numInCfgEdges()
Return the number of in-coming CFG edges. |
int |
numInDataEdges()
Return the number of in-coming data edges. |
int |
numOfInCfgEdge(Chord in)
Return the number of duplicate in-coming CFG edges from the specified node. |
abstract int |
numOutCfgEdges()
Return the number of out-going CFG edges. |
boolean |
parentsFinished(HashSet<Chord> finished)
Return true if all predecessor CFG nodes are in the finished set. |
boolean |
parentsVisited()
Return true if the parents of this CFG node have been visited. |
void |
pushAllInCfgEdges(Stack<Chord> wl)
Add the predecessors of this CFG node to the stack. |
abstract void |
pushAllOutCfgEdges(Stack<Chord> wl)
Add the successors of this CFG node to the stack. |
void |
pushChordWhenReady(Stack<Chord> wl)
Place this CFG node on the stack when all its predecessor nodes have been visited. |
int |
pushChordWhenReady(Stack<Chord> wl,
int label)
Place this CFG node on the stack when all its predecessor nodes have been visited. |
void |
pushInCfgEdges(Stack<Chord> wl)
Add the predecessors of this CFG node to the stack if they haven't been visited before. |
void |
pushInCfgEdges(Stack<Chord> wl,
HashSet<Chord> done)
Add the predecessors of this CFG node to the stack if they haven't been visited before. |
void |
pushInDataEdges(Stack<Expr> wl)
Push all incoming data edges on the stack. |
abstract void |
pushOutCfgEdges(Stack<Chord> wl)
Add the successors of this CFG node to the stack if they haven't been visited before. |
abstract void |
pushOutCfgEdges(Stack<Chord> wl,
HashSet<Chord> done)
Add the successors of this CFG node to the stack if they haven't been visited before. |
abstract void |
pushSortedOutCfgEdges(Stack<Chord> wl)
Add the successors of this CFG node to the stack if they haven't been visited, and all their parents have. |
abstract void |
pushSortedOutCfgEdges(Stack<Chord> wl,
HashSet<Chord> finished)
Add the successors of this CFG node to the stack if they haven't been visited, and all their parents have. |
void |
recordRefs(References refs)
Record any variable references in this CFG node in the table of references. |
static void |
removeDeadCode(Stack<Chord> chords)
Remove any CFG nodes that do not have an incoming CFG edge and any un-needed nodes from the CFG. |
boolean |
removeDualExprs()
Remove all DualExpr instances
from the CFG. |
void |
removeFromCfg()
Remove myself from the CFG. |
void |
removeRefs(References refs)
Remove any variable references in this CFG node from the table of references. |
abstract void |
removeUseDef()
Remove any use - def links, may - use links, etc. |
void |
reorderInCfgEdgesOfCopy(HashMap<Chord,Chord> nm)
Reorder the incoming CFG edges of a new CFG node to match the order of the in-coming edges of the this CFG node. |
abstract boolean |
replaceDecl(Declaration oldDecl,
Declaration newDecl)
Replace all occurrances of a Declaration with another declaration. |
void |
replaceInCfgEdge(Chord oldChord,
Chord newChord)
Replace the existing in-coming CFG edge with a new edge. |
abstract void |
replaceOutCfgEdge(Chord oldChord,
Chord newChord)
Replace the existing out-going CFG edge with a new edge. |
void |
setLabel(int label)
Associate an integer value with a CFG node. |
void |
setSourceLineNumber(int lineNumber)
Set the source line number associated with this node. |
void |
setVisited()
Associate the current color value with a CFG node. |
java.lang.String |
toStringSpecial()
Return a String containing additional information
about this CFG node. |
void |
unlinkChord()
Break any un-needed links from a CFG node that is being deleted. |
boolean |
visited()
Return true if this CFG node has been visited during the current visit (i.e., is the current color). |
Methods inherited from class scale.score.Note |
---|
executionCostEstimate, getChord, getEssentialUse, setAnnotationLevel, setReportLevel, toString, validate, visit |
Methods inherited from class scale.common.Root |
---|
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, hashCode, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, trace, trace, trace |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected int lineNumber
Constructor Detail |
---|
protected Chord()
Method Detail |
---|
public static int deletedCFGNodes()
public static int deadCFGNodes()
public static int nullCFGNodes()
null nodes
removed.
public static int gotoCFGNodes()
GotoChord
nodes removed.
public static void nextVisit()
setVisited()
,
visited()
,
nextVisit()
,
pushOutCfgEdges(scale.common.Stack)
,
pushInCfgEdges(scale.common.Stack)
public final void setLabel(int label)
Domination
class uses it in computing dominators.
public final int getLabel()
public boolean isSequential()
SequentialChord
instance.
public boolean isBranch()
public boolean isLoopHeader()
LoopHeaderChord
instance.
public boolean isLoopPreHeader()
LoopPreHeaderChord
instance.
public boolean isLoopExit()
LoopExitChord
instance.
public boolean isLoopTail()
LoopTailChord
instance.
public boolean isPhiExpr()
PhiExprChord
instance.
public boolean isSpecial()
public boolean isMarker()
public boolean isExprChord()
ExprChord
instance.
public final void setVisited()
nextVisit()
,
visited()
,
pushOutCfgEdges(scale.common.Stack)
,
pushInCfgEdges(scale.common.Stack)
public final boolean visited()
nextVisit()
,
setVisited()
,
pushOutCfgEdges(scale.common.Stack)
,
pushInCfgEdges(scale.common.Stack)
public boolean parentsVisited()
public boolean parentsFinished(HashSet<Chord> finished)
finished
- is the set to test.public abstract void pushAllOutCfgEdges(Stack<Chord> wl)
public abstract void pushOutCfgEdges(Stack<Chord> wl)
nextVisit()
,
setVisited()
,
visited()
public abstract void pushOutCfgEdges(Stack<Chord> wl, HashSet<Chord> done)
done
- is the set of visited CFG nodespublic abstract void pushSortedOutCfgEdges(Stack<Chord> wl)
public abstract void pushSortedOutCfgEdges(Stack<Chord> wl, HashSet<Chord> finished)
finished
- is the set of finished nodes.public final void pushInCfgEdges(Stack<Chord> wl)
nextVisit()
,
setVisited()
,
visited()
public final void pushInCfgEdges(Stack<Chord> wl, HashSet<Chord> done)
done
- is the set of visited CFG nodespublic final void pushAllInCfgEdges(Stack<Chord> wl)
public final int pushChordWhenReady(Stack<Chord> wl, int label)
LoopHeaderChord.labelCFGLoopOrder()
.
Scribble.labelCFG()
public final void pushChordWhenReady(Stack<Chord> wl)
Scribble.linearize(scale.common.Vector)
public java.lang.String getDisplayLabel()
String
suitable for labeling this node in a
graphical display. This method should be over-ridden as it
simplay returns the class name.
getDisplayLabel
in interface DisplayNode
getDisplayLabel
in class Root
public DColor getDisplayColorHint()
String
specifying the color to use for
coloring this node in a graphical display. This method should be
over-ridden as it simplay returns the color lightblue.
getDisplayColorHint
in interface DisplayNode
getDisplayColorHint
in class Root
DColor
public DShape getDisplayShapeHint()
String
specifying a shape to use when
drawing this node in a graphical display. This method should be
over-ridden as it simplay returns the shape "ellipse".
getDisplayShapeHint
in interface DisplayNode
getDisplayShapeHint
in class Root
DShape
public abstract Chord copy()
public final void removeFromCfg()
Each node in the CFG has a link back to the nodes that point to
it. When a node is removed using removeFromCfg ()
, the nodes that point to the node being removed
are changed to point to the successor of the node being removed.
It can't do this if there is more than one successor. It this
way, the node is removed but the CFG graph remains valid.
The expungeFromCfg()
method does not link
the parent nodes to the successor node. It breaks the CFG graph.
It is up to the calling method to insure that the CFG graph is
valid.
expungeFromCfg()
public void unlinkChord()
public final void extractFromCfg()
Each node in the CFG has a link back to the nodes that point to
it. When a node is removed using removeFromCfg()
, the nodes that point to the node being removed
are changed to point to the successor of the node being removed.
It can't do this if there is more than one successor. It this
way, the node is removed but the CFG graph remains valid.
The <expungeFromCfg()
method does not
link the parent nodes to the successor node. It breaks the CFG
graph. It is up to the calling method to insure that the CFG
graph is valid.
expungeFromCfg()
public static void removeDeadCode(Stack<Chord> chords)
NullChord
and GotoChord
nodes.
chords
- a list of all statement nodes to be checked.public abstract void replaceOutCfgEdge(Chord oldChord, Chord newChord)
oldChord
- is the old edgenewChord
- is the new edgepublic final void replaceInCfgEdge(Chord oldChord, Chord newChord)
oldChord
- is the old edgenewChord
- is the new edgepublic final void expungeFromCfg()
removeFromCfg()
public final void insertBeforeInCfg(SequentialChord newChord)
newChord
- the node to be inserted.public void linkTo(Chord child)
SequentialChord
instance and not a BranchChord
instance or EndChord
instance.
public final void insertAfterOutCfg(Chord newChord, Chord outEdge)
newChord
- the node to be inserted.outEdge
- is my out-going CFG edgepublic void addInCfgEdge(Chord node)
node
- CFG node which is pointing to mepublic final void deleteInCfgEdge(Chord node)
node
- specifies the in-coming CFG edgepublic final Chord[] getInCfgEdgeArray()
public final Chord getInCfgEdge()
null
.
public final Chord getFirstInCfgEdge()
null
is returned.
public final Chord getInCfgEdge(int i)
public final int numInCfgEdges()
public final int indexOfInCfgEdge(Chord in)
public final int nthIndexOfInCfgEdge(Chord in, int n)
public int numOfInCfgEdge(Chord in)
public final void changeParentOutCfgEdge(Chord newEdge)
public final Chord firstInBasicBlock()
isFirstInBasicBlock()
,
isLastInBasicBlock()
,
lastInBasicBlock()
public final boolean isFirstInBasicBlock()
firstInBasicBlock()
,
isLastInBasicBlock()
,
lastInBasicBlock()
public abstract boolean isLastInBasicBlock()
lastInBasicBlock()
,
isFirstInBasicBlock()
,
firstInBasicBlock()
public final Chord lastInBasicBlock()
isLastInBasicBlock()
,
isFirstInBasicBlock()
,
firstInBasicBlock()
public abstract Chord getNextChord()
public abstract int numOutCfgEdges()
public abstract Chord getOutCfgEdge(int i)
public abstract Chord[] getOutCfgEdgeArray()
public abstract void changeOutCfgEdge(Chord oldEdge, Chord newEdge)
oldEdge
- the out-going CFG edge to be changednewEdge
- the new out-going CFG edgepublic Expr[] getInDataEdgeArray()
getInDataEdgeArray
in class Note
public Expr getInDataEdge(int i)
getInDataEdge
in class Note
public int numInDataEdges()
numInDataEdges
in class Note
public void pushInDataEdges(Stack<Expr> wl)
public void changeInDataEdge(Expr oldExpr, Expr newExpr)
This method ensures that the node previously pointing to this one is updated properly, as well as the node which will now point to this node.
Expr
instances and CFG nodes have a
fixed number of incoming data edges with specific meaning applied
to each.
changeInDataEdge
in class Note
oldExpr
- is the expression to be replacednewExpr
- is the new expressionpublic abstract int indexOfOutCfgEdge(Chord to, int skip)
to
- is the target CFG nodeskip
- ispecifies how many occurrances of to
to skip
public abstract void deleteInDataEdges()
public abstract void deleteOutCfgEdges()
public abstract void clearEdgeMarkers()
public abstract boolean edgeMarked(int edge)
edge
- specifies the edge associated with the marker
public abstract void markEdge(int edge)
edge
- specifies the edge associated with the markerpublic abstract void clearEdge(int edge)
edge
- specifies the edge associated with the markerpublic Expr getDefExpr()
Expr
instance
that specifies the variable.
null
or a Expr
instance that defines a variablepublic final int getSourceLineNumber()
public final void setSourceLineNumber(int lineNumber)
public void copySourceLine(Chord from)
public int executionOrder(Chord n)
NOTE - this method will not perform correctly if the Chords have not been labeled.
n
- the node to compare against.
Scribble.labelCFG()
public LoopHeaderChord getLoopHeader()
LoopHeaderChord
object for the
loop that contains this node. The method will return a
null
if the CFG node is not connected.
For LoopInitChord
and LoopPreHeaderChord
instances, this method
returns the loop header for the loop that they are in - not the
loop header for which they are the initial nodes.
public LoopHeaderChord getLoopHeader(int limit)
LoopHeaderChord
object for the
loop that contains this node. The method will return a
null
if the CFG node is not connected.
For LoopInitChord
and LoopPreHeaderChord
instances, this method
returns the loop header for the loop that they are in - not the
loop header for which they are the initial nodes.
limit
- is a limit on how many nodes are checked before we give uppublic int getLoopNumber()
public Vector<PhiExprChord> findPhiChords()
phi chords
in
the basic block starting at this node.
public void loopClean()
public boolean isAssignChord()
public final boolean inBasicBlock(Chord first)
public LoopExitChord findLoopExit(LoopHeaderChord header)
LoopExitChord
instance, for the
specified loop, that is reachable from this CFG node. Return
null
if none is found.
public CallExpr getCall(boolean ignorePure)
null
if none.
ignorePure
- is true if pure function calls are to be ignored.public abstract Vector<Declaration> getDeclList()
declarations
referenced in this CFG node or null
.
public abstract Vector<LoadExpr> getLoadExprList()
LoadExpr
instances in this CFG node or null
.
public abstract Vector<Expr> getExprList()
Expr
instances in this CFG node or null
.
public abstract boolean replaceDecl(Declaration oldDecl, Declaration newDecl)
Declaration
with another declaration. Return true if a replace
occurred.
public abstract void removeUseDef()
public abstract void linkSubgraph(HashMap<Chord,Chord> nm)
nm
- is a map from the old nodes to the new nodes.Scribble.linkSubgraph(scale.common.Vector, scale.common.HashMap, scale.common.Vector)
public void reorderInCfgEdgesOfCopy(HashMap<Chord,Chord> nm)
nm
- is the mapping from old nodes to new nodesScribble.linkSubgraph(scale.common.Vector, scale.common.HashMap, scale.common.Vector)
public void recordRefs(References refs)
references
in this CFG node in the table of references.
public void removeRefs(References refs)
references
in this CFG node from the table of references.
public boolean removeDualExprs()
DualExpr
instances
from the CFG. Use the lower form. This eliminates references to
variables that may no longer be needed.
public java.lang.String toStringSpecial()
String
containing additional information
about this CFG node.
toStringSpecial
in class Root
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |