scale.score.expr
Class BinaryExpr

java.lang.Object
  extended by scale.common.Root
      extended by scale.score.Note
          extended by scale.score.expr.Expr
              extended by scale.score.expr.BinaryExpr
All Implemented Interfaces:
AnnotationInterface, DisplayNode
Direct Known Subclasses:
AdditionExpr, AndExpr, BitAndExpr, BitOrExpr, BitShiftExpr, BitXorExpr, CompareExpr, ComplexValueExpr, DivisionExpr, ExponentiationExpr, MatchExpr, MaxExpr, MinExpr, MultiplicationExpr, OrExpr, RemainderExpr, SubtractionExpr, Transcendental2Expr

public abstract class BinaryExpr
extends Expr

This class is the superclass of all binary operators.

$Id: BinaryExpr.java,v 1.63 2007-10-17 13:39:59 burrill Exp $

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


Field Summary
 
Fields inherited from class scale.score.expr.Expr
fpReorder, SE_DOMAIN, SE_NONE, SE_OVERFLOW, SE_STATE
 
Constructor Summary
BinaryExpr(Type t, Expr la, Expr ra)
           
 
Method Summary
 void associativeSwapOperands()
          See if the associative property of the expression can be used to make two constants the arguments of the same binary expression.
 boolean containsDeclaration(Declaration decl)
          Return true if this expression contains a reference to the variable.
 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 executionCostEstimate()
          Return a relative cost estimate for executing the expression.
 AliasAnnote getAliasAnnote()
          Get the alias annotation associated with a Scribble operator.
 void getDeclList(java.util.AbstractCollection<Declaration> varList)
          Add all declarations referenced in this expression to the Vector.
 void getExprList(Vector<Expr> expList)
          Add all Expr instances in this expression to the Vector.
 Expr getLeftArg()
          Return the left argument to the operator.
 void getLoadExprList(Vector<LoadExpr> expList)
          Add all LoadExpr instances in this expression to the Vector.
 Expr getOperand(int position)
          Return the nth operand.
 Expr[] getOperandArray()
          Return an array of the operands to the expression.
 Expr getRightArg()
          Return the right argument to the operator.
 boolean isAssociative()
          Return true if the binary operation is associative: (a α b) α c ≡ a α (b α c).
 boolean isCommutative()
          Return true if the binary operation is commutative: (a α b) ≡ (b &alpha a).
 boolean isLeftDistributive()
          Return true if the binary operation α is left distributive over β: (a β b) α c ≡ (a α c) β (b α c).
 boolean isRightDistributive()
          Return true if the binary operation α is right distributive over β: a α (b β c) ≡ (a α b) β (a α c).
 void loopClean()
          Clean up any loop related information.
 int numOperands()
          Return the number of operands to this expression.
 boolean optimizationCandidate()
          Return true if the expression can be moved without problems.
 void pushOperands(Stack<Expr> wl)
          Push all of the operands of this expression on the Stack.
 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.
 void removeUseDef()
          Remove any use - def links, may - use links, etc.
 boolean replaceDecl(Declaration oldDecl, Declaration newDecl)
          Replace all occurrances of a Declaration with another Declaration.
 void setLeftArg(Expr la)
          Replace the left operand.
 Expr setOperand(Expr operand, int position)
          Set the nth operand of an expression.
 void setRightArg(Expr ra)
          Replace the right operand.
 int sideEffects()
          Return an indication of the side effects execution of this expression may cause.
 void swapOperands()
          Swap the left and right arguments.
 void unlinkExpression()
          If the node is no longer needed, sever its use-def link, etc.
 void validate()
          Check this node for validity.
 
Methods inherited from class scale.score.expr.Expr
addCast, addCast, canonical, changeInDataEdge, conditionalCopy, conditionalUnlinkExpression, copy, deleteOutDataEdge, executionOrder, executionOrdinal, findCriticalChord, findLinearCoefficient, findSubscriptExpr, getAffineExpr, getAffineRepresentation, getCall, getConstantValue, getConstantValue, getCoreType, getCriticalChord, getDefExpr, getDisplayColorHint, getDisplayLabel, getDisplayShapeHint, getDualExpr, getInDataEdge, getInDataEdgeArray, getLoopHeader, getLow, getLValue, getOutDataEdge, getPointedToCore, getReference, getReuseLevel, getRValue, getType, getUseDef, hasTrueFalseResult, isCast, isDefined, isDefined, isLiteralExpr, isLoopInvariant, isMatchExpr, isMemoryDef, isMemRefExpr, isScalar, isSimpleExpr, mayGenerateCall, numInDataEdges, reduce, removeDualExprs, setCrossloopReuse, setOutDataEdge, setSpatialReuse, setStep, setTemporalReuse, setType, setUseDef, toStringSpecial, validLValue
 
Methods inherited from class scale.score.Note
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
 

Constructor Detail

BinaryExpr

public BinaryExpr(Type t,
                  Expr la,
                  Expr ra)
Method Detail

equivalent

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

Overrides:
equivalent in class Expr
Returns:
true if classes are identical and the core types are equivalent

setOperand

public Expr setOperand(Expr operand,
                       int position)
Set the nth operand of an expression. This method eliminates the data edge between the previous operand expression and this expression. The new operand must not be null.

Overrides:
setOperand in class Expr
Parameters:
operand - - the new operand
position - - indicates which operand
Returns:
the previous operand

getOperand

public Expr getOperand(int position)
Return the nth operand.

Overrides:
getOperand in class Expr
Parameters:
position - the index of the operand

getOperandArray

public Expr[] getOperandArray()
Return an array of the operands to the expression.

Specified by:
getOperandArray in class Expr

numOperands

public int numOperands()
Return the number of operands to this expression.

Specified by:
numOperands in class Expr

getLeftArg

public final Expr getLeftArg()
Return the left argument to the operator.


getRightArg

public final Expr getRightArg()
Return the right argument to the operator.


setLeftArg

public final void setLeftArg(Expr la)
Replace the left operand. This method eliminates the data edge between the previous left argument expression and this expression. The la argument may be null.

Parameters:
la - is the new left argument

setRightArg

public final void setRightArg(Expr ra)
Replace the right operand. This method eliminates the data edge between the previous right argument expression and this expression. The ra argument may be null.

Parameters:
ra - is the new right argument

swapOperands

public final void swapOperands()
Swap the left and right arguments.


associativeSwapOperands

public void associativeSwapOperands()
See if the associative property of the expression can be used to make two constants the arguments of the same binary expression. For example, (x + c1) + c2 is changed to (c2 + c1) + x. This method should be called only by associative binary expressions.


isCommutative

public boolean isCommutative()
Return true if the binary operation is commutative: (a α b) ≡ (b &alpha a).


isAssociative

public boolean isAssociative()
Return true if the binary operation is associative: (a α b) α c ≡ a α (b α c).


isLeftDistributive

public boolean isLeftDistributive()
Return true if the binary operation α is left distributive over β: (a β b) α c ≡ (a α c) β (b α c).


isRightDistributive

public boolean isRightDistributive()
Return true if the binary operation α is right distributive over β: a α (b β c) ≡ (a α b) β (a α c).


loopClean

public void loopClean()
Clean up any loop related information.

Overrides:
loopClean in class Expr

unlinkExpression

public void unlinkExpression()
If the node is no longer needed, sever its use-def link, etc.

Overrides:
unlinkExpression in class Expr

containsDeclaration

public boolean containsDeclaration(Declaration decl)
Return true if this expression contains a reference to the variable.

Overrides:
containsDeclaration in class Expr
See Also:
LoadExpr.setUseOriginal(boolean)

dependsOnDeclaration

public boolean dependsOnDeclaration(Declaration decl)
Return true if this expression's value depends on the variable. The use-def links are followed.

Overrides:
dependsOnDeclaration in class Expr
See Also:
LoadExpr.setUseOriginal(boolean)

optimizationCandidate

public boolean optimizationCandidate()
Return true if the expression can be moved without problems. Expressions that reference global variables, non-atomic variables, etc are not optimization candidates.

Specified by:
optimizationCandidate in class Expr

getAliasAnnote

public AliasAnnote getAliasAnnote()
Get the alias annotation associated with a Scribble operator. Most Scribble operators do not have alias variables so this routine may return null. Typically, the alias variable information is attached to the declaration node associated with the load operations. However, we sometimes need to create alias variables to hold alias information that is not directly assigned to a user variable (e.g., **x).

Overrides:
getAliasAnnote in class Expr
Returns:
the alias annotation associated with the expression

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.

Specified by:
getDeclList in class Expr

getLoadExprList

public void getLoadExprList(Vector<LoadExpr> expList)
Add all LoadExpr instances in this expression to the Vector.

Specified by:
getLoadExprList in class Expr

getExprList

public void getExprList(Vector<Expr> expList)
Add all Expr instances in this expression to the Vector.

Specified by:
getExprList in class Expr

pushOperands

public void pushOperands(Stack<Expr> wl)
Push all of the operands of this expression on the Stack.

Specified by:
pushOperands in class Expr

replaceDecl

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

Specified by:
replaceDecl in class Expr
Returns:
true if a replace occurred.

removeUseDef

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

Specified by:
removeUseDef in class Expr

validate

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

Overrides:
validate in class Expr

recordRefs

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

Specified by:
recordRefs in class Expr

removeRefs

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

Specified by:
removeRefs in class Expr

sideEffects

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

Specified by:
sideEffects in class Expr
See Also:
Expr.SE_NONE