scale.clef.decl
Class VariableDecl

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.decl.Declaration
              extended by scale.clef.decl.ValueDecl
                  extended by scale.clef.decl.VariableDecl
All Implemented Interfaces:
java.lang.Comparable, AnnotationInterface, DisplayNode
Direct Known Subclasses:
EquivalenceDecl, FormalDecl, RenamedVariableDecl, VirtualVar

public class VariableDecl
extends ValueDecl

This class declares a variable.

$Id: VariableDecl.java,v 1.103 2007-08-28 13:34:32 burrill Exp $

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

If you want to name your generated variables _inxxx where xxx is a number you would do

   UniqueName un = new UniqueName("_in");
   ...
   VariableDecl vd = new VariableDecl(un.genName(), type);
   vd.setTemporary();
   ...
 
If you don't care about the name just do
   VariableDecl vd = new VariableDecl(type);
 
The naming scheme is basically _oonnn where oo identifies the optimization that created the variable. Compiler created variables should be temporary variables unless they must reside in memory. Some values in use for oo are
oocreateruse
A parserFunction prototype argument names
V parserCompiler created variables
_t FindAliasesCompiler created temporary alias variables
vv AliasesCompiler created temporary alias virtual variables
rv_ AliasesCompiler created temporary alias variables
addrtaken_ AliasesCompiler created temporary alias variables
s Scribble Compiler created temporary variables
vn ValNumCompiler created temporary variables
li LICMCompiler created temporary variables
sr ScalarReplacement Compiler created temporary variables
np frontendCompiler created temporary variables
cs Clef2ScribbleCompiler created temporary variables

See Also:
UniqueName

Field Summary
static boolean ignoreAddressTaken
          Set this flag true to study the effect of the address-taken attribute.
 
Constructor Summary
VariableDecl(java.lang.String name, Type type)
          Create a variable declaration which doesn't have a default value.
VariableDecl(java.lang.String name, Type type, Expression initialValue)
           
 
Method Summary
 boolean addressTaken()
          Return true if the address of this Declaration has been taken.
protected  void computeAttributes()
          Determine how the variable must be handled.
 Declaration copy(java.lang.String name)
          Return a copy of this Declaration but with a different name.
 void declareFtnResultVar()
          Specify that the variable is declared as the result variable of a function.
 int getAddressRegister()
          Return the register the code generator assigned to the address of this variable.
 Literal getConstantValue()
          Return the constant value of the expression.
 Displacement getDisplacement()
          Return the displacement the code generator assigned to this variable.
 Expression getInitialValue()
          Return the initializer for this variable or null.
 VariableDecl getOriginal()
          Return the variable that this variable was renamed from.
 Assigned getStorageLoc()
          Return the location type used for this declaration.
 int getValueRegister()
          Return the register the code generator assigned to this variable.
 boolean hasHiddenAliases()
          Return true if the variable may be modified in an unknown way.
 boolean hasHiddenPtrAliases()
          Return true if the memory, to which this pointer variable refers, may be modified in an unknown way.
 boolean hasInvalidArrayReferences()
          Return true if the array specified by this variable has invalid array references.
 boolean inMemory()
          Return true if this declaration is to be allocated to memory.
 boolean isCommonBaseVar()
          Return true if the variable is the base variable for Fortran COMMON.
 boolean isCommonBaseVariable()
          Return true if this is the base variable of a Fortran COMMON area.
 boolean isConst()
          Return true if the variable is a const variable.
 boolean isFtnResultVar()
          Return true if the declaration is declared as the result variable of a function.
 boolean isNotAliasCandidate()
          Return true if no aliases should be created for this variable.
 boolean isNotSSACandidate()
          Return true if this variable can not be in SSA form.
 boolean isReferenced()
          Return true if the declaration is referenced somewhere in the Clef AST.
 boolean isRestricted()
          Return true if the type specifies restricted.
 boolean isStatic()
          Return true if this declaration is static.
