coins.hir2lir
Class ReformHir

java.lang.Object
  extended bycoins.hir2lir.ReformHir

public class ReformHir
extends java.lang.Object

ReformHir class Reform HIR for profiling and parallelization without using OpenMP.


Field Summary
protected  boolean fChanged
           
protected  CoinsOptions fCoinsOptions
           
protected  int fDbgLevel
           
protected  LoopParallel fLoopParallel
           
protected  java.util.Map fLoopStmtToLoopTable
           
protected  java.util.List fLoopsToBeParallelized
           
 FlowRoot flowRoot
           
protected  int fMaxDegreeOfParallel
           
 int fMaximumNumberOfReductions
           
protected  Var fNumberOfThreads
           
protected  FlowResults fResults
           
protected  boolean fStackInLocalMemory
           
protected  java.util.Map fStatementsToBeAdded
           
protected  java.util.List fStatementsToBeDeleted
           
protected  java.util.Map fStatementsToBeReplaced
           
protected  java.util.List fSubpDefinitionList
           
protected  SubpFlow fSubpFlow
           
protected  SymTable fSymTableCurrent
           
protected  Var fThreadDescriptor
           
protected  Subp fThreadEnd
           
protected  Subp fThreadForkForDoAll
           
protected  Var fThreadIdArray
           
protected  Var fThreadIdOfMaster
           
protected  Subp fThreadInit
           
protected  Subp fThreadJoin
           
protected  Subp fThreadPostprocess
           
protected  Subp fThreadPostprocessForDoAllThread
           
protected  Subp fThreadPreprocessForDoAllLoop
           
protected  Subp fThreadPreprocessForDoAllThread
           
protected  Subp fThreadSelfId
           
protected  Type fThreadType
           
protected  LoopUtil fUtil
           
protected  HIR hir
           
 HirRoot hirRoot
           
 IoRoot ioRoot
           
protected  SubpFlow subpFlow
           
protected  Sym sym
           
 SymRoot symRoot
           
 
Constructor Summary
ReformHir(HirRoot pHirRoot)
          ReformHir Process HIR pragmas and change them to ones that may correspond to HIR pragma.
 
Method Summary
protected  void callHirBaseToC(HirRoot hirRoot, SymRoot symRoot, IoRoot io, java.io.OutputStream out)
          Translates HIR-Base into a C source program and writes it to an OutputStream.
protected  void changeLoopToSubprogram(LoopTable pTable)
          Change loop indicated by pTable to a subprogram to be executed in parallel.
 Param defineParam(java.lang.String pHeader, Type pType, SymTable pSymTable)
           
 Var defineVar(java.lang.String pHeader, Type pType, SymTable pSymTable, Subp pDefinedIn)
           
protected  Var getPrimaryInductionVar(ForStmt pForStmt)
          Get the primary induction variable of the loop.
protected  Reduction getReductionForVar(Var pVar, java.util.List pReductionList)
           
protected  java.util.List getReductionList(LoopTable pTable)
          Get the list of reductions for the loop represented by pTable.
protected  java.util.Set getReductionVar(java.util.List pReductionList)
          Get all reduction variables each of which corresponds to the reduction table in pReductionList.
protected  Var getVarOfExp(Exp pExp)
          Get the variable represented by pExp or by its child 1 node.
protected  Exp initialValueOfReduction(LoopTable pTable, Var pReductionVar)
           
protected  boolean makeCSourceFromHirBase(java.lang.String timing, HirRoot hirRoot, SymRoot symRoot, IoRoot io)
           
protected  SubpDefinition makeSubpDefinition(LoopTable pTable, java.util.List pInLoopVarList, java.util.List pChangeToLocal, java.util.List pChangeToGlobal, java.util.Set pInductionVars, java.util.Set pReductionVarSet, java.util.Set pReductionsToInitiate, java.util.List pPassPointer, java.util.Set pCopyToChild, java.util.Set pCopyBack)
          Make subprogram definition corresponding to the loop represented by pTable.
protected  boolean parallelize(SubpDefinition pSubpDefinition)
          Parallelize the subprogram pSubpDefinition.
 void printList(java.util.List pList, java.lang.String pHeader)
          Print the list pList with header pHeader.
protected  void printLoopTable(LoopTable pTable)
           
 void printSet(java.util.Set pSet, java.lang.String pHeader)
          Print the set pSet with header indicated by pHeader.
protected  boolean reformForInitiation(SubpDefinition pSubpDefinition)
          Reform for thread initiation without parallelizing.
 void reformForParallel()
           
 void reformForProfiling()
          Change global gragmas (pragmas placed as global declaration) (inf prof (defaultTraceOn)) (inf prof (defaultTraceOff)) (inf prof (subpTraceOn subp1 subp1 ...)) (inf prof (subpTraceOff subp1 subp1 ...)) to subprogram-wise pragma.
protected  boolean reformHirToParallelize()
          Decide how to transform HIR of SubpDefinition indicated by subpFlow so as it can be executed in parallel.
protected  HIR rewriteVariables(HIR pNewHir, java.util.Map pOldSymToNewVarExp)
          Rewrite variables in pNewHir according to the map pOldSymToNewVarExp.
protected  java.util.Set varNodeToVarSet(java.util.Set pVarNodes)
          Change the set of VarNodes to a set of corresponding Vars.
protected  Stmt writeVector(Var pFromVar, Var pToVar, SymTable pSymTable)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ioRoot

public final IoRoot ioRoot

symRoot

public final SymRoot symRoot

hirRoot

public final HirRoot hirRoot

hir

protected HIR hir

sym

protected Sym sym

fCoinsOptions

protected CoinsOptions fCoinsOptions

fChanged

protected boolean fChanged

flowRoot

public FlowRoot flowRoot

fLoopParallel

protected LoopParallel fLoopParallel

fUtil

protected LoopUtil fUtil

fSubpFlow

protected SubpFlow fSubpFlow

subpFlow

protected SubpFlow subpFlow

fResults

protected FlowResults fResults

fSymTableCurrent

protected SymTable fSymTableCurrent

fSubpDefinitionList

protected java.util.List fSubpDefinitionList

fStatementsToBeReplaced

protected java.util.Map fStatementsToBeReplaced

fStatementsToBeAdded

protected java.util.Map fStatementsToBeAdded

fStatementsToBeDeleted

protected java.util.List fStatementsToBeDeleted

fLoopStmtToLoopTable

protected java.util.Map fLoopStmtToLoopTable

fLoopsToBeParallelized

protected java.util.List fLoopsToBeParallelized

fMaxDegreeOfParallel

protected int fMaxDegreeOfParallel

fThreadType

protected Type fThreadType

fThreadDescriptor

protected Var fThreadDescriptor

fNumberOfThreads

protected Var fNumberOfThreads

fThreadIdArray

protected Var fThreadIdArray

fThreadIdOfMaster

protected Var fThreadIdOfMaster

fStackInLocalMemory

protected boolean fStackInLocalMemory

fThreadInit

protected Subp fThreadInit

fThreadEnd

protected Subp fThreadEnd

fThreadPreprocessForDoAllLoop

protected Subp fThreadPreprocessForDoAllLoop

fThreadPostprocess

protected Subp fThreadPostprocess

fThreadForkForDoAll

protected Subp fThreadForkForDoAll

fThreadPreprocessForDoAllThread

protected Subp fThreadPreprocessForDoAllThread

fThreadPostprocessForDoAllThread

protected Subp fThreadPostprocessForDoAllThread

fThreadJoin

protected Subp fThreadJoin

fThreadSelfId

protected Subp fThreadSelfId

fDbgLevel

protected int fDbgLevel

fMaximumNumberOfReductions

public final int fMaximumNumberOfReductions
See Also:
Constant Field Values
Constructor Detail

ReformHir

public ReformHir(HirRoot pHirRoot)
ReformHir Process HIR pragmas and change them to ones that may correspond to HIR pragma. If InfStmts are changed, then renumber the HIR nodes.

Method Detail

reformForProfiling

public void reformForProfiling()
Change global gragmas (pragmas placed as global declaration) (inf prof (defaultTraceOn)) (inf prof (defaultTraceOff)) (inf prof (subpTraceOn subp1 subp1 ...)) (inf prof (subpTraceOff subp1 subp1 ...)) to subprogram-wise pragma.


reformForParallel

public void reformForParallel()

parallelize

protected boolean parallelize(SubpDefinition pSubpDefinition)
Parallelize the subprogram pSubpDefinition.

Parameters:
pSubpDefinition - Subprogram definition requested to be parallelized.
Returns:
true if parallelizing transformation is actually done.

reformForInitiation

protected boolean reformForInitiation(SubpDefinition pSubpDefinition)
Reform for thread initiation without parallelizing.

Parameters:
pSubpDefinition - Subprogram definition that may contain thread initiation pragma.
Returns:
true if transformation is actually done.

reformHirToParallelize

protected boolean reformHirToParallelize()
Decide how to transform HIR of SubpDefinition indicated by subpFlow so as it can be executed in parallel. The results are recorded in fStatementsToBeAdded fStatementsToBeReplaced, fStatementsToBeDeleted.

Returns:
true if HIR is to be actually transformed.

changeLoopToSubprogram

protected void changeLoopToSubprogram(LoopTable pTable)
Change loop indicated by pTable to a subprogram to be executed in parallel.

Parameters:
pTable - Loop table of the loop to be parallelized.

makeSubpDefinition

protected SubpDefinition makeSubpDefinition(LoopTable pTable,
                                            java.util.List pInLoopVarList,
                                            java.util.List pChangeToLocal,
                                            java.util.List pChangeToGlobal,
                                            java.util.Set pInductionVars,
                                            java.util.Set pReductionVarSet,
                                            java.util.Set pReductionsToInitiate,
                                            java.util.List pPassPointer,
                                            java.util.Set pCopyToChild,
                                            java.util.Set pCopyBack)
Make subprogram definition corresponding to the loop represented by pTable.

Parameters:
pTable - Loop table of the loop.
pInLoopVarList - list of variables appering in the loop.
pChangeToLocal - variables to be changed from global to local.
pChangeToGlobal - variables to be changed from local to global.
pInductionVars - set of induction variables in the loop.
pReductionVarSet - set of reduction variables in the loop.
pReductionsToInitiate - set of reduction variables to be initialized in the generated subprgoram.
pPassPointer - set of variables passing write back receiver including reductions.
pCopyToChild - set of variables to be copied from parent to child (neither last private nore reduction).
pCopyBack - set of variabled to be copied from child to parent (neither last private nore reduction).
Returns:
SubpDefinition generated.

rewriteVariables

protected HIR rewriteVariables(HIR pNewHir,
                               java.util.Map pOldSymToNewVarExp)
Rewrite variables in pNewHir according to the map pOldSymToNewVarExp.

Parameters:
pNewHir - Statement or expression to be changed.
pOldSymToNewVarExp - maps old variable to new variable expression.

defineVar

public Var defineVar(java.lang.String pHeader,
                     Type pType,
                     SymTable pSymTable,
                     Subp pDefinedIn)

defineParam

public Param defineParam(java.lang.String pHeader,
                         Type pType,
                         SymTable pSymTable)

getPrimaryInductionVar

protected Var getPrimaryInductionVar(ForStmt pForStmt)
Get the primary induction variable of the loop.

Parameters:
pForStmt - loop statement.
Returns:
the primary induction variable

writeVector

protected Stmt writeVector(Var pFromVar,
                           Var pToVar,
                           SymTable pSymTable)

printLoopTable

protected void printLoopTable(LoopTable pTable)

printList

public void printList(java.util.List pList,
                      java.lang.String pHeader)
Print the list pList with header pHeader.

Parameters:
pList - list of items to be printed.
pHeader - string explaining the set in short.

printSet

public void printSet(java.util.Set pSet,
                     java.lang.String pHeader)
Print the set pSet with header indicated by pHeader.

Parameters:
pSet - set of items.
pHeader - header string to be printed.

varNodeToVarSet

protected java.util.Set varNodeToVarSet(java.util.Set pVarNodes)
Change the set of VarNodes to a set of corresponding Vars.

Parameters:
pVarNodes - set of VarNodes.
Returns:
the set of Var symbols.

getVarOfExp

protected Var getVarOfExp(Exp pExp)
Get the variable represented by pExp or by its child 1 node.

Parameters:
pExp -
Returns:
the variable represented by pExp.

getReductionVar

protected java.util.Set getReductionVar(java.util.List pReductionList)
Get all reduction variables each of which corresponds to the reduction table in pReductionList.

Parameters:
pReductionList - list of reductions.
Returns:
set of reduction variables.

getReductionList

protected java.util.List getReductionList(LoopTable pTable)
Get the list of reductions for the loop represented by pTable.

Parameters:
pTable - LoopTable of the loop.
Returns:
list of reductions.

getReductionForVar

protected Reduction getReductionForVar(Var pVar,
                                       java.util.List pReductionList)

initialValueOfReduction

protected Exp initialValueOfReduction(LoopTable pTable,
                                      Var pReductionVar)

makeCSourceFromHirBase

protected boolean makeCSourceFromHirBase(java.lang.String timing,
                                         HirRoot hirRoot,
                                         SymRoot symRoot,
                                         IoRoot io)
                                  throws java.io.IOException
Throws:
java.io.IOException

callHirBaseToC

protected void callHirBaseToC(HirRoot hirRoot,
                              SymRoot symRoot,
                              IoRoot io,
                              java.io.OutputStream out)
                       throws java.io.IOException
Translates HIR-Base into a C source program and writes it to an OutputStream.

Parameters:
hirRoot - an HirRoot object.
symRoot - a SymRoot object.
io - the IoRoot.
out - an OutputStream to which the C source program is written.
Throws:
java.io.IOException - any IO error.
PassException - unrecoverable error(s) found in processing.