scale.score.chords
Class ExprChord

java.lang.Object
  extended by scale.common.Root
      extended by scale.score.Note
          extended by scale.score.chords.Chord
              extended by scale.score.chords.SequentialChord
                  extended by scale.score.chords.ExprChord
All Implemented Interfaces:
AnnotationInterface, DisplayNode
Direct Known Subclasses:
ExitChord, PhiExprChord

public class ExprChord
extends SequentialChord

This class is used to represent an assignment operation in a CFG. The value may be assigned to the bit-bucket.

$Id: ExprChord.java,v 1.66 2007-10-17 13:39:58 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

If the left-hand-side of the ExprChord instance is not null it is always an expression that evaluates to an address. It is usually a LoadDeclAddressExpr instance but may be a LoadDeclValueExpr instance.


Field Summary
 
Fields inherited from class scale.score.chords.Chord
lineNumber
 
Constructor Summary
ExprChord(Expr rhs)
          Create a node that holds a computation.
ExprChord(Expr rhs, Chord next)
          Create a node that holds a computation.
ExprChord(Expr lhs, Expr rhs)
          Create a node that holds a computation.
ExprChord(Expr lhs, Expr rhs, Chord next)
          Create a node that holds a computation.
ExprChord(Expr lhs, Expr rhs, Expr predicate, boolean onTrue)
          Create a node that holds a computation.
 
Method Summary
 void addDefUse(LoadExpr expr)
          Add a new link from the definition to the use.
 void addMayDef(MayDef mayDef)
          Add may definition information to the store.
 void changeInDataEdge(Expr oldExpr, Expr newExpr)
          This method changes an incoming data edge to point to a new expression.
 boolean checkDefUse(Expr use)
          Return true is a def-use link exists.
 Chord copy()
          Make a copy of this CFG node with the same out-going CFG edges.
 void deleteInDataEdges()
          Remove all the in-coming data edges.
 int executionCostEstimate()
          Return a relative cost estimate for executing this CFG node.
 CallExpr getCall(boolean ignorePure)
          Return the call expression or null if none.
 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.
 LoadExpr getDefUse(int i)
          Return the i-th def-use link.
 LoadExpr[] getDefUseArray()
          Return an array of the use-def links.
 Vector<Expr> getExprList()
          Return a vector of all Expr instances in this CFG node or null.
 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.
 Vector<LoadExpr> getLoadExprList()
          Return a vector of all LoadExpr instances in this CFG node or null.
 Expr getLValue()
          Return the lvalue if this node holds an expression that is an assignment statement or null.
 MayDef getMayDef()
          Return the may definition info assciated with the store.
 Expr getPredicate()
          Return the predicate expression or null if the store is not predicated.
 Expr getRValue()
          Return the rvalue or null.
 boolean isAssignChord()
          Return true if this node holds an expression that represent an assignment statement.
 boolean isDefined(Expr lv)
          The expression is a defined if it is on the left hand side of the store expression.
 boolean isExprChord()
          Return true if this is an expression chord.
 boolean isVaCopy()
          Is this store as a special case - va_copy()?
 int numDefUseLinks()
          Return the number of def-use links.
 int numInDataEdges()
          Return the number of in-coming data edges.
 boolean predicatedOnTrue()
          Return true if the store is enabled when the predicate value is non-zero.
 void printDefUse()
          Display the def-use links.
 void pushInDataEdges(Stack<Expr> wl)
          Push all incoming data edges on the stack.
 void recordRefs(References refs)
          Record any variable references in this CFG node from the table of references.
 void removeDefUse(LoadExpr expr)
          Remove an existing link from the definition to the use.
 boolean removeDualExprs()
          Remove all DualExpr instances from this CFG node.
 Expr removePredication()
          Change this predicated store into a normal store.
 void removeRefs(References refs)
          Remove any variable references in this CFG node in the table of references.
 void removeUseDef()
          Remove any information such as use - def links, may use links, etc.
 boolean replaceDecl(Declaration oldDecl, Declaration newDecl)
          Replace all occurrances of a Declaration with another Declaration.
 void setLValue(Expr lhs)
          Set the lvalue.
 void setRValue(Expr rhs)
          Set the rvalue.
 void setVaCopy()
          Mark this store as a special case - va_copy().
 int sideEffects()
          Return an indication of the side effects execution of this CFG node may cause.
 Expr singleDefUse()
          Return the single def-use link or null if there are more than one or none.
 void specifyPredicate(Expr predicate, boolean onTrue)
          Specify predicate for this operation.
 java.lang.String toStringSpecial()
          Return a String containing additional information about this class instance.
 void validate()
          Check this node for validity.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.score.chords.SequentialChord
changeOutCfgEdge, clearEdge, clearEdgeMarkers, deleteOutCfgEdges, edgeMarked, getNextChord, getOutCfgEdge, getOutCfgEdgeArray, getTarget, indexOfOutCfgEdge, isLastInBasicBlock, isSequential, linkSubgraph, linkTo, markEdge, numOutCfgEdges, pushAllOutCfgEdges, pushOutCfgEdges, pushOutCfgEdges, pushSortedOutCfgEdges, pushSortedOutCfgEdges, replaceOutCfgEdge, setTarget, setTargetUnsafe
 
Methods inherited from class scale.score.chords.Chord
addInCfgEdge, changeParentOutCfgEdge, copySourceLine, deadCFGNodes, deletedCFGNodes, deleteInCfgEdge, executionOrder, expungeFromCfg, extractFromCfg, findLoopExit, findPhiChords, firstInBasicBlock, getDisplayColorHint, getDisplayLabel, getDisplayShapeHint, getFirstInCfgEdge, getInCfgEdge, getInCfgEdge, getInCfgEdgeArray, getLabel, getLoopHeader, getLoopHeader, getLoopNumber, getSourceLineNumber, gotoCFGNodes, inBasicBlock, indexOfInCfgEdge, insertAfterOutCfg, insertBeforeInCfg, isBranch, isFirstInBasicBlock, isLoopExit, isLoopHeader, isLoopPreHeader, isLoopTail, isMarker, isPhiExpr, isSpecial, lastInBasicBlock, loopClean, nextVisit, nthIndexOfInCfgEdge, nullCFGNodes, numInCfgEdges, numOfInCfgEdge, parentsFinished, parentsVisited, pushAllInCfgEdges, pushChordWhenReady, pushChordWhenReady, pushInCfgEdges, pushInCfgEdges, removeDeadCode, removeFromCfg, reorderInCfgEdgesOfCopy, replaceInCfgEdge, setLabel, setSourceLineNumber, setVisited, unlinkChord, visited
 
Methods inherited from class scale.score.Note
getChord, getEssentialUse, setAnnotationLevel, setReportLevel, toString
 
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
 

Constructor Detail

ExprChord

public ExprChord(Expr lhs,
                 Expr rhs,
                 Chord next)
Create a node that holds a computation.

Parameters:
lhs - is the target of the assignment or null
rhs - is the source expression for the assignment or null
next - is the out-going CFG edge and may be null

ExprChord

public ExprChord(Expr rhs,
                 Chord next)
Create a node that holds a computation.

Parameters:
rhs - is the source expression or null
next - is the out-going CFG edge and may be null

ExprChord

public ExprChord(Expr rhs)
Create a node that holds a computation.

Parameters:
rhs - is the source expression or null

ExprChord

public ExprChord(Expr lhs,
                 Expr rhs)
Create a node that holds a computation.

Parameters:
lhs - is the target of the assignment or null
rhs - is the source expression for the assignment or null

ExprChord

public ExprChord(Expr lhs,
                 Expr rhs,
                 Expr predicate,
                 boolean onTrue)
Create a node that holds a computation.

Parameters:
lhs - is the target of the assignment or null
rhs - is the source expression for the assignment or null
predicate - pecifies the predicate expression
onTrue - is true if the operation is enabled if onTrue is true and the predicate value is non-zero or onTrue is false and the predicate value is zero
Method Detail

isExprChord

public final boolean isExprChord()
Return true if this is an expression chord.

Overrides:
isExprChord in class Chord

getInDataEdgeArray

public final 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.

Overrides:
getInDataEdgeArray in class Chord
Returns:
an array of in-coming data edges.

deleteInDataEdges

public final void deleteInDataEdges()
Remove all the in-coming data edges.

Overrides:
deleteInDataEdges in class SequentialChord

getInDataEdge

public final Expr getInDataEdge(int i)
Return the specified in-coming data edge.

Overrides:
getInDataEdge in class Chord

numInDataEdges

public final int numInDataEdges()
Return the number of in-coming data edges.

Overrides:
numInDataEdges in class Chord

pushInDataEdges

public void pushInDataEdges(Stack<Expr> wl)
Push all incoming data edges on the stack.

Overrides:
pushInDataEdges in class Chord

copy

public Chord copy()
Description copied from class: Chord
Make a copy of this CFG node with the same out-going CFG edges. The validity of the CFG graph is maintained.

Specified by:
copy in class Chord
Returns:
a copy of this node

toStringSpecial

public java.lang.String toStringSpecial()
Return a String containing additional information about this class instance.

Overrides:
toStringSpecial in class Chord

isAssignChord

public final boolean isAssignChord()
Return true if this node holds an expression that represent an assignment statement.

Overrides:
isAssignChord in class Chord

setLValue

public final void setLValue(Expr lhs)
Set the lvalue.


setRValue

public final void setRValue(Expr rhs)
Set the rvalue.


getLValue

public final Expr getLValue()
Return the lvalue if this node holds an expression that is an assignment statement or null.


getRValue

public final Expr getRValue()
Return the rvalue or null.


changeInDataEdge

public final void changeInDataEdge(Expr oldExpr,
                                   Expr newExpr)
This method changes an incoming data edge to point to a new expression.

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 and Chord nodes have a fixed number of incoming edges with specific meaning applied to each.

Overrides:
changeInDataEdge in class Chord
Parameters:
oldExpr - is the expression to be replaced
newExpr - is the new expression

visit

public void visit(Predicate p)
Description copied from class: Note
Process a node by calling its associated routine. See the "visitor" design pattern in Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma, et al, Addison Wesley, ISBN 0-201-63361-2.

Each class has a visit(Predicate p) method. For example, in class ABC:

   public void visit(Predicate p)
   {
     p.visitABC(this);
   }
 
and the class that implements Predicate has a method
   public void visitABC(Note n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements Predicate can call
   n.visit(this);
 
where n is a Note sub-class without determining which specific sub-class n is. The visit pattern basically avoids implementing a large switch statement or defining different methods in each class for some purpose.

Specified by:
visit in class Note
See Also:
Predicate

getDeclList

public final Vector<Declaration> getDeclList()
Return a vector of all declarations referenced in this CFG node or null.

Overrides:
getDeclList in class SequentialChord

getLoadExprList

public final Vector<LoadExpr> getLoadExprList()
Return a vector of all LoadExpr instances in this CFG node or null.

Overrides:
getLoadExprList in class SequentialChord

getExprList

public final Vector<Expr> getExprList()
Return a vector of all Expr instances in this CFG node or null.

Overrides:
getExprList in class SequentialChord

replaceDecl

public final boolean replaceDecl(Declaration oldDecl,
                                 Declaration newDecl)
Replace all occurrances of a Declaration with another Declaration.

Overrides:
replaceDecl in class SequentialChord
Returns:
true if a replace occurred

getCall

public final CallExpr getCall(boolean ignorePure)
Return the call expression or null if none.

Overrides:
getCall in class Chord
Parameters:
ignorePure - is true if pure function calls are to be ignored.

validate

public void validate()
Check this node for validity. This method throws an error if the node is not linked properly.

Overrides:
validate in class Note

recordRefs

public void recordRefs(References refs)
Record any variable references in this CFG node from the table of references.

Overrides:
recordRefs in class Chord

removeRefs

public void removeRefs(References refs)
Remove any variable references in this CFG node in the table of references.

Overrides:
removeRefs in class Chord

executionCostEstimate

public int executionCostEstimate()
Return a relative cost estimate for executing this CFG node.

Overrides:
executionCostEstimate in class SequentialChord

sideEffects

public int sideEffects()
Return an indication of the side effects execution of this CFG node may cause.

See Also:
Expr.SE_NONE

addDefUse

public final void addDefUse(LoadExpr expr)
Add a new link from the definition to the use. This method DOES NOT update the use to def link in the use.

Parameters:
expr - the new use-def link

removeDefUse

public final void removeDefUse(LoadExpr expr)
Remove an existing link from the definition to the use. This method DOES NOT update the use to def link in the use.

Parameters:
expr - the existing use-def link

singleDefUse

public final Expr singleDefUse()
Return the single def-use link or null if there are more than one or none.


numDefUseLinks

public int numDefUseLinks()
Return the number of def-use links.


getDefUse

public final LoadExpr getDefUse(int i)
Return the i-th def-use link. Use getDefUseArray if the def-use links will be modified while iterating over them.


getDefUseArray

public final LoadExpr[] getDefUseArray()
Return an array of the use-def links.


checkDefUse

public final boolean checkDefUse(Expr use)
Return true is a def-use link exists.


addMayDef

public void addMayDef(MayDef mayDef)
Add may definition information to the store.

Parameters:
mayDef - the may definition info.

getMayDef

public MayDef getMayDef()
Return the may definition info assciated with the store.


removeUseDef

public void removeUseDef()
Remove any information such as use - def links, may use links, etc.

Overrides:
removeUseDef in class SequentialChord

isDefined

public boolean isDefined(Expr lv)
The expression is a defined if it is on the left hand side of the store expression.

Parameters:
lv - the expression we're checking
Returns:
true if lv is an lvalue, otherwise return false

getDefExpr

public Expr getDefExpr()
If this CFG node results in a variable being given a new value, return the Expr instance that specifies the variable.

Overrides:
getDefExpr in class Chord
Returns:
a null or a LoadExpr that defines a variable

printDefUse

public void printDefUse()
Display the def-use links.


getPredicate

public final Expr getPredicate()
Return the predicate expression or null if the store is not predicated.


removePredication

public final Expr removePredication()
Change this predicated store into a normal store.


specifyPredicate

public final void specifyPredicate(Expr predicate,
                                   boolean onTrue)
Specify predicate for this operation.


predicatedOnTrue

public final boolean predicatedOnTrue()
Return true if the store is enabled when the predicate value is non-zero. Return false if the store is enabled when the predicate value is zero.


setVaCopy

public final void setVaCopy()
Mark this store as a special case - va_copy().


isVaCopy

public final boolean isVaCopy()
Is this store as a special case - va_copy()?


removeDualExprs

public boolean removeDualExprs()
Remove all DualExpr instances from this CFG node. Use the lower form. This eliminates references to variables that may no longer be needed.

Overrides:
removeDualExprs in class Chord