protected  boolean isStorageLocSet()
          Return true if the location type used for this declaration is known.
 boolean isTemporary()
          Return true if the declaration is a temporary variable.
 boolean isVariableDecl()
          Return true if VariableDecl instance.
 boolean isVolatile()
          Return true if the type specifies volatile.
 boolean optimizationCandidate()
          Return true if this variable is not a global variable, is not an atomic type, is not volatile, is not const, has no hidden alias, does not have its address taken, and does not have an initial value.
 Residency residency()
          Return the declaration residency.
 VariableDecl returnVariableDecl()
          Return a VariableDecl instance or null.
 void setAddressRegister(int reg)
          Specify the register the code generator assigned to the address of this variable.
 void setAddressTaken()
          Record that the address is used.
 void setDisplacement(Displacement disp)
          Specify the displacement the code generator assigned to this variable.
 void setHiddenAliases()
          Specify that the variable may be modified in an unknown way.
 void setHiddenPtrAliases()
          Specify that the memory, to which this pointer variable refers, may be modified in an unknown way.
 void setInitialValue(Expression value)
          Specify the initial value for a variable.
 void setInvalidArrayReferences()
          Record that the array specified by this variable has invalid array references.
 void setReferenced()
          Specify that the variable is referenced somewhere in the Clef AST.
 void setResidency(Residency residency)
          Specify the residency of the declaration.
 void setStorageLoc(Assigned loc)
          Set the location type used for this declaration.
 void setTemporary()
          Specify that the variable is a temporary variable.
 void setType(Type type)
          Specify the type of this declaration.
 void setValue(Expression value)
          Specify the initial value for a variable.
 void setValueRegister(int reg, ResultMode mode)
          Specify the register the code generator temporarily assigned to this variable.
 void setVisibility(Visibility visibility)
          Specify the visibility of the declaration.
 boolean shouldBeInRegister()
          Return true if this variable should be allocated to a register.
 void specifyCommonBaseVariable()
          Specify that this variable is the base variable for a Fortram COMMON.
 java.lang.String toStringSpecial()
          This method allows sub-classes to provide class specific stuff to the string.
 ResultMode valueRegMode()
          Return the register mode that the code generator temporarily assigned to this variable.
 void visit(Predicate p)
          Process a node by calling its associated routine.
 
Methods inherited from class scale.clef.decl.ValueDecl
getChild, getValue, isValueDecl, numChildren, returnValueDecl
 
Methods inherited from class scale.clef.decl.Declaration
accessibility, compareTo, getActualType, getAlias, getCoreType, getDecl, getDisplayColorHint, getDisplayLabel, getDisplayShapeHint, getMode, getName, getPointedToCore, getTag, getType, hashCode, isCaseLabelDecl, isEnumElementDecl, isEquivalenceDecl, isExceptionDecl, isFieldDecl, isFileDecl, isFormalDecl, isForwardProcedureDecl, isGlobal, isLabelDecl, isProcedureDecl, isPure, isRenamed, isRenamedVariableDecl, isRoutineDecl, isStmtFtnDecl, isTypeDecl, isTypeName, isUnknownFormals, isVirtual, isWeak, returnCaseLabelDecl, returnEnumElementDecl, returnEquivalenceDecl, returnExceptionDecl, returnFieldDecl, returnFileDecl, returnFormalDecl, returnForwardProcedureDecl, returnLabelDecl, returnProcedureDecl, returnRenamedVariableDecl, returnRoutineDecl, returnStmtFtnDecl, returnTypeDecl, returnTypeName, returnUnknownFormals, setAccessibility, setAlias, setName, setTag, setWeak, visibility
 
Methods inherited from class scale.clef.Node
getSourceLineNumber, setAnnotationLevel, setReportLevel, setSourceLineNumber, toString, toString, toStringChildren
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, 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

ignoreAddressTaken

public static boolean ignoreAddressTaken
Set this flag true to study the effect of the address-taken attribute. Note, when this flag is set true programs will not be compiled correctly.

Constructor Detail

VariableDecl

public VariableDecl(java.lang.String name,
                    Type type,
                    Expression initialValue)

VariableDecl

public VariableDecl(java.lang.String name,
                    Type type)
Create a variable declaration which doesn't have a default value.

Method Detail

setType

public void setType(Type type)
Description copied from class: Declaration
Specify the type of this declaration.

Overrides:
setType in class Declaration

setVisibility

public void setVisibility(Visibility visibility)
Specify the visibility of the declaration.

Overrides:
setVisibility in class Declaration
Parameters:
visibility - is the visibility of the declaration
See Also:
Visibility

setResidency

public void setResidency(Residency residency)
Specify the residency of the declaration.

Overrides:
setResidency in class Declaration
Parameters:
residency - is the residency of the declaration
See Also:
Residency

residency

public Residency residency()
Return the declaration residency.

Overrides:
residency in class Declaration
See Also:
Residency

isStorageLocSet

protected final boolean isStorageLocSet()
Return true if the location type used for this declaration is known.


getStorageLoc

public Assigned getStorageLoc()
Return the location type used for this declaration. If the location type has not yet been decided, this routine determines where the variable should be located. Variables whose residency is memory, whose visibility is not local, or that have an initial value are assigned to memory. Variables whose address is taken or that can not be assigned to a register, are allocated to the stack.

Overrides:
getStorageLoc in class Declaration
See Also:
setStorageLoc(scale.clef.decl.Assigned), Machine.keepTypeInRegister(scale.clef.type.Type, boolean)

setStorageLoc

public final void setStorageLoc(Assigned loc)
Set the location type used for this declaration.

Overrides:
setStorageLoc in class Declaration

inMemory

public boolean inMemory()
Return true if this declaration is to be allocated to memory.

Overrides:
inMemory in class Declaration

getDisplacement

public final Displacement getDisplacement()
Return the displacement the code generator assigned to this variable.

Overrides:
getDisplacement in class Declaration

setDisplacement

public final void setDisplacement(Displacement disp)
Specify the displacement the code generator assigned to this variable.

Overrides:
setDisplacement in class Declaration

getValueRegister

public final int getValueRegister()
Return the register the code generator assigned to this variable.

Overrides:
getValueRegister in class Declaration

valueRegMode

public final ResultMode valueRegMode()
Return the register mode that the code generator temporarily assigned to this variable.

Overrides:
valueRegMode in class Declaration
See Also:
Generator

setValueRegister

public final void setValueRegister(int reg,
                                   ResultMode mode)
Specify the register the code generator temporarily assigned to this variable.

Overrides:
setValueRegister in class Declaration
See Also:
Generator

getAddressRegister

public final int getAddressRegister()
Return the register the code generator assigned to the address of this variable.

Overrides:
getAddressRegister in class Declaration

setAddressRegister

public final void setAddressRegister(int reg)
Specify the register the code generator assigned to the address of this variable.

Overrides:
setAddressRegister in class Declaration

isReferenced

public boolean isReferenced()
Return true if the declaration is referenced somewhere in the Clef AST.

Overrides:
isReferenced in class Declaration
See Also:
VariableDecl, RoutineDecl

setReferenced

public final void setReferenced()
Specify that the variable is referenced somewhere in the Clef AST.

Overrides:
setReferenced in class Declaration
See Also:
VariableDecl, RoutineDecl

isConst

public boolean isConst()
Return true if the variable is a const variable.

Overrides:
isConst in class ValueDecl

isTemporary

public final boolean isTemporary()
Return true if the declaration is a temporary variable.

Overrides:
isTemporary in class Declaration

setTemporary

public final void setTemporary()
Specify that the variable is a temporary variable.


hasHiddenAliases

public boolean hasHiddenAliases()
Return true if the variable may be modified in an unknown way.

Overrides:
hasHiddenAliases in class Declaration

setHiddenAliases

public final void setHiddenAliases()
Specify that the variable may be modified in an unknown way.


hasHiddenPtrAliases

public boolean hasHiddenPtrAliases()
Return true if the memory, to which this pointer variable refers, may be modified in an unknown way.


setHiddenPtrAliases

public final void setHiddenPtrAliases()
Specify that the memory, to which this pointer variable refers, may be modified in an unknown way.


isFtnResultVar

public final boolean isFtnResultVar()
Return true if the declaration is declared as the result variable of a function.

Overrides:
isFtnResultVar in class Declaration

declareFtnResultVar

public final void declareFtnResultVar()
Specify that the variable is declared as the result variable of a function.


setAddressTaken

public final void setAddressTaken()
Record that the address is used.

Overrides:
setAddressTaken in class Declaration

addressTaken

public boolean addressTaken()
Return true if the address of this Declaration has been taken.

Overrides:
addressTaken in class Declaration

specifyCommonBaseVariable

public final void specifyCommonBaseVariable()
Specify that this variable is the base variable for a Fortram COMMON.


isCommonBaseVariable

public final boolean isCommonBaseVariable()
Return true if this is the base variable of a Fortran COMMON area.

Overrides:
isCommonBaseVariable in class Declaration

setInvalidArrayReferences

public final void setInvalidArrayReferences()
Record that the array specified by this variable has invalid array references. An example of an invalid array reference is something like
    ((int) ((char *) a + 14))[5]
 


hasInvalidArrayReferences

public final boolean hasInvalidArrayReferences()
Return true if the array specified by this variable has invalid array references. An example of an invalid array reference is something like
    ((int) ((char *) a + 14))[5]
 


computeAttributes

protected final void computeAttributes()
Determine how the variable must be handled. There seems to be some redundancy involved but we will leave the resolution to some future date. It is true that if the variable is an optimization candidate, then it must be able to be put in SSA form.


isNotSSACandidate

public final boolean isNotSSACandidate()
Return true if this variable can not be in SSA form. A variable cannot be put in SSA form if Also, there is no need to place const variables in SSA form.


isNotAliasCandidate

public final boolean isNotAliasCandidate()
Return true if no aliases should be created for this variable. An aliases should not be created if this variable An "alias" is usually created by using a copy of the variable that is maintained in a register.


shouldBeInRegister

public final boolean shouldBeInRegister()
Return true if this variable should be allocated to a register. A variable can not be allocated to a register if


optimizationCandidate

public final boolean optimizationCandidate()
Return true if this variable


isVolatile

public final boolean isVolatile()
Return true if the type specifies volatile.


isRestricted

public final boolean isRestricted()
Return true if the type specifies restricted.


visit

public void visit(Predicate p)
Description copied from class: Node
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(Node n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements Predicate can call
   n.visit(this);
 
where n is a Node 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.

Overrides:
visit in class ValueDecl
See Also:
Predicate

getInitialValue

public final Expression getInitialValue()
Return the initializer for this variable or null.


setInitialValue

public final void setInitialValue(Expression value)
Specify the initial value for a variable. This method is used in those cases where the variable must be defined before its initial value is known.


setValue

public final void setValue(Expression value)
Specify the initial value for a variable. This method is used in those cases where the variable must be defined before its initial value is known.

Overrides:
setValue in class ValueDecl

getConstantValue

public Literal getConstantValue()
Return the constant value of the expression.

Overrides:
getConstantValue in class ValueDecl
See Also:
Lattice

isStatic

public final boolean isStatic()
Return true if this declaration is static.


getOriginal

public VariableDecl getOriginal()
Return the variable that this variable was renamed from.


toStringSpecial

public java.lang.String toStringSpecial()
Description copied from class: Node
This method allows sub-classes to provide class specific stuff to the string.

Overrides:
toStringSpecial in class Declaration

copy

public Declaration copy(java.lang.String name)
Return a copy of this Declaration but with a different name.

Specified by:
copy in class Declaration

isCommonBaseVar

public final boolean isCommonBaseVar()
Return true if the variable is the base variable for Fortran COMMON.


isVariableDecl

public final boolean isVariableDecl()
Description copied from class: Declaration
Return true if VariableDecl instance.

Overrides:
isVariableDecl in class Declaration

returnVariableDecl

public final VariableDecl returnVariableDecl()
Description copied from class: Declaration
Return a VariableDecl instance or null.

Overrides:
returnVariableDecl in class Declaration