|
|||||||||
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.expr.Expr
public abstract class Expr
The base class for Score expression classes.
$Id: Expr.java,v 1.160 2007-10-17 13:40:00 burrill Exp $
Copyright 2008 by the
Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.
All expression instances have an associated type.
An expression instance is an operation plus some number of
arguments. Each argument is an expression instance as well. The
value of an expression may propagate to another expression (as one
of its operands) or to a CFG node (e.g., ExprChord
instance).
An expression instance has a fixed number of incoming data edges (i.e., its operands) and one outgoing data edge.
As modeled by this class, an expression has some number of operands
which are represented as incoming data edges, and a value which is
represented as the outgoing data edge. Some expression classes
have extra information which is not an operand. This information
is sometimes properly part of the operator (e.g., the type of
conversion for ConversionExpr
instances), and sometimes it is not even that
(e.g., the value of a literal). This extra information is in some
sense not part of the CFG (i.e., these are non-graph edges).
Since an expression may have only one outgoing data edges an expression instance is not unique in that there may be other instances that are equivalent (identical in a loose sense). The copy() method is provided so that an equivalent expression instance may be created from an exisiting expression instance. Attempting to link in an expression instance that is already linked into the CFG results in a scale.common.InternalError exception.
Memory references are defined by instances of the LoadExpr
abstract class and the LoadValueIndirectExpr
class.
LoadDeclAddressExpr
instance on the right-hand-side never
references memory - it evaluates to an address.
LoadDeclValueExpr
instance always causes a memory reference (or register copy).
LoadValueIndirectExpr
instance always causes a memory reference.
Field Summary | |
---|---|
static boolean |
fpReorder
True if floating point operations may be reordered. |
static int |
SE_DOMAIN
Side effect - may cause fault because of domain values. |
static int |
SE_NONE
Side effect - none. |
static int |
SE_OVERFLOW
Side effect - may cause overflow or underflow fault. |
static int |
SE_STATE
Side effect - changes some global state (e.g., memory location) |
Constructor Summary | |
---|---|
protected |
Expr()
|
protected |
Expr(Type type)
Build an expression node. |
Method Summary | |
---|---|
Expr |
addCast(Expr orig)
Add a cast of an address if required. |
Expr |
addCast(Type orig)
Add a cast of an address if required. |
long |
canonical()
Return a unique value representing this particular expression. |
void |
changeInDataEdge(Expr oldExpr,
Expr newExpr)
This method changes an incoming data edge to point to a new expression. |
Expr |
conditionalCopy()
Return a deep copy of the expression tree if this expression is used. |
void |
conditionalUnlinkExpression()
If the node is no longer needed, sever its use-def link, etc. |
boolean |
containsDeclaration(Declaration decl)
Return true if this expression contains a reference to the variable. |
abstract Expr |
copy()
Perform a deep copy of the expression tree. |
void |
deleteOutDataEdge(Note node)
This method deletes the outgoing data edge. |
boolean |
dependsOnDeclaration(Declaration decl)
Return true if this expression's value depends on the variable. |
boolean |
equivalent(Expr exp)
Return true if the expressions are equivalent. |
int |
executionOrder(Expr n)
Determine the execution ordering of the two nodes. |
int |
executionOrdinal()
Return the "execution ordinal" of this expression. |
protected Chord |
findCriticalChord(HashMap<Expr,Chord> lMap,
Chord independent)
Return the Chord with the highest label value from the set of Chords that must be executed before this expression. |
int |
findLinearCoefficient(VariableDecl indexVar,
LoopHeaderChord thisLoop)
Return the coefficient of a linear expression. |
SubscriptExpr |
findSubscriptExpr()
Return the SubscriptExpr that this load
uses or null if none is found. |
AffineExpr |
getAffineExpr(HashMap<Expr,AffineExpr> affines,
LoopHeaderChord thisLoop)
Return the affine
representation for this expression or null if it is
not affine. |
protected AffineExpr |
getAffineRepresentation(HashMap<Expr,AffineExpr> affines,
LoopHeaderChord thisLoop)
Return the affine
representation for this expression. |
AliasAnnote |
getAliasAnnote()
Get the alias annotation associated with a Scribble operator. |
CallExpr |
getCall(boolean ignorePure)
Return the call expression or null if none. |
Literal |
getConstantValue()
Return the constant value of the expression. |
Literal |
getConstantValue(HashMap<Expr,Literal> cvMap)
Return the constant value of the expression. |
Type |
getCoreType()
Return the core type of the expression. |
Chord |
getCriticalChord(HashMap<Expr,Chord> lMap,
Chord independent)
Return the Chord with the highest label value from the set of Chords that must be executed before this expression. |
abstract void |
getDeclList(java.util.AbstractCollection<Declaration> varList)
Add all declarations referenced in this expression to the Vector. |
Expr |
getDefExpr()
If this expression results in a variable being given a new value, return the LoadExpr 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. |
DualExpr |
getDualExpr()
Return the DualExpr containing this SubscriptExpr or null if none. |
abstract void |
getExprList(Vector<Expr> expList)
Add all Expr instances in this expression to the Vector. |
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. |
abstract void |
getLoadExprList(Vector<LoadExpr> expList)
Add all LoadExpr instances in this expression to
the Vector. |
LoopHeaderChord |
getLoopHeader()
Return the node which represents the loop that contains this node. |
Expr |
getLow()
Return the low-level representation. |
Expr |
getLValue()
Return the lvalue if this statement is an assignment statement. |
Expr |
getOperand(int position)
Return the specified operand. |
abstract Expr[] |
getOperandArray()
Return an array of the operands to the expression. |
Note |
getOutDataEdge()
Return the out-going data edge. |
Type |
getPointedToCore()
Return the type of the thing pointed to by the type of the expression. |
Expr |
getReference()
Return the variable reference for the expression. |
int |
getReuseLevel()
|
Expr |
getRValue()
Return the rvalue if this statement is an assignment statement. |
Type |
getType()
Return the type of the expression. |
ExprChord |
getUseDef()
Return the use-def link for the expression. |
boolean |
hasTrueFalseResult()
Return true if the result of the expression is either true (1) or false (0). |
boolean |
isCast()
Return true if this expression is a cast of an address. |
boolean |
isDefined()
This method determines if this expression's value is defined or used by the expression. |
boolean |
isDefined(Expr lv)
Check if the given expression is defined by this expression. |
boolean |
isLiteralExpr()
Return true if this is a literal expression. |
boolean |
isLoopInvariant(LoopHeaderChord loop)
Return true if this expression is loop invariant. |
boolean |
isMatchExpr()
Return true if this is a match expression. |
boolean |
isMemoryDef()
Return true if the node reference is a definition. |
boolean |
isMemRefExpr()
Return true if the expression loads a value from memory. |
boolean |
isScalar()
Return true if this expression represents an operation that uses scalar types. |
boolean |
isSimpleExpr()
Return true if this is a simple expression. |
void |
loopClean()
Clean up any loop related information. |
boolean |
mayGenerateCall()
Return true if this expression may result in the generation of a call to a subroutine. |
int |
numInDataEdges()
Return the number of in-coming data edges. |
abstract int |
numOperands()
Return the number of operands to this expression. |
abstract boolean |
optimizationCandidate()
Return true if the expression can be moved without problems. |
abstract void |
pushOperands(Stack<Expr> wl)
Push all of the operands of this expression on the Stack. |
abstract void |
recordRefs(Chord stmt,
References refs)
Record any variable references in this expression in the table of references. |
Expr |
reduce()
Return a simplied equivalent expression. |
boolean |
removeDualExprs()
Remove occurances of DualExpr instances. |
abstract void |
removeRefs(Chord stmt,
References refs)
Remove any variable references in this expression from the table of references. |
abstract void |
removeUseDef()
Remove any use - def links, may - use links, etc. |
abstract boolean |
replaceDecl(Declaration oldDecl,
Declaration newDecl)
Replace all occurrances of a Declaration with another Declaration. |
void |
setCrossloopReuse(int level)
|
protected Expr |
setOperand(Expr operand,
int position)
Set the nth operand of an expression. |
void |
setOutDataEdge(Note node)
This method adds an outgoing data edge to this node. |
void |
setSpatialReuse(int level)
|
void |
setStep(int step)
|
void |
setTemporalReuse(int level)
|
void |
setType(Type type)
Set the type of the expression. |
void |
setUseDef(ExprChord se)
Set the use-def link for the expression. |
abstract int |
sideEffects()
Return an indication of the side effects execution of this expression may cause. |
java.lang.String |
toStringSpecial()
Return any special information of a node that is not a child or annotation. |
void |
unlinkExpression()
This node is no longer needed so sever its use-def link, etc. |
void |
validate()
Check this node for validity. |
boolean |
validLValue()
Return true if this expression is valid on the left side of an assignment. |
Methods inherited from class scale.score.Note |
---|
executionCostEstimate, getChord, getEssentialUse, setAnnotationLevel, setReportLevel, toString, 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 |
---|
public static final int SE_NONE
public static final int SE_OVERFLOW
public static final int SE_DOMAIN
public static final int SE_STATE
public static boolean fpReorder
Constructor Detail |
---|
protected Expr(Type type)
type
- is the type of the value that results from this expression.protected Expr()
Method Detail |
---|
public abstract int sideEffects()
SE_NONE
public boolean equivalent(Expr exp)
public java.lang.String getDisplayLabel()
getDisplayLabel
in interface DisplayNode
getDisplayLabel
in class Root
public DColor getDisplayColorHint()
getDisplayColorHint
in interface DisplayNode
getDisplayColorHint
in class Root
DColor
public DShape getDisplayShapeHint()
getDisplayShapeHint
in interface DisplayNode
getDisplayShapeHint
in class Root
DShape
public final Type getType()
public final Type getCoreType()
public final Type getPointedToCore()
getCoreType().getPointedTo().getCoreType()
public final void setType(Type type)
type
- is the type of the expressionpublic abstract Expr copy()
public final Expr conditionalCopy()
protected Expr setOperand(Expr operand, int position)
operand
must not be
null
.
operand
- - the new operandposition
- - indicates which operand
public Expr getOperand(int position)
position
- is the index of the operandpublic abstract Expr[] getOperandArray()
public abstract int numOperands()
public final Expr getInDataEdge(int i)
getInDataEdge
in class Note
public final int numInDataEdges()
numInDataEdges
in class Note
public boolean isDefined(Expr lv)
lv
- is the given expression to check.
public boolean isMatchExpr()
public boolean isLiteralExpr()
public boolean isCast()
public boolean isDefined()
public Expr getReference()
public Expr getLValue()
public Expr getRValue()
public Expr getLow()
public final Expr[] getInDataEdgeArray()
getInDataEdgeArray
in class Note
public final Note getOutDataEdge()
public final void setOutDataEdge(Note node)
node
- Note to which this out edge is pointingpublic final 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
and Chord
nodes have a fixed number of incoming edges with specific meaning
applied to each. Hence, the edge being replaced is indicated by
position.
changeInDataEdge
in class Note
oldExpr
- is the expression to be replacednewExpr
- is the new expressionpublic final void deleteOutDataEdge(Note node)
This method is a helper routine. It intended to aid another routine which deletes this edge as an incoming edge. The two methods work together to maintain bi-directional edges.
node
- Indicates edge to be deleted, by designating its opposite end.public java.lang.String toStringSpecial()
Root
toStringSpecial
in class Root
public Literal getConstantValue(HashMap<Expr,Literal> cvMap)
Lattice
public Literal getConstantValue()
Lattice
protected Chord findCriticalChord(HashMap<Expr,Chord> lMap, Chord independent)
lMap
- is used to memoize the expression to critical Chord
informationindependent
- is returned if the expression is not dependent
on anythingpublic final Chord getCriticalChord(HashMap<Expr,Chord> lMap, Chord independent)
lMap
- is used to memoize the expression to critical Chord
informationindependent
- is returned if the expression is not dependent
on anythingpublic boolean isScalar()
public long canonical()
public boolean validLValue()
public abstract void removeUseDef()
public Expr getDefExpr()
LoadExpr
that specifies the variable.
null
or a LoadExpr
that
defines a variablepublic final int executionOrder(Expr n)
0 if this and n are in the same CFG node on the same side of the assignment. 1 if this occurs before n. -1 if n occurs before this.Two nodes are equivalent if we can't determine that one defintely occurs before the other (e.g., in an assignment statement, a[i] = a[i-1], the execution order is not defined. The right hand side of an assignment is considered to precede the left-hand side.
NOTE - this method will not perform correctly if the Chords have not been labeled.
n
- the node to compare against.
Chord.executionOrder(scale.score.chords.Chord)
,
Scribble.labelCFG()
public int executionOrdinal()
o1
and o2
be the execution ordinals of
two expressions e1
and e2
respectively.
Then, o1
is less than o2
iff
e1
is executed before e2
. The right
hand side of an assignment is considered to precede the left-hand
side. Two expressions in the same expression tree will have the
same ordinal.
NOTE - this method will not perform correctly if the Chords have not been labeled.
executionOrder(scale.score.expr.Expr)
,
Chord.executionOrder(scale.score.chords.Chord)
,
Scribble.labelCFG()
public final LoopHeaderChord getLoopHeader()
public boolean isMemoryDef()
public int findLinearCoefficient(VariableDecl indexVar, LoopHeaderChord thisLoop)
public final AffineExpr getAffineExpr(HashMap<Expr,AffineExpr> affines, LoopHeaderChord thisLoop)
affine
representation
for this expression or null
if it is
not affine.
affines
- is a mapping from an expression to its representation
and is used to avoid combinatorial explosion through use-def
linksthisLoop
- the loop for which this expression may be affineAffineExpr
protected AffineExpr getAffineRepresentation(HashMap<Expr,AffineExpr> affines, LoopHeaderChord thisLoop)
affine
representation
for this expression. This method should be
called only from the getAffineExpr()
method. This method never returns null
.
affines
- is a mapping from an expression to its representation
and is used to avoid combinatorial explosion through use-def
linksthisLoop
- the loop for which this expression may be affineAffineExpr
,
AffineExpr.notAffine
public final DualExpr getDualExpr()
DualExpr
containing this SubscriptExpr
or null if none. Follow the use-def
chain if necessary.
public ExprChord getUseDef()
public void setUseDef(ExprChord se)
public boolean isMemRefExpr()
public boolean isSimpleExpr()
public CallExpr getCall(boolean ignorePure)
ignorePure
- is true if pure function calls are to be ignored.public void loopClean()
public void unlinkExpression()
public final void conditionalUnlinkExpression()
public boolean isLoopInvariant(LoopHeaderChord loop)
loop
- is the looppublic boolean mayGenerateCall()
public SubscriptExpr findSubscriptExpr()
SubscriptExpr
that this load
uses or null
if none is found. This method uses the
use-def link to find an existing SubscriptExpr
instance.
public void setTemporalReuse(int level)
public void setCrossloopReuse(int level)
public void setSpatialReuse(int level)
public void setStep(int step)
public int getReuseLevel()
public boolean containsDeclaration(Declaration decl)
LoadExpr.setUseOriginal(boolean)
public boolean dependsOnDeclaration(Declaration decl)
LoadExpr.setUseOriginal(boolean)
public abstract boolean optimizationCandidate()
public AliasAnnote getAliasAnnote()
public abstract void getDeclList(java.util.AbstractCollection<Declaration> varList)
public abstract void getLoadExprList(Vector<LoadExpr> expList)
LoadExpr
instances in this expression to
the Vector.
public abstract void getExprList(Vector<Expr> expList)
Expr
instances in this expression to the Vector.
public abstract void pushOperands(Stack<Expr> wl)
public abstract boolean replaceDecl(Declaration oldDecl, Declaration newDecl)
public abstract void recordRefs(Chord stmt, References refs)
public abstract void removeRefs(Chord stmt, References refs)
public Expr reduce()
SubscriptExpr.lower()
public void validate()
validate
in class Note
public boolean removeDualExprs()
DualExpr
instances.
DualExpr
instance was removed.public final Expr addCast(Expr orig)
orig
- is the expression being replaced
public final Expr addCast(Type orig)
orig
- is the type of the expression being replaced
public boolean hasTrueFalseResult()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |