at.dms.kjc.backendSupport
Class CodeStoreHelper

java.lang.Object
  extended by at.dms.kjc.backendSupport.MinCodeUnit
      extended by at.dms.kjc.backendSupport.CodeStoreHelper
All Implemented Interfaces:
SIRCodeUnit
Direct Known Subclasses:
CodeStoreHelperJoiner, CodeStoreHelperSimple, CodeStoreHelperSplitter

public abstract class CodeStoreHelper
extends MinCodeUnit

For creation of additional code necessary to getting filter / joiner / splitter code hooked up to a ComputeCodeStore.

Author:
dimock / concept and stolen code from mgordon

Field Summary
protected  BackEndFactory backEndBits
          a BackEndFactory for getting information about other parts of the back end
protected  JMethodDeclaration initMethod
           
static String initStage
          possible prefix for functions in initialization
static boolean INLINE_WORK
          Do we want to inline work functions or just call a single copy?
protected  JMethodDeclaration preWorkMethod
           
protected  JMethodDeclaration primePumpMethod
           
static String primePumpStage
          possible prefix for functions in prime-pump stage
protected  SliceNode sliceNode
          The slice node that we are generating helper code for
static String steadyStage
          possible prefix for functions in steady state
protected  int uniqueID
          a value that should be unique per instance, useful in generating non-clashing variable names.
static String workCounter
          possible prefix for loop counters for iterating work function
protected  JMethodDeclaration workMethod
           
 
Constructor Summary
CodeStoreHelper(SliceNode node, BackEndFactory backEndBits)
          General constructor: need to add fields and methods later.
CodeStoreHelper(SliceNode node, FilterContent filter, BackEndFactory backEndBits)
          Constructor from a FilterContent, fills out fields, methods, initMethod, preWorkMethod, workMethod.
 
Method Summary
static void addHelperForSliceNode(SliceNode s, CodeStoreHelper u)
          Record a mapping from a SliceNode to a CodeStoreHelper.
static CodeStoreHelper findHelperForSliceNode(SliceNode s)
          Use #findCodeForSlice, #addCodeForSlice to keep track of whether a SIRCodeUnit of code has been generated already for a SliceNode.
 JMethodDeclaration getInitMethod()
           
abstract  JMethodDeclaration getInitStageMethod()
           
 JMethodDeclaration getPreWorkMethod()
           
abstract  JMethodDeclaration getPrimePumpMethod()
           
protected  JMethodDeclaration getPrimePumpMethodForFilter(FilterInfo filterInfo)
          Calculate and return the method that will implement one execution of this filter in the primepump stage.
abstract  JBlock getSteadyBlock()
           
protected static int getUniqueID()
          a way of setting the unique value
 JFieldDeclaration[] getUsefulFields()
           
 JMethodDeclaration[] getUsefulMethods()
           
protected  JBlock getWorkFunctionBlock(int mult)
          Return a JBlock that iterates mult times the result of calling getWorkFunctionCall().
protected  JStatement getWorkFunctionCall()
          Return the code that will call the work function once.
 JMethodDeclaration getWorkMethod()
           
 void reset()
          Clean up static data.
 void setInitMethod(JMethodDeclaration meth)
          set init method: please pass it some method already in range of MinCodeUnit.getMethods()
 void setPreWorkMethod(JMethodDeclaration meth)
          set preWork (initWork) method: please pass it some method already in range of MinCodeUnit.getMethods()
 void setWorkMethod(JMethodDeclaration meth)
          set work method: please pass it some method already in range of MinCodeUnit.getMethods()
 
Methods inherited from class at.dms.kjc.backendSupport.MinCodeUnit
addField, addFields, addMethod, addMethods, getFields, getMethods, setFields, setMethods
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

initStage

public static String initStage
possible prefix for functions in initialization


steadyStage

public static String steadyStage
possible prefix for functions in steady state


primePumpStage

public static String primePumpStage
possible prefix for functions in prime-pump stage


workCounter

public static String workCounter
possible prefix for loop counters for iterating work function


INLINE_WORK

public static boolean INLINE_WORK
Do we want to inline work functions or just call a single copy?


sliceNode

protected SliceNode sliceNode
The slice node that we are generating helper code for


backEndBits

protected BackEndFactory backEndBits
a BackEndFactory for getting information about other parts of the back end


uniqueID

protected int uniqueID
a value that should be unique per instance, useful in generating non-clashing variable names.


primePumpMethod

protected JMethodDeclaration primePumpMethod

initMethod

protected JMethodDeclaration initMethod

preWorkMethod

protected JMethodDeclaration preWorkMethod

workMethod

protected JMethodDeclaration workMethod
Constructor Detail

CodeStoreHelper

public CodeStoreHelper(SliceNode node,
                       BackEndFactory backEndBits)
General constructor: need to add fields and methods later.


CodeStoreHelper

public CodeStoreHelper(SliceNode node,
                       FilterContent filter,
                       BackEndFactory backEndBits)
Constructor from a FilterContent, fills out fields, methods, initMethod, preWorkMethod, workMethod. Note: clones inputs.

Method Detail

getUniqueID

protected static int getUniqueID()
a way of setting the unique value


getInitMethod

public JMethodDeclaration getInitMethod()
Returns:
get init method, may be null since some SliceNodes may only generate helper methods.

setInitMethod

public void setInitMethod(JMethodDeclaration meth)
set init method: please pass it some method already in range of MinCodeUnit.getMethods()


getPreWorkMethod

public JMethodDeclaration getPreWorkMethod()
Returns:
get preWork (initWork) method, may be null.

setPreWorkMethod

public void setPreWorkMethod(JMethodDeclaration meth)
set preWork (initWork) method: please pass it some method already in range of MinCodeUnit.getMethods()


getWorkMethod

public JMethodDeclaration getWorkMethod()
Returns:
get work method, may be null since some SliceNodes may only generate helper methods.

setWorkMethod

public void setWorkMethod(JMethodDeclaration meth)
set work method: please pass it some method already in range of MinCodeUnit.getMethods()


findHelperForSliceNode

public static CodeStoreHelper findHelperForSliceNode(SliceNode s)
Use #findCodeForSlice, #addCodeForSlice to keep track of whether a SIRCodeUnit of code has been generated already for a SliceNode.

Parameters:
s - A SliceNode
Returns:
The CodeStoreHelper added for the SliceNode by #addCodeForSlice.

addHelperForSliceNode

public static void addHelperForSliceNode(SliceNode s,
                                         CodeStoreHelper u)
Record a mapping from a SliceNode to a CodeStoreHelper. Used to track out-of-sequence code generation to eliminate duplicates.

Parameters:
s - a SliceNode
u - a CodeStoreHelper

reset

public void reset()
Clean up static data.


getUsefulFields

public JFieldDeclaration[] getUsefulFields()
Returns:
all fields that are needed in the ComputeCodeStore: both those from underlying code and those generated in this class

getUsefulMethods

public JMethodDeclaration[] getUsefulMethods()
Returns:
all methods that are needed in the ComputeCodeStore: may decide to not return a method if its body will be inlined.

getInitStageMethod

public abstract JMethodDeclaration getInitStageMethod()
Returns:
the method we should call to execute the init stage.

getSteadyBlock

public abstract JBlock getSteadyBlock()
Returns:
The block we should inline to execute the steady-state

getPrimePumpMethod

public abstract JMethodDeclaration getPrimePumpMethod()
Returns:
The method to call for one execution of the filter in the prime pump stage.

getPrimePumpMethodForFilter

protected JMethodDeclaration getPrimePumpMethodForFilter(FilterInfo filterInfo)
Calculate and return the method that will implement one execution of this filter in the primepump stage. This method may be called multiple times depending on the number of stages in the primepump stage itself.

Returns:
The method that implements one stage of the primepump exeuction of this filter.

getWorkFunctionBlock

protected JBlock getWorkFunctionBlock(int mult)
Return a JBlock that iterates mult times the result of calling getWorkFunctionCall().

Parameters:
mult - Number of times to iterate work function.
Returns:
as described, or null if getWorkFunctionCall() returns null;

getWorkFunctionCall

protected JStatement getWorkFunctionCall()
Return the code that will call the work function once. It will either be the entire function inlined or a function call.

Returns:
The code to execute the work function once or null if there is no work function.
See Also:
INLINE_WORK