at.dms.kjc.backendSupport
Class ComputeCodeStore<ComputeNodeType extends ComputeNode<?>>

java.lang.Object
  extended by at.dms.kjc.backendSupport.ComputeCodeStore<ComputeNodeType>
Type Parameters:
ComputeNodeType - nasty recursive type, historical relic. TODO: get rid of.
All Implemented Interfaces:
SIRCodeUnit
Direct Known Subclasses:
CellComputeCodeStore, RawComputeCodeStore, UniComputeCodeStore

public class ComputeCodeStore<ComputeNodeType extends ComputeNode<?>>
extends Object
implements SIRCodeUnit

A data structure for associating code with each compute node at each phase. A Code Store implements a SIRCodeUnit so that you can add fields and methods as needed. A ComputeCodeStore also has a main method (of type void->void). The main method has three predefined parts: addInitStatement(JStatement) can be used to add a statement that is performed before the steady state. This is normally called to add statments calling (or inlining) a work method that needs to be run at initialization time to pre-load data needed for peeks. addSteadyLoopStatement(JStatement) can be used to add a statement that is performed in the steady state loop. addCleanupStatement(JStatement) can be used to add a statement that is performed after the steady state loop. It may be useful to call addInitFunctionCall(JMethodDeclaration) to add a call to some method to the beginning of the main method. As the name implies, this is usually used to add calls to the init() functions in filters. Use constructors without the iterationBound parameter to run the steady state indefinitely (and thus make addCleanupStatement(JStatement) useless). Use constructors with the iterationBound parameter to run the steady state for the number of times determined at run time by the value of the iterationBound. As lifted from MGordon's code there is a mutually-recursive type problem: ComputeCodeStore and ComputeNode types are extended in parallel, and each refers to the other. New constructors allow ComputeCodeStore to be constructed without reference to a ComputeNode.

Author:
mgodon / dimock

Field Summary
protected  JBlock cleanupBlock
          the block executed after the steadyLoop
protected static boolean CODE
          set to false if you do not want to generate the work functions calls or inline them useful for debugging
protected  JFieldDeclaration[] fields
          The fields of the tile
protected  JBlock initBlock
          the block that executes each slicenode's init schedule, as calculated currently
protected  JMethodDeclaration mainMethod
          this method calls all the initialization routines and the steady state routines
static String mainName
          The name of the main function for each tile.
protected  JMethodDeclaration[] methods
          the methods of this tile
protected  String myMainName
          name that may be unique per processor.
protected  ComputeNodeType parent
          The ComputeNode this compute code will be place on
protected  JBlock steadyLoop
          block for the steady-state, as calculated currently
 
Constructor Summary
ComputeCodeStore()
          Constructor: steady state loops indefinitely, no pointer back to compute node.
ComputeCodeStore(ALocalVariable iterationBound)
          Constructor: caller will add code to bound number of iterations, no pointer back to compute node.
ComputeCodeStore(ComputeNodeType parent)
          Constructor: steady state loops indefinitely, code store has pointer back to a compute node.
ComputeCodeStore(ComputeNodeType parent, ALocalVariable iterationBound)
          Constructor: caller will add code to bound number of iterations, code store has pointer back to a compute node.
 
Method Summary
 void addCleanupStatement(JStatement stmt)
          Add a statement to the end of the cleanup code.
 void addField(JFieldDeclaration field)
          Adds field field to this, if field is not already registered as a field of this.
 void addFields(JFieldDeclaration[] f)
          Adds f to the fields of this.
 void addInitFunctionCall(JMethodDeclaration init)
          Add the call the init function for a filter as the first statement in "main".
 void addInitStatement(JStatement stmt)
           
 void addInitStatementFirst(JStatement stmt)
           
 void addMethod(JMethodDeclaration method)
          Bill's code adds method meth to this, if meth is not already registered as a method of this.
 void addMethods(JMethodDeclaration[] m)
          Adds m to the methods of this.
protected  void addSteadyLoop()
          Add a way of iterating steadyLoop to the main method.
protected  void addSteadyLoop(ALocalVariable iterationBound)
          Add a way of iterating steadyLoop to the main method.
 void addSteadyLoopStatement(JStatement stmt)
           
 JFieldDeclaration[] getFields()
          Return the fields of this store.
 JMethodDeclaration getMainFunction()
          Return the main function of this store that will execute the init, primepump, and loop the steady-schedule.
 JMethodDeclaration[] getMethods()
          Return the methods of this store.
 String getMyMainName()
          get name for MAIN method in this code store.
 boolean hasMethod(JMethodDeclaration meth)
           
 void setFields(JFieldDeclaration[] f)
          Set the fields of this to f.
 void setMethods(JMethodDeclaration[] m)
          Set methods to m.
protected  void setMyMainName(String mainName)
          Override to get different MAIN names on different ComputeNode's
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mainName

public static String mainName
The name of the main function for each tile. This static field is passed to setMyMainName(String) which can use it or ignore it in setting up a local name for the main loop in each ComputeCodeStore. Assuming that there is only a single subclass of ComputeCodeStore in a given back end you could attempt to override this local field by:
 static { if ("".equals(mainName)) mainName = "__MAIN__";}
 
But you would need to understand your class loader to know what the value would be if multiple subclasses of ComputeCodeStore are loaded in a back end. You are generally better off calling setMyMainName(String) in your constructor and ignoring this field.


myMainName

protected String myMainName
name that may be unique per processor.


CODE

protected static final boolean CODE
set to false if you do not want to generate the work functions calls or inline them useful for debugging

See Also:
Constant Field Values

fields

protected JFieldDeclaration[] fields
The fields of the tile


methods

protected JMethodDeclaration[] methods
the methods of this tile


mainMethod

protected JMethodDeclaration mainMethod
this method calls all the initialization routines and the steady state routines


parent

protected ComputeNodeType extends ComputeNode<?> parent
The ComputeNode this compute code will be place on


steadyLoop

protected JBlock steadyLoop
block for the steady-state, as calculated currently


initBlock

protected JBlock initBlock
the block that executes each slicenode's init schedule, as calculated currently


cleanupBlock

protected JBlock cleanupBlock
the block executed after the steadyLoop

Constructor Detail

ComputeCodeStore

public ComputeCodeStore(ComputeNodeType parent)
Constructor: steady state loops indefinitely, code store has pointer back to a compute node.

Parameters:
parent - a ComputeNode.

ComputeCodeStore

public ComputeCodeStore(ComputeNodeType parent,
                        ALocalVariable iterationBound)
Constructor: caller will add code to bound number of iterations, code store has pointer back to a compute node.

Parameters:
parent - a ComputeNode.
iterationBound - a variable that will be defined locally in

ComputeCodeStore

public ComputeCodeStore(ALocalVariable iterationBound)
Constructor: caller will add code to bound number of iterations, no pointer back to compute node.

Parameters:
iterationBound - a variable that will be defined locally by getMainFunction().addAllStatments(0,stmts);

ComputeCodeStore

public ComputeCodeStore()
Constructor: steady state loops indefinitely, no pointer back to compute node.

Method Detail

addSteadyLoop

protected void addSteadyLoop()
Add a way of iterating steadyLoop to the main method. If you do not want the steady state to loop infinitely then you should override this method.


addSteadyLoop

protected void addSteadyLoop(ALocalVariable iterationBound)
Add a way of iterating steadyLoop to the main method. This version takes a local variable (add declaration to mainMethod) that will hold the iteration count. Current implementation is a simple for loop counting up. XXX: The proper behavior is to loop forever if this variable is set to -1, but the current implementation will loop only INT_MAX times.

Parameters:
iterationBound - the local variable that will hold the iteration count.

setMyMainName

protected void setMyMainName(String mainName)
Override to get different MAIN names on different ComputeNode's


getMyMainName

public String getMyMainName()
get name for MAIN method in this code store.

Returns:
name from a JMethodDeclaration

addInitStatement

public void addInitStatement(JStatement stmt)
Parameters:
stmt - statement to add after any other statements in init code.

addInitStatementFirst

public void addInitStatementFirst(JStatement stmt)

addCleanupStatement

public void addCleanupStatement(JStatement stmt)
Add a statement to the end of the cleanup code. Make sure to
getMainFunction().addStatement(getCleanupBlock());
after calling

Parameters:
stmt - statement to add after any other statements in cleanup code.

addSteadyLoopStatement

public void addSteadyLoopStatement(JStatement stmt)
Parameters:
stmt - statement to add after any other statements in steady-state code.

addMethod

public void addMethod(JMethodDeclaration method)
Bill's code adds method meth to this, if meth is not already registered as a method of this. Requires that method is non-null.

Specified by:
addMethod in interface SIRCodeUnit
Parameters:
method - The method to add.

setMethods

public void setMethods(JMethodDeclaration[] m)
Set methods to m.

Specified by:
setMethods in interface SIRCodeUnit
Parameters:
m - The methods to install.

addFields

public void addFields(JFieldDeclaration[] f)
Adds f to the fields of this. Does not check for duplicates.

Specified by:
addFields in interface SIRCodeUnit
Parameters:
f - The fields to add to the end.

addField

public void addField(JFieldDeclaration field)
Adds field field to this, if field is not already registered as a field of this. (existing field is checked for with ==).

Specified by:
addField in interface SIRCodeUnit
Parameters:
field - The field to attempt to add.

addMethods

public void addMethods(JMethodDeclaration[] m)
Adds m to the methods of this. Does not check for duplicates.

Specified by:
addMethods in interface SIRCodeUnit
Parameters:
m - The methods to attempt to add to the end of the methods.

hasMethod

public boolean hasMethod(JMethodDeclaration meth)
Parameters:
meth -
Returns:
Return true if this compute code store already has the declaration of meth in its method array.

getMethods

public JMethodDeclaration[] getMethods()
Return the methods of this store.

Specified by:
getMethods in interface SIRCodeUnit
Returns:
the methods of this store.

getFields

public JFieldDeclaration[] getFields()
Return the fields of this store.

Specified by:
getFields in interface SIRCodeUnit
Returns:
the fields of this store.

setFields

public void setFields(JFieldDeclaration[] f)
Set the fields of this to f.

Specified by:
setFields in interface SIRCodeUnit
Parameters:
f - The fields to install.

getMainFunction

public JMethodDeclaration getMainFunction()
Return the main function of this store that will execute the init, primepump, and loop the steady-schedule.

Returns:
the main function.

addInitFunctionCall

public void addInitFunctionCall(JMethodDeclaration init)
Add the call the init function for a filter as the first statement in "main".

Parameters:
init - the init function, a call to it will be added.