scale.score.dependence
Class AffineExpr

java.lang.Object
  extended by scale.score.dependence.AffineExpr

public final class AffineExpr
extends java.lang.Object

A class to represent affine expressions used by the data dependence tester.

$Id: AffineExpr.java,v 1.25 2007-05-03 18:00:57 burrill Exp $

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

An expression is an affine function of variables X1, X2, ..., Xn if it can be expressed as k + Σ aiXi where k, ai are constants. Note, we do not handle the cases where ai or k are loop invariant expressions; they must be integer constants.


Field Summary
static AffineExpr marker
          A token used to represent the affine representation for a Phi functions during determination of its affine representation.
static AffineExpr notAffine
          A token used to represent the affine representation for non-affine expressions.
 
Constructor Summary
AffineExpr()
          Create a new affine expression.
AffineExpr(long coefficient)
          Create a new affine expression.
AffineExpr(VariableDecl vd, long coefficient, LoopHeaderChord loop)
          Create a new affine expression with one term.
AffineExpr(VariableDecl vd, LoopHeaderChord loop)
          Create a new affine expression with one term.
 
Method Summary
 AffineExpr add(AffineExpr a2)
          Return this affine expression which is the addition of two affine expressions.
static AffineExpr add(AffineExpr a1, AffineExpr a2)
          Return this affine expression which is the addition of two affine expressions.
 void addConst(long constant)
          Add constant to the affine expression.
 void addTerm(long coefficient)
          Add a constant value to the affine expression.
 void addTerm(VariableDecl var, long coefficient, LoopHeaderChord loop)
          Add a variable to the affine expression.
 void addTerm(VariableDecl var, LoopHeaderChord loop)
          Add a variable to the affine expression.
 AffineExpr copy()
          Create a copy of the AffineExpr.
 boolean differenceWithin(AffineExpr ae, int offset)
          Return true if the difference of two affine expressions are within in a range.
static AffineExpr divide(AffineExpr a1, AffineExpr a2)
          Return this affine expression which is the division of two affine expressions.
 boolean equivalent(AffineExpr ae)
          Return true if this affine expression is equivalent to the argument.
 void gcd(AffineExpr e)
          Set the constant term to the greatest common denominator of this expression's constant term and the specified expression's constant term.
 long getCoefficient(int term)
          Return the coefficient of the specified term of the affine expression.
 long getConstant()
          Return the constant term from the affine expression.
 LoopHeaderChord getLoop(int term)
          Return the loop associated with the specified term of the affine expression.
 int getTermIndex(VariableDecl term)
          Return the index of the term if the affine expression contains a reference to the variable and -1 otherwise.
 int getTermIndexOrig(VariableDecl term)
          Return the index of the term if the affine expression contains a reference to the variable or a renamed version of the variable and -1 otherwise.
 VariableDecl getVariable(int term)
          Return the variable of the specified term of the affine expression.
 boolean greater(AffineExpr ae)
          Return true if this affine expression is definitely greater than the argument.
 boolean greaterEqual(AffineExpr ae)
          Return true if this affine expression is definitely greater than or equal to the argument.
 boolean hasLoopIndex(LoopHeaderChord loop)
          Return true if one of the terms is a loop index variable
 boolean hasTerm(VariableDecl term)
          Return true if the affine expression contains the parameter term.
 boolean isConst()
          Return true if this affine expression is constant.
 boolean lessEqual(AffineExpr ae)
          Return true if this affine expression is definitely less than or equal the argument.
 void lower(AffineExpr e)
          Set the constant term to the smaller of this expression's constant term and the specified expression's constant term.
 void merge(AffineExpr ae)
          Merge two affine expressions.
 void multConst(long c)
          Multiply the affine expression by a constant.
 AffineExpr multiply(AffineExpr a2)
          Return this affine expression which is the product of two affine expressions.
static AffineExpr multiply(AffineExpr a1, AffineExpr a2)
          Return this affine expression which is the product of two affine expressions.
static AffineExpr negate(AffineExpr a1)
          Return this affine expression which is the division of two affine expressions.
 int numTerms()
          Return the number of terms in the affine expression.
 boolean possiblyGreater(AffineExpr ae)
          Return true if this affine expression is possibly greater than the argument.
 boolean possiblyLess(AffineExpr ae)
          Return true if this affine expression is possibly less than the argument.
 void setCoefficient(int term, long coefficient)
          Set the coefficient of the specified term of the affine expression.
 void setConstant(long c)
          Set the constant term of the affine expression.
 AffineExpr subtract(AffineExpr a2)
          Return this affine expression which is the difference of two affine expressions.
static AffineExpr subtract(AffineExpr a1, AffineExpr a2)
          Return this affine expression which is the difference of two affine expressions.
 java.lang.String toString()
           
 void upper(AffineExpr e)
          Set the constant term to the larger of this expression's constant term and the specified expression's constant term.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

notAffine

public static final AffineExpr notAffine
A token used to represent the affine representation for non-affine expressions.


marker

public static final AffineExpr marker
A token used to represent the affine representation for a Phi functions during determination of its affine representation.

Constructor Detail

AffineExpr

public AffineExpr()
Create a new affine expression.


AffineExpr

public AffineExpr(long coefficient)
Create a new affine expression.


AffineExpr

public AffineExpr(VariableDecl vd,
                  LoopHeaderChord loop)
Create a new affine expression with one term.


AffineExpr

public AffineExpr(VariableDecl vd,
                  long coefficient,
                  LoopHeaderChord loop)
Create a new affine expression with one term.

Method Detail

addTerm

public void addTerm(VariableDecl var,
                    LoopHeaderChord loop)
Add a variable to the affine expression.

Parameters:
var - the variable
loop - is the loop in which the variable is defined

addTerm

public void addTerm(VariableDecl var,
                    long coefficient,
                    LoopHeaderChord loop)
Add a variable to the affine expression.

Parameters:
var - the variable
coefficient - is the coefficient of the variable
loop - is the loop in which the variable is defined

addTerm

public void addTerm(long coefficient)
Add a constant value to the affine expression.

Parameters:
coefficient - is the constant value

hasTerm

public boolean hasTerm(VariableDecl term)
Return true if the affine expression contains the parameter term.


getTermIndex

public int getTermIndex(VariableDecl term)
Return the index of the term if the affine expression contains a reference to the variable and -1 otherwise.


getTermIndexOrig

public int getTermIndexOrig(VariableDecl term)
Return the index of the term if the affine expression contains a reference to the variable or a renamed version of the variable and -1 otherwise.


getConstant

public long getConstant()
Return the constant term from the affine expression.


setConstant

public void setConstant(long c)
Set the constant term of the affine expression.


setCoefficient

public void setCoefficient(int term,
                           long coefficient)
Set the coefficient of the specified term of the affine expression.


getCoefficient

public long getCoefficient(int term)
Return the coefficient of the specified term of the affine expression.


hasLoopIndex

public boolean hasLoopIndex(LoopHeaderChord loop)
Return true if one of the terms is a loop index variable


numTerms

public int numTerms()
Return the number of terms in the affine expression.


getVariable

public VariableDecl getVariable(int term)
Return the variable of the specified term of the affine expression.


getLoop

public LoopHeaderChord getLoop(int term)
Return the loop associated with the specified term of the affine expression.


addConst

public void addConst(long constant)
Add constant to the affine expression.


multConst

public void multConst(long c)
Multiply the affine expression by a constant.


merge

public void merge(AffineExpr ae)
Merge two affine expressions. That, is add the terms of the argument expression into this one.


equivalent

public boolean equivalent(AffineExpr ae)
Return true if this affine expression is equivalent to the argument.

Parameters:
ae - affine expression to compare

possiblyGreater

public boolean possiblyGreater(AffineExpr ae)
Return true if this affine expression is possibly greater than the argument.

Parameters:
ae - affine expression to compare

greaterEqual

public boolean greaterEqual(AffineExpr ae)
Return true if this affine expression is definitely greater than or equal to the argument.

Parameters:
ae - affine expression to compare

greater

public boolean greater(AffineExpr ae)
Return true if this affine expression is definitely greater than the argument.

Parameters:
ae - affine expression to compare

possiblyLess

public boolean possiblyLess(AffineExpr ae)
Return true if this affine expression is possibly less than the argument.

Parameters:
ae - affine expression to compare

lessEqual

public boolean lessEqual(AffineExpr ae)
Return true if this affine expression is definitely less than or equal the argument.

Parameters:
ae - affine expression to compare

differenceWithin

public boolean differenceWithin(AffineExpr ae,
                                int offset)
Return true if the difference of two affine expressions are within in a range.

Parameters:
ae - affine expression to compare

isConst

public boolean isConst()
Return true if this affine expression is constant.


lower

public void lower(AffineExpr e)
Set the constant term to the smaller of this expression's constant term and the specified expression's constant term.


upper

public void upper(AffineExpr e)
Set the constant term to the larger of this expression's constant term and the specified expression's constant term.


gcd

public void gcd(AffineExpr e)
Set the constant term to the greatest common denominator of this expression's constant term and the specified expression's constant term.


copy

public AffineExpr copy()
Create a copy of the AffineExpr.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

add

public AffineExpr add(AffineExpr a2)
Return this affine expression which is the addition of two affine expressions.


add

public static AffineExpr add(AffineExpr a1,
                             AffineExpr a2)
Return this affine expression which is the addition of two affine expressions.


subtract

public AffineExpr subtract(AffineExpr a2)
Return this affine expression which is the difference of two affine expressions.


subtract

public static AffineExpr subtract(AffineExpr a1,
                                  AffineExpr a2)
Return this affine expression which is the difference of two affine expressions.


multiply

public AffineExpr multiply(AffineExpr a2)
Return this affine expression which is the product of two affine expressions.


multiply

public static AffineExpr multiply(AffineExpr a1,
                                  AffineExpr a2)
Return this affine expression which is the product of two affine expressions.


divide

public static AffineExpr divide(AffineExpr a1,
                                AffineExpr a2)
Return this affine expression which is the division of two affine expressions.


negate

public static AffineExpr negate(AffineExpr a1)
Return this affine expression which is the division of two affine expressions.