scale.score.dependence
Class AffineExpr

java.lang.Object
  |
  +--scale.score.dependence.AffineExpr

public final class AffineExpr
extends java.lang.Object

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

$Id: AffineExpr.java,v 1.6 2002/01/14 21:22:20 burrill Exp $

Copyright 2002 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, v1, v2, ..., vN if it can be expressed as the sum of a known constant times each of the variables plus a constant. That is,

 c0 + c1*v1 + c2*v2 + ... + cN*vN, 
 for known integers, c0..cN.
 
The omega test wants an AffineExpr object associated with each subscript, loop bound, or conditional (we don't do anything for conditionals yet).

See Also:
AffineTerm

Constructor Summary
AffineExpr()
          Create a new affine expression object.
AffineExpr(int n)
          Create a new affine expression object with room for n terms.
 
Method Summary
 void add(AffineExpr ae)
          Add the argument affine expression to this one.
 void addConst(int c)
          Add constant to affine expression.
 void addMaxTerm(Expr indexVar)
          Add an index variable to the affine expression.
 void addMinTerm(Expr indexVar)
          Add an index variable to the affine expression.
 void addTerm(AffineTerm at)
          Add a term to the affine expression.
 void addTerm(Expr indexVar)
          Add a index variable to the affine expression.
 int constValue()
           
 AffineExpr copy()
          Create a deep copy of the AffineExpr.
 boolean differenceWithin(AffineExpr ae, int offset)
          check if the difference of two affine expressions are within in a range
 boolean equivalent(AffineExpr ae)
          Check if this affine expression is equivalent.
 void gcd(AffineExpr e)
           
 AffineTerm getConstantTerm()
          Get the constant term from the affine expression.
 AffineTerm getMaxTerm()
          Get the MAX term; should be the first term (index 0).
 AffineTerm getMinTerm()
          Get the MIN term; should be the first term (index 0).
 AffineTerm getTerm(int i)
          Get the ith term from the affine expression.
 Vector getVarTerms()
          Return the variable (non-constant) terms of the affine expression.
 boolean greater(AffineExpr ae)
          check if this affine expression is definitely greater than ae
 boolean greaterEqual(AffineExpr ae)
          check if this affine expression is definitely greater than or equal to ae
 boolean hasLoopIndex()
          Return true if one of the terms is a loop index variable
 boolean hasMaxTerm()
          Return true if the expression has a MAX term.
 boolean hasMinTerm()
          Return true if the expression has a MIN term.
 AffineTerm hasTerm(Expr term)
          Return true if the affine expression contains the parameter term.
 boolean isConst()
           
 boolean lessEqual(AffineExpr ae)
          check if this affine expression is definitely less than or equal to ae
 void lower(AffineExpr e)
           
 void merge(AffineExpr ae)
          Merge two affine expressions.
 void multConst(int c)
          Multiply affine expression by constant int.
 int numTerms()
          Return the number of terms in the affine expression.
 boolean possiblyGreater(AffineExpr ae)
          Check if this affine expression is possibly greater than ae
 boolean possiblyLess(AffineExpr ae)
          check if this affine expression is possibly less than ae
 void setMaxFlag()
          Set the hasMax flag
 void setMinFlag()
          Set the hasMin flag
 void simplify()
           
 void simplifyConstTerms()
           
 void substract(AffineExpr ae)
          Substract the argument affine expression from this one.
 java.lang.String toString()
          Redefine toString to print out exactly the way Petit prints so that we can compare using diff.
 java.lang.String toString2()
          Redefine toString to print out meaningful results.
 java.lang.String toString3()
          Redefine toString to print out exactly the way Petit prints so that we can compare using diff.
 java.lang.String toStringSpecial()
          Redefine toString to print out meaningful results.
 void upper(AffineExpr e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AffineExpr

public AffineExpr(int n)
Create a new affine expression object with room for n terms.

AffineExpr

public AffineExpr()
Create a new affine expression object.
Method Detail

addTerm

public void addTerm(Expr indexVar)
Add a index variable to the affine expression.
Parameters:
indexVar - the index variable

addTerm

public void addTerm(AffineTerm at)
Add a term to the affine expression.
Parameters:
at - the affine term.

addMinTerm

public void addMinTerm(Expr indexVar)
Add an index variable to the affine expression.
Parameters:
indexVar - the index variable

addMaxTerm

public void addMaxTerm(Expr indexVar)
Add an index variable to the affine expression.
Parameters:
indexVar - the index variable

setMinFlag

public void setMinFlag()
Set the hasMin flag

setMaxFlag

public void setMaxFlag()
Set the hasMax flag

hasMinTerm

public boolean hasMinTerm()
Return true if the expression has a MIN term.

hasMaxTerm

public boolean hasMaxTerm()
Return true if the expression has a MAX term.

getVarTerms

public Vector getVarTerms()
Return the variable (non-constant) terms of the affine expression.

getTerm

public AffineTerm getTerm(int i)
Get the ith term from the affine expression.

hasTerm

public AffineTerm hasTerm(Expr term)
Return true if the affine expression contains the parameter term.

getMinTerm

public AffineTerm getMinTerm()
Get the MIN term; should be the first term (index 0).

getMaxTerm

public AffineTerm getMaxTerm()
Get the MAX term; should be the first term (index 0).

getConstantTerm

public AffineTerm getConstantTerm()
Get the constant term from the affine expression. This should only be called after the affine expression is finalized, as this may add an extra term.

hasLoopIndex

public boolean hasLoopIndex()
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. It doesn't include the initial coefficient value (which doesn't have an index variable).
Returns:
the number of terms in the affine expression.

addConst

public void addConst(int c)
Add constant to affine expression.

multConst

public void multConst(int c)
Multiply affine expression by constant int.

add

public void add(AffineExpr ae)
Add the argument affine expression to this one.

substract

public void substract(AffineExpr ae)
Substract the argument affine expression from this one.

merge

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

simplify

public void simplify()

simplifyConstTerms

public void simplifyConstTerms()

equivalent

public boolean equivalent(AffineExpr ae)
Check if this affine expression is equivalent.
Parameters:
ae - affine expression to compare

possiblyGreater

public boolean possiblyGreater(AffineExpr ae)
Check if this affine expression is possibly greater than ae
Parameters:
ae - affine expression to compare

greaterEqual

public boolean greaterEqual(AffineExpr ae)
check if this affine expression is definitely greater than or equal to ae
Parameters:
ae - affine expression to compare

greater

public boolean greater(AffineExpr ae)
check if this affine expression is definitely greater than ae
Parameters:
ae - affine expression to compare

possiblyLess

public boolean possiblyLess(AffineExpr ae)
check if this affine expression is possibly less than ae
Parameters:
ae - affine expression to compare

lessEqual

public boolean lessEqual(AffineExpr ae)
check if this affine expression is definitely less than or equal to ae
Parameters:
ae - affine expression to compare

differenceWithin

public boolean differenceWithin(AffineExpr ae,
                                int offset)
check if the difference of two affine expressions are within in a range
Parameters:
ae - affine expression to compare

isConst

public boolean isConst()

constValue

public int constValue()

lower

public void lower(AffineExpr e)

upper

public void upper(AffineExpr e)

gcd

public void gcd(AffineExpr e)

copy

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

toString

public java.lang.String toString()
Redefine toString to print out exactly the way Petit prints so that we can compare using diff. Do some formatting to match Petit output. Swap constant term and second term if the second (non-constant) term has positive coefficient: 1+i -> i+1; 1-j -> 1-j; Also, move index term coefficients that need to be printed (greater than 1 in absolute value) after the term: 2*i -> i*2; -3*j -> j*(-3)
Overrides:
toString in class java.lang.Object

toString3

public java.lang.String toString3()
Redefine toString to print out exactly the way Petit prints so that we can compare using diff.

toString2

public java.lang.String toString2()
Redefine toString to print out meaningful results.

toStringSpecial

public java.lang.String toStringSpecial()
Redefine toString to print out meaningful results.