scale.score.expr
Class LiteralExpr

java.lang.Object
  extended by scale.common.Root
      extended by scale.score.Note
          extended by scale.score.expr.Expr
              extended by scale.score.expr.ValueExpr
                  extended by scale.score.expr.LiteralExpr
All Implemented Interfaces:
AnnotationInterface, DisplayNode

public class LiteralExpr
extends ValueExpr

This class represents the instantiation of a literal in Scribble.

$Id: LiteralExpr.java,v 1.97 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.

This literal can be an aggregation of scalar values, a string, or a scalar value. The literal's actual value is stored in a seperate object.

See Also:
Literal

Field Summary
 
Fields inherited from class scale.score.expr.Expr
fpReorder, SE_DOMAIN, SE_NONE, SE_OVERFLOW, SE_STATE
 
Constructor Summary
LiteralExpr(Literal literal)
          This method builds an expression node with this operation as the operator.
 
Method Summary
 Expr add(Type type, Expr arg)
          Return an expression that represents the addition of this expression to the argument expression.
 long canonical()
          Return a unique value representing this particular expression.
 Expr copy()
          Perform a deep copy of the expression tree.
 Expr divide(Type type, Expr arg)
          Return an expression that represents the division of this expression by the argument expression.
 boolean equivalent(Expr exp)
          Return true if the expressions are equivalent.
 int executionCostEstimate()
          Return a relative cost estimate for executing the 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)
          Determine the coefficent of a linear expression.
protected  AffineExpr getAffineRepresentation(HashMap<Expr,AffineExpr> affines, LoopHeaderChord thisLoop)
          Return the affine representation for this expression.
 Literal getConstantValue()
          Return the constant value of the expression.
 Literal getConstantValue(HashMap<Expr,Literal> cvMap)
          Return the constant value of the expression.
 void getDeclList(java.util.AbstractCollection<Declaration> varList)
          Add all declarations referenced in this expression to the vector.
 java.lang.String getDisplayLabel()
          Return a String suitable for labeling this node in a graphical display.
 Literal getLiteral()
          Return the literal associated with this expression.
 boolean hasTrueFalseResult()
          Return true if the result of the expression is either true (1) or false (0).
 boolean isLiteralExpr()
          Return true if this is a literal expression.
 boolean isLoopInvariant(LoopHeaderChord loop)
          Return true if this expression is loop invariant.
 boolean isOne()
          Return true if the value of this literal is known to be one.
 boolean isSimpleExpr()
          Return true if this is a simple expression.
 boolean isZero()
          Return true if the value of this literal is known to be zero.
 Expr multiply(Type type, Expr arg)
          Return an expression that represents the multiplication of this expression to the argument expression.
 boolean optimizationCandidate()
          Return true if the literal value is an atomic type.
 void recordRefs(Chord stmt, References refs)
          Record any variable references in this expression in the table of references.
 void removeRefs(Chord stmt, References refs)
          Remove any variable references in this expression from the table of references.
 boolean replaceDecl(Declaration oldDecl, Declaration newDecl)
          Replace all occurrances of a declaration with another declaration.
 void setLiteral(Literal literal)
          Set the literal associated with this expression.
 Expr subtract(Type type, Expr arg)
          Return an expression that represents the subtraction of the argument expression from expression.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.score.expr.ValueExpr
getExprList, getLoadExprList, getOperandArray, numOperands, pushOperands, removeUseDef, sideEffects
 
Methods inherited from class scale.score.expr.Expr
addCast, addCast, changeInDataEdge, conditionalCopy, conditionalUnlinkExpression, containsDeclaration, deleteOutDataEdge, dependsOnDeclaration, executionOrder, executionOrdinal, findSubscriptExpr, getAffineExpr, getAliasAnnote, getCall, getCoreType, getCriticalChord, getDefExpr, getDisplayColorHint, getDisplayShapeHint, getDualExpr, getInDataEdge, getInDataEdgeArray, getLoopHeader, getLow, getLValue, getOperand, getOutDataEdge, getPointedToCore, getReference, getReuseLevel, getRValue, getType, getUseDef, isCast, isDefined, isDefined, isMatchExpr, isMemoryDef, isMemRefExpr, isScalar, loopClean, mayGenerateCall, numInDataEdges, reduce, removeDualExprs, setCrossloopReuse, setOperand, setOutDataEdge, setSpatialReuse, setStep, setTemporalReuse, setType, setUseDef, toStringSpecial, unlinkExpression, validate, validLValue
 
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

LiteralExpr

public LiteralExpr(Literal literal)
This method builds an expression node with this operation as the operator.

Method Detail

equivalent

public boolean equivalent(Expr exp)
Return true if the expressions are equivalent. This method should be called by the equivalent() method of the derived classes.

Overrides:
equivalent in class Expr
Returns:
true if the expressions are equivalent

getLiteral

public Literal getLiteral()
Return the literal associated with this expression.


setLiteral

public void setLiteral(Literal literal)
Set the literal associated with this expression.


copy

public Expr copy()
Description copied from class: Expr
Perform a deep copy of the expression tree. By deep copy, we mean that copies are made of the expression tree.

Specified by:
copy in class Expr
Returns:
a copy of this 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

getDisplayLabel

public java.lang.String getDisplayLabel()
Description copied from class: Expr
Return a String suitable for labeling this node in a graphical display. This method should be over-ridden as it simplay returns the class name.

Specified by:
getDisplayLabel in interface DisplayNode
Overrides:
getDisplayLabel in class Expr

getConstantValue

public Literal getConstantValue(HashMap<Expr,Literal> cvMap)
Return the constant value of the expression. Follow use-def links.

Overrides:
getConstantValue in class Expr
See Also:
Lattice

getConstantValue

public Literal getConstantValue()
Return the constant value of the expression. Do not follow use-def links.

Overrides:
getConstantValue in class Expr
See Also:
Lattice

findCriticalChord

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.

Overrides:
findCriticalChord in class Expr
Parameters:
lMap - is used to memoize the expression to critical Chord information
independent - is returned if the expression is not dependent on anything

canonical

public long canonical()
Return a unique value representing this particular expression.

Overrides:
canonical in class Expr

isLoopInvariant

public boolean isLoopInvariant(LoopHeaderChord loop)
Return true if this expression is loop invariant.

Overrides:
isLoopInvariant in class ValueExpr
Parameters:
loop - is the loop

findLinearCoefficient

public int findLinearCoefficient(VariableDecl indexVar,
                                 LoopHeaderChord thisLoop)
Determine the coefficent of a linear expression. Return the coefficient value if the literal is an integer.

Overrides:
findLinearCoefficient in class Expr

getAffineRepresentation

protected AffineExpr getAffineRepresentation(HashMap<Expr,AffineExpr> affines,
                                             LoopHeaderChord thisLoop)
Description copied from class: Expr
Return the affine representation for this expression. This method should be called only from the getAffineExpr() method. This method never returns null.

Overrides:
getAffineRepresentation in class Expr
Parameters:
affines - is a mapping from an expression to its representation and is used to avoid combinatorial explosion through use-def links
thisLoop - the loop for which this expression may be affine
See Also:
AffineExpr, AffineExpr.notAffine

optimizationCandidate

public boolean optimizationCandidate()
Return true if the literal value is an atomic type.

Specified by:
optimizationCandidate in class Expr

executionCostEstimate

public int executionCostEstimate()
Return a relative cost estimate for executing the expression.

Specified by:
executionCostEstimate in class Note

getDeclList

public void getDeclList(java.util.AbstractCollection<Declaration> varList)
Add all declarations referenced in this expression to the vector.

Overrides:
getDeclList in class ValueExpr

replaceDecl

public boolean replaceDecl(Declaration oldDecl,
                           Declaration newDecl)
Replace all occurrances of a declaration with another declaration. Return true if a replace occurred.

Overrides:
replaceDecl in class ValueExpr
Returns:
true if a replace occurred.

recordRefs

public void recordRefs(Chord stmt,
                       References refs)
Record any variable references in this expression in the table of references.

Overrides:
recordRefs in class ValueExpr

removeRefs

public void removeRefs(Chord stmt,
                       References refs)
Remove any variable references in this expression from the table of references.

Overrides:
removeRefs in class ValueExpr

add

public Expr add(Type type,
                Expr arg)
Return an expression that represents the addition of this expression to the argument expression. This is used in the lowering of subscript expressions.

See Also:
SubscriptExpr.lower()

subtract

public Expr subtract(Type type,
                     Expr arg)
Return an expression that represents the subtraction of the argument expression from expression. This is used in the lowering of subscript expressions.

See Also:
SubscriptExpr.lower()

multiply

public Expr multiply(Type type,
                     Expr arg)
Return an expression that represents the multiplication of this expression to the argument expression. This is used in the lowering of subscript expressions.

See Also:
SubscriptExpr.lower()

divide

public Expr divide(Type type,
                   Expr arg)
Return an expression that represents the division of this expression by the argument expression. This is used in the lowering of subscript expressions.

See Also:
SubscriptExpr.lower()

isZero

public boolean isZero()
Return true if the value of this literal is known to be zero.


isOne

public boolean isOne()
Return true if the value of this literal is known to be one.


isSimpleExpr

public boolean isSimpleExpr()
Return true if this is a simple expression. A simple expression consists solely of local scalar variables, constants, and numeric operations such as add, subtract, multiply, and divide.

Overrides:
isSimpleExpr in class Expr

isLiteralExpr

public boolean isLiteralExpr()
Return true if this is a literal expression.

Overrides:
isLiteralExpr in class Expr

hasTrueFalseResult

public boolean hasTrueFalseResult()
Return true if the result of the expression is either true (1) or false (0).

Overrides:
hasTrueFalseResult in class Expr