coins.opt
クラス GlobalReform

java.lang.Object
  |
  +--coins.opt.GlobalReform

public class GlobalReform
extends java.lang.Object


入れ子クラスの概要
protected  class GlobalReform.MatchingData
          The class MatchingData represents various matching insormation and provides methods to set/refer them.
protected  class GlobalReform.NontermPatInstance
          This class holds information for the instance of a nonterminal or a pattern and provides methods for them.
protected  class GlobalReform.OptInf
          OptInf is used to represent an object instanciated for each pattern and nonterminal.
protected  class GlobalReform.PatternCodeRange
          PatternCodeRange represents pattern code range including upper value and lower value.
 
フィールドの概要
protected  boolean fChanged
           
protected  int[] fCodeIndexFrom
           
protected  int[] fCodeIndexTo
           
protected  CoinsOptions fCoinsOptions
           
protected  java.util.Set fCompileTimeEval
           
protected  Subp fCurrentPatternSym
           
protected  Stmt fCurrentStmt
           
protected  int fDbgLevel
           
(パッケージプライベート) static double fDontCareCode
           
protected  java.util.Map fExpandedNonterm
           
protected  java.util.Map fExpandedNontermInstance
           
protected  java.util.Set fFittingSet
           
protected  java.util.Set fFitToAnyCall
           
protected  java.util.Set[] fFormalParams
           
protected  java.util.Map fGlobalPatternParamMap
           
(パッケージプライベート) static double fHirCodeLim
           
(パッケージプライベート) static double fHirCodeLim2
           
(パッケージプライベート) static double fHirCodeLim3
           
(パッケージプライベート) static double fHirCodeLim4
           
(パッケージプライベート) static double fHirCodeLim5
           
(パッケージプライベート) static double fHirCodeLim6
           
protected  java.util.Set fHirKeys
           
protected  java.util.Map fInPatternMap
           
protected  int[] fInstanceNumberForNonterminals
           
protected  GlobalReform.MatchingData[] fLastMatchingDataForNonterm
           
protected  java.util.Map fLocalVarListMap
           
protected  java.util.Map fMatchingDataForNonterm
           
protected  java.util.Map fMatchingDataForNontermInstance
           
protected  int fMaxStmtsInPattern
           
protected  Stmt fNextStmt
           
protected  double fNextStmtCode
           
protected  java.util.Set fNoFurtherChange
           
protected  java.util.List fNonterminalList
           
protected  java.util.Set fNonterminalParameters
           
protected  java.util.Set fNonterminalSet
           
protected  java.util.Map fNontermInstanceInPattern
           
protected  Subp[] fNontermPat
           
protected  int fNontermPatCount
           
protected  GlobalReform.NontermPatInstance fNontermPatInstanceOfCurrentPattern
           
protected  java.util.Map fOptionMap
           
protected  java.util.Map fOriginalVarMap
           
protected  java.util.Map fOutPatternMap
           
protected  double[] fPatternCodeLower
           
protected  double[] fPatternCodeUpper
           
protected  int fPatternCount
           
protected  java.util.List fPatternList
           
protected  java.util.Set fPatternParameters
           
protected  int fProductionCount
           
protected  java.util.Map fProductionMap
           
protected  int[] fProductionsInNonterminal
           
protected  int[] fStmt1CodeIndexFrom
           
protected  int[] fStmt1CodeIndexTo
           
protected  int[] fStmt2CodeIndexFrom
           
protected  int[] fStmt2CodeIndexTo
           
protected  java.util.Set fStmtParamSet
           
protected  int[] fStmtsInPattern
           
protected  java.util.List fSubpToReform
           
protected  int fSubrootCount
           
protected  Stmt fTailStmtMatched
           
protected  java.util.Map fTransparentMap
           
protected  boolean[] fUsedAsPatternRoot
           
protected  boolean[] fUsedAsSubRoot
           
protected  HIR hir
           
protected  HirRoot hirRoot
           
protected  IoRoot ioRoot
           
protected  SymRoot symRoot
           
 
コンストラクタの概要
GlobalReform(HirRoot pHirRoot)
          Constructor GlobalTransform.
 
メソッドの概要
protected  java.util.Map adjustMatchingData(GlobalReform.MatchingData pData, java.util.Map pParamCorresp)
          Get the HIR corresponding to pattern parameters that are given as keys of pParamCorresp which maps pattern parameters to primary HIR that may contain parameters.
protected  HIR adjustNonterminal(GlobalReform.MatchingData pData, GlobalReform.NontermPatInstance pNontermPatInstance, HIR pCallNode, java.util.Set pTraversedMatchingData, int pNthInstance, boolean pRevisedMatchingData)
          Change a nonterminal call to a plain HIR subtree that has resolved parameters and nonterminal calls by executing following steps: (1) Get the instance of MatchingData lData1 corresponding to the nonterminal call pCallNode.
protected  HIR adjustOutPattern(GlobalReform.MatchingData pData, HIR pOutHir, java.util.Set pTraversedMatchingData, int pNthInstance)
          Adjust the out pattern pOutHir corresponding to the pattern/nonterminal represented by pData, that is, If pOutHir is a pattern/nonterminal param node, then replace it by the HIR corresponding to it; If pOutHir represents a nonterminal, then replace it by the expanded HIR corresponding to it invoking adjustNonterminal with a MachingData obtained by copying pData; If pOutHir represents _reform(n_th_instance, patternParam, replacementExp, nonterminalCallExp), then expand the nonterminal and then replace the pattern parameter (patternParam) contained in it with replacementExp and then replace the pattern parameters according to the correspondence given in pData.
protected  HIR adjustType(Exp pExp, Type pType)
           
protected  boolean checkConsistency(Subp pPattern, java.util.List pLocalVarList, HIR pInPattern, HIR pOutPattern)
          Check the consistency of parameters in in-pattern and out-pattern.
protected  void computePatternCodeRange()
          computePatternCodeRange compute pattern code range (fPatternCodeUpper and fPatternCodeLower) of all patterns.
protected  GlobalReform.PatternCodeRange computePatternCodeRangeOf(HIR pHir)
          computePatternCodeRangeOf(.....) computes pattern code range of pHir and set upper to pUpper[0], loper to pLower[0].
protected  java.lang.String dbgMap(java.util.Map pMap)
          make the text string showing the contents of the map pMap.
protected  void dbgOut(int pLevel, java.lang.String pMessage)
           
protected  void dbgOut(int pLevel, java.lang.String pMessageClass, java.lang.String pMessage)
           
protected  java.lang.String dbgSet(java.util.Set pSet)
           
 boolean doReform(java.util.List pReformPatternList)
          doReform transforms subprograms listed up in #pragma globalReform target subp1 subp2 ...
protected  HIR evaluateReform(GlobalReform.MatchingData pData, HIR pOutHir, java.util.Set pTraversedMatchingData)
          Evaluate the special function _reform by calling reformByChangingParam( ... ) after examining given arguments.
protected  HIR expandExp(GlobalReform.MatchingData pData, HIR pExp, GlobalReform.NontermPatInstance pParentNonterm)
          Expand all nonterminal calls in pExp to the the expandedExp of the nonterminal instance corresponding to the nonterminal call.
protected  HIR expandNonterminal(GlobalReform.MatchingData pData, GlobalReform.NontermPatInstance pNontermPatInstance, HIR pCallExp, java.util.Set pTraversedNonterminals)
          expandNonterminal expands the right hand side of the selected productin of the nonterminal pNontermPatInstance and return it.
protected  HIR expandOutPattern(GlobalReform.MatchingData pData, HIR pOutHir, java.util.Set pTraversedNonterminals)
          expandOutPattern expands pOutHir according to pData.
protected  HIR getExpandedHir(HIR pCallExp, GlobalReform.NontermPatInstance pNontermInstance)
          Get the expanded HIR corresponding to pCallExp calling pNonterminal.
protected  java.util.Map getFormalActualParamCorrespondence(GlobalReform.MatchingData pData, GlobalReform.NontermPatInstance pNontermPat, HIR pCallNode, boolean pAdjustPhase)
          Get formal-actual parameter correspondence for the nonterminal pNontermPat that is called by the node pCallNode and return the correspondence.
(パッケージプライベート)  int getIndex(Subp pSubp)
          Get the index number of a pattern or a nonterminal.
protected  java.util.Set getLeafOperands(HIR pHir)
          Get the set of leaf operands of pHir.
protected  GlobalReform.NontermPatInstance getNontermInstance(Subp pNonterm, HIR pCallExp, GlobalReform.NontermPatInstance pParentInstance)
          Get the instance of the nonterminal pNonterm corresponding to the nonterminal call expression pCallExp seeing callToNontermInstanceMap of the parent nonterminal pParentInstance.
protected  Param getOriginalParam(Param pParam)
          Get the original parameter from which pParam is instanciated.
protected  Var getOriginalVar(Var pVar)
          Get the original variable from which pVar is instanciated.
protected  java.util.Map getParamCorrespForArgWithNonterm(GlobalReform.MatchingData pData, HIR pArgExp, Sym pCallerFormalParam, GlobalReform.NontermPatInstance pParentNonterm, boolean pAdjustPhase)
          Get formal-actual parameter correspondence for the formal parameter pCallerFormalParam and actual parameter pArgExp that calls child nonterminal.
protected  Param getParamInstance(Param pParam, GlobalReform.NontermPatInstance pNontermInstance)
          Get the parameter instanciated from pParam for the instance of the nonterminal pNontermInstance.
protected  Var getVarInstance(Var pVar, GlobalReform.NontermPatInstance pNontermInstance)
          Get the variable instanciated from pVar for the instance of the nonterminal pNontermInstance.
 java.lang.String hirToString(HIR pHir)
           
protected  Param instanciateParam(Subp pNonterm, Param pParam, int pInstanceNumber)
          Get a new instance of the parameter pParam used in the nonterminal pnonterm.
protected  Var instanciateVar(Subp pNonterm, Var pVar, int pKind, int pInstanceNumber)
          Get the new instance of the variable pVar.
protected  boolean isFittingSym(Sym pSym)
          If pSym is a fitting symbol or an instance of a fitting symbol, then return true, else return false.
protected  boolean isMatchedArray(GlobalReform.MatchingData pData, HIR pSubPattern, HIR pHir, GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
          isMatchedArray discriminates whether HIR subtree pHir matches with the pattern pSubPattern (in-pattern or part of in-pattern) comparing pHir with pSubPattern where pHir or pSubPattern may be an expression representing an array (vector) or array element.
protected  boolean isMatchedAssignStmt(GlobalReform.MatchingData pData, GlobalReform.NontermPatInstance pNontermInstance, HIR pNontermCall, HIR pHir, GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
          Examine whether the assign statement pHir matches with the pattern specified by _assignStmt.
protected  boolean isMatchedCondition(GlobalReform.MatchingData pData, HIR pSubPattern, HIR pHir, GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
          isMatchedCondition: Check comparison expression having different operation code, where either pSubPattern or pHir have comparison operator.
protected  boolean isMatchedNonterminal(GlobalReform.MatchingData pData, GlobalReform.NontermPatInstance pNontermInstance, HIR pNontermCall, HIR pHir, GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
          isMatchedNonterminal discriminates whether the nonterminal (pMetaSym) refered by pNonterminalCall matches with the input HIR tree pHir.
protected  boolean isMatchedPattern(GlobalReform.MatchingData pData, HIR pSubPattern, HIR pHir, GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
          isMatchedPattern discriminates whether HIR subtree pHir matches with the pattern pSubPattern (in-pattern or a part of in-pattern) comparing pHir with pSubPattern.
protected  boolean isMatchedStmtSeq(GlobalReform.MatchingData pData, HIR pSubPattern, Stmt pStmt, int pPatternIndex, GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
          isMatchedStmtSeq discriminates whether HIR subtree matches with the pattern pSubPattern (in-pattern or part of in-pattern) that is a sequence of statements comparing the statement sequence starting with pStmt.
protected  boolean isMatchedSubs(GlobalReform.MatchingData pData, HIR pSubPattern, HIR pHir, GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
          isMatchedSubs discriminates whether HIR subtree pHir matches with the pattern pSubPattern (in-pattern or part of in-pattern) comparing pHir with pSubPattern where pHir or pSubPattern may be an expression representing an array element.
protected  boolean isNontermParam(Sym pSym)
          If pSym is a nonterminal parameter or an instance of a nonterminal parameter, then return true, else return false.
protected  boolean isPatternParam(Sym pSym)
          If pSym is a pattern parameter or an instance of a pattern parameter, then return true, else return false.
protected  boolean isSameTree(HIR pTree1, HIR pTree2)
          isSameTree is a little different from that of coins.flow.HirSubpFlowImpl.
protected  boolean isTransparent(Var pDeclVar, HIR pHir, GlobalReform.MatchingData pData)
          If pDeclVar is declared as transparent to some variables and if pHir contains any of such variables or pDeclVar is included in pHir then pHir is treated as not transparent to pDeclVar
protected  void listUpHeadingHir(Subp pNontermPatSym, java.util.List pHeadingHirList, HIR pHir)
          List up top subtrees for pHir and add the subtrees to pHeadingHirList.
protected  HIR makeHirKey(HIR pExp)
          Make an HIR that can be used as a key of maps so that there is only one instance for each group of HIR subtrees where member subtrees have the same shape when they are included in the same group (keeping one to one correspondence between key and group).
protected  void makeParamCorrespComplete(GlobalReform.MatchingData pData)
          If a nonterminal param is mapped to a pattern param directly or indirectly (by tracing the sequence of nontermParam-to-nontermParam correspondence), then record the HIR corresponding to the nonterm parameter as the HIR corresponding to the pattern parameter.
protected  double patternCode(HIR pHir)
          Compute the pattern code of pHir digging out up to 2 levels of children.
(パッケージプライベート)  boolean postProcess(boolean pMatched, java.util.Map pGlobalPatternParamMap, GlobalReform.MatchingData pData)
          If matching failed, then restore fGlobalPatternParamMap by their previous value pGlobalPatternParamMap.
protected  void processTransparent(Subp pPattern, java.lang.String pOptionName, IrList pOptionList)
          Process the pragma specifications such as #pragma globalReform transparentFitting pc (pzz2, pi2) and record the transparency relations to fTransparentMap.
protected  void putToMap(java.util.Map pMap, Sym pSym, HIR pHir)
          Put the correspondence of pSym-pHir to pMap if it is not a circular reference that is, if pSym is not an operand of pHir.
protected  void recordExpandedHir(HIR pCallExp, HIR pExpandedHir, GlobalReform.NontermPatInstance pNontermPatInstance)
          Record the copy of pExpandedHir to fExpandedNontermInstance using pNontermPatInstance as key and fExpandedNonterm using makeHirKey(pCallExp) as key.
protected  boolean recordParamCorresp(GlobalReform.MatchingData pData, Sym pParam, HIR pHir)
          Record the correspondence between the parameter pParam and the (matched) input pHir.
protected  HIR reformByChangingParam(GlobalReform.MatchingData pData, HIR pNontermCall, HIR pParamNode, HIR pRewriteExp, java.util.Set pTraversedMatchingData, int pNthInstance)
          reformByChangingParam does the transformation specified by _reform(n_th_instance, patternParam, replacementExp, nonterminalCallExp)
protected  HIR replaceExpAdjustingType(Exp lOld, Exp lNew)
          Replace expression lOld by lNew adjusting type to that of lOld.
protected  HIR replaceHirTree(HIR pOld, HIR pNew)
          Replace pOld with pNew according to their kind.
protected  HIR replaceParameters(GlobalReform.MatchingData pData, HIR pOutHir, java.util.Set pTraversedMatchingData, boolean pNontermParamOnly)
          Replace nonterminal/pattern parameters and fitting symbols contained in pOutHi by the HIR correnponding to the parameters or fitting symbols where the correspondence is given by pData.
protected  HIR replaceStatementParameter(GlobalReform.MatchingData pData, SymNode pSymNode, java.util.Set pTraversedMatchingData, boolean pNontermParamOnly)
          Replace the node of statement parameter with the sequence of statements corresponding to it.
protected  void setNonterminalFlag(HIR pPattern)
          Set FLAG_NONTERMINAL to all call nodes that call _bnfOr, _bnfSeq, or _assignStmt contained in pPattern.
(パッケージプライベート)  int setPatternCodeRange(int pStartIndex, java.util.List pRangeList)
          Set the pattern code ranges in pRangeList to fPatternCodeUpper/Lower starting from pStartIndex and return the updated next index value.
protected  HIR traceParamCorresp(GlobalReform.MatchingData pData, Var pParamInstance, HIR pMatchedHir, boolean pAdjustPhase)
          Trace the sequence of nonterminal parameter replacement and return the HIR that corresponds to the parameter pParamInstance directly or indirectly.
protected  HIR traceParamCorrespSimply(GlobalReform.MatchingData pData, Var pParamInstance)
           
protected  HIR traceReplacementSeq(GlobalReform.MatchingData pData, Sym pParam, java.util.Set pTracedParam, java.util.Set pTraversedMatchingData, boolean pNontermParamOnly)
          traceReplacementSeq gets replica HIR that is used to replace pParam which may be either a nonterminal parameter or a pattern parameter.
protected  HIR transformByPatternSym(GlobalReform.MatchingData pData, Subp pPatternSym, HIR pInHir)
          transformByPatternSym transforms pInHir according to the pair of in-pattern and out-pattern defined by pPatternSym.
protected  HIR transformStmtSeq(GlobalReform.MatchingData pData, Subp pPatternSym, Stmt pInStmt)
          Transform the statement sequence beginning with pInStmt that matched with the statement pattern pPatternsym by applying adjustOutPattern to the corresponding out-pattern and then applying replaceParameters to the adjusted result.
protected  HIR tryToReform(GlobalReform.MatchingData pData, HIR pHir)
          Try to transform given HIR subtree pHir.
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

hirRoot

protected HirRoot hirRoot

symRoot

protected SymRoot symRoot

ioRoot

protected IoRoot ioRoot

fOptionMap

protected java.util.Map fOptionMap

fCoinsOptions

protected CoinsOptions fCoinsOptions

fPatternList

protected java.util.List fPatternList

fInPatternMap

protected java.util.Map fInPatternMap

fOutPatternMap

protected java.util.Map fOutPatternMap

fNonterminalList

protected java.util.List fNonterminalList

fNonterminalSet

protected java.util.Set fNonterminalSet

fProductionMap

protected java.util.Map fProductionMap

fFittingSet

protected java.util.Set fFittingSet

fTransparentMap

protected java.util.Map fTransparentMap

fPatternCount

protected int fPatternCount

fNontermPatCount

protected int fNontermPatCount

fSubrootCount

protected int fSubrootCount

fProductionCount

protected int fProductionCount

fNontermPat

protected Subp[] fNontermPat

fLocalVarListMap

protected java.util.Map fLocalVarListMap

fSubpToReform

protected java.util.List fSubpToReform

fStmtParamSet

protected java.util.Set fStmtParamSet

fNoFurtherChange

protected java.util.Set fNoFurtherChange

fCompileTimeEval

protected java.util.Set fCompileTimeEval

fFitToAnyCall

protected java.util.Set fFitToAnyCall

fCurrentPatternSym

protected Subp fCurrentPatternSym

fUsedAsPatternRoot

protected boolean[] fUsedAsPatternRoot

fUsedAsSubRoot

protected boolean[] fUsedAsSubRoot

fCodeIndexFrom

protected int[] fCodeIndexFrom

fCodeIndexTo

protected int[] fCodeIndexTo

fStmt1CodeIndexFrom

protected int[] fStmt1CodeIndexFrom

fStmt1CodeIndexTo

protected int[] fStmt1CodeIndexTo

fStmt2CodeIndexFrom

protected int[] fStmt2CodeIndexFrom

fStmt2CodeIndexTo

protected int[] fStmt2CodeIndexTo

fPatternCodeUpper

protected double[] fPatternCodeUpper

fPatternCodeLower

protected double[] fPatternCodeLower

fStmtsInPattern

protected int[] fStmtsInPattern

fPatternParameters

protected java.util.Set fPatternParameters

fNonterminalParameters

protected java.util.Set fNonterminalParameters

fProductionsInNonterminal

protected int[] fProductionsInNonterminal

fMaxStmtsInPattern

protected int fMaxStmtsInPattern

fNextStmtCode

protected double fNextStmtCode

fCurrentStmt

protected Stmt fCurrentStmt

fNextStmt

protected Stmt fNextStmt

fTailStmtMatched

protected Stmt fTailStmtMatched

fMatchingDataForNontermInstance

protected java.util.Map fMatchingDataForNontermInstance

fMatchingDataForNonterm

protected java.util.Map fMatchingDataForNonterm

fLastMatchingDataForNonterm

protected GlobalReform.MatchingData[] fLastMatchingDataForNonterm

fGlobalPatternParamMap

protected java.util.Map fGlobalPatternParamMap

fExpandedNontermInstance

protected java.util.Map fExpandedNontermInstance

fExpandedNonterm

protected java.util.Map fExpandedNonterm

fNontermPatInstanceOfCurrentPattern

protected GlobalReform.NontermPatInstance fNontermPatInstanceOfCurrentPattern

fHirKeys

protected java.util.Set fHirKeys

fFormalParams

protected java.util.Set[] fFormalParams

fInstanceNumberForNonterminals

protected int[] fInstanceNumberForNonterminals

fOriginalVarMap

protected java.util.Map fOriginalVarMap

fNontermInstanceInPattern

protected java.util.Map fNontermInstanceInPattern

fHirCodeLim

static double fHirCodeLim

fDontCareCode

static double fDontCareCode

fHirCodeLim2

static double fHirCodeLim2

fHirCodeLim3

static double fHirCodeLim3

fHirCodeLim4

static double fHirCodeLim4

fHirCodeLim5

static double fHirCodeLim5

fHirCodeLim6

static double fHirCodeLim6

fChanged

protected boolean fChanged

fDbgLevel

protected int fDbgLevel

hir

protected HIR hir
コンストラクタの詳細

GlobalReform

public GlobalReform(HirRoot pHirRoot)
Constructor GlobalTransform. Process pragmas #pragma globalReform patternSym pattern1 pattern2 ... #pragma globalReform target subp1 subp2 ... Make pattern map fPatternMap showing the correspondence of in-pattern and out-pattern checking the consistency of parameter usage in the pattern.

パラメータ:
pHirRoot - HirRoot conveyed.
メソッドの詳細

doReform

public boolean doReform(java.util.List pReformPatternList)
doReform transforms subprograms listed up in #pragma globalReform target subp1 subp2 ... replacing HIR subtrees matched with some in-pattern treating parameters in in-pattern and out-pattern properly. HIR body of patterns are set to empty block at exit so as to suppress further optimization and code generation for them.

パラメータ:
pReformPatternList - is empty at entry and contains all patterns specified by #pragma globalReform at exit.
戻り値:
true if HIR is changed by the transformation, false otherwise.

tryToReform

protected HIR tryToReform(GlobalReform.MatchingData pData,
                          HIR pHir)
Try to transform given HIR subtree pHir. If it matches with some in-pattern, then it is transformed to the form indicated by the out-pattern corresponding to the in-pattern. The matching process is done in 3 steps to speedup the matching. Case 1 - Pattern is one expression or one statement. step 1: operator of pHir is the same to the operator of root node of some in-pattern. step 2: pattern code of pHir is in the range of upper/lower pattern code of some in-pattern. step 3: Every nodes in pHir are the same to those of some in-pattern in the corresponding position except for parameters. Case 2 - Pattern is a sequence of statements step 1: operator of the first statement in pHir is the same to the operator of root node (or 1st statement) of some in-pattern. step 2: pattern codes of 1st statement and 2nd statement starting from pHir are in the range of upper/lower pattern codes of 1st statement and 2nd statement of some in-pattern, respectively. step 3: Every nodes in statement sequence starting from pHir are the same to those of some in-pattern in the corresponding position except for parameters. If the matched in-pattern is a sequence of stetements, fTailStmtMatched hold the statement of input statement sequence corresponding to the last statement of the matched in-pattern to show that the next pattern match is to be started from fTailStmtMatched.getNextStmt().

パラメータ:
pHir - HIR subtree to be transformed or statement from which matching is to be started.
戻り値:
transformed HIR subtree (that may be a block statement when the transformed result is a sequence of statements).

isMatchedPattern

protected boolean isMatchedPattern(GlobalReform.MatchingData pData,
                                   HIR pSubPattern,
                                   HIR pHir,
                                   GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
isMatchedPattern discriminates whether HIR subtree pHir matches with the pattern pSubPattern (in-pattern or a part of in-pattern) comparing pHir with pSubPattern. In the process of comparison, a parameter in pSubPattern is treated to match with any HIR expression of the same type or matches with any statement if the parameter is a statement parameter listed up in #pragma globalReform stmtParam The correspondence of parameter and HIR subtree located in the corresponding position is recorded in pData.paramCorresp or pData.nontermParamCorresp. The input expression/statement corresponding to the pattern is recorded in pData.expandedHir which may contain pattern parameter so that further replacement of the parameter is possible. In C language, array element expression has several variations such as subs-expression or pointer-expression. It makes the process of comparison and the process of replacement of parameters complicated. This problem is handled by isMatchedSubs (for subscripted variable expression), and isMatchedArray (for array expression).

パラメータ:
pData - matching data.
pSubPattern - in-pattern or part of in-pattern.
pHir - input expression/statement to be compared with pSubPattern.
pAncestorNontermPatInstance - ancestor instance of nonterminal or pattern.
戻り値:
true if pHir matched with pSubPattern false if no.

postProcess

boolean postProcess(boolean pMatched,
                    java.util.Map pGlobalPatternParamMap,
                    GlobalReform.MatchingData pData)
If matching failed, then restore fGlobalPatternParamMap by their previous value pGlobalPatternParamMap. If matching succeeded, then leave fGlobalPatternParamMap unchanged (in the updated status).

パラメータ:
pMatched - true if the matching succeeded, otherwise false.
pGlobalPatternParamMap - Previous pattern param mapping.
戻り値:
pMatched.

isMatchedSubs

protected boolean isMatchedSubs(GlobalReform.MatchingData pData,
                                HIR pSubPattern,
                                HIR pHir,
                                GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
isMatchedSubs discriminates whether HIR subtree pHir matches with the pattern pSubPattern (in-pattern or part of in-pattern) comparing pHir with pSubPattern where pHir or pSubPattern may be an expression representing an array element. In HIR corresponding to C language, array element may be represented as one of (subs subscriptExp) (subs (undecay pointerExp elemCount) subscriptExp) (contents (add pointerExp (mult elemSize subscriptExp))) and each combination of them should be considered in the comparison. isMatchedSubs does such comparison and record the correspondence of parameter in pSubPattern and the expression in pHir.

パラメータ:
pData - matching data.
pSubPattern - in-pattern or its subexpression.
pHir - part of input program to be matched.
pAncestorNontermPatInstance - ancestor instance of nonterminal or pattern.
戻り値:
true if pHir matched with pSubPattern.

isMatchedArray

protected boolean isMatchedArray(GlobalReform.MatchingData pData,
                                 HIR pSubPattern,
                                 HIR pHir,
                                 GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
isMatchedArray discriminates whether HIR subtree pHir matches with the pattern pSubPattern (in-pattern or part of in-pattern) comparing pHir with pSubPattern where pHir or pSubPattern may be an expression representing an array (vector) or array element. In HIR corresponding to C language, array and array element may be represented as one of (subs subscriptExp) (contents (add (mult elemSize subscriptExp))) (undecay pointerExp elemCount) (decay arrayExp) (addr variableExp) (subs subscriptExp) (subs (undecay pointerExp elemCount) subscriptExp) (contents (add pointerExp (mult elemSize subscriptExp))) and each combination of them should be considered in the comparison.

パラメータ:
pData - matching data.
pSubPattern - in-pattern or its subexpression.
pHir - part of input program to be matched.
pAncestorNontermPatInstance - ancestor instance of nonterminal or pattern.
戻り値:
true if pHir matched with pSubPattern.

isMatchedStmtSeq

protected boolean isMatchedStmtSeq(GlobalReform.MatchingData pData,
                                   HIR pSubPattern,
                                   Stmt pStmt,
                                   int pPatternIndex,
                                   GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
isMatchedStmtSeq discriminates whether HIR subtree matches with the pattern pSubPattern (in-pattern or part of in-pattern) that is a sequence of statements comparing the statement sequence starting with pStmt.

パラメータ:
pData - Maching data.
pSubPattern - Pattern taking the form of a sequence of statements.
pStmt - Statement from which comparison should take place.
pPatternIndex - Index assigned to the pattern (used to the number of statements in the pattern).
pAncestorNontermPatInstance - ancestor instance of nonterminal or pattern.
戻り値:
true if matched, false otherwise.

isMatchedCondition

protected boolean isMatchedCondition(GlobalReform.MatchingData pData,
                                     HIR pSubPattern,
                                     HIR pHir,
                                     GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
isMatchedCondition: Check comparison expression having different operation code, where either pSubPattern or pHir have comparison operator.

パラメータ:
pData - matching data.
pSubPattern - in-pattern or part of in-pattern.
pHir - input expression/statement to be compared with pSubPattern.
pAncestorNontermPatInstance - ancestor instance of nonterminal or pattern.
戻り値:
true if pHir matched with pSubPattern false if no.

isMatchedNonterminal

protected boolean isMatchedNonterminal(GlobalReform.MatchingData pData,
                                       GlobalReform.NontermPatInstance pNontermInstance,
                                       HIR pNontermCall,
                                       HIR pHir,
                                       GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
isMatchedNonterminal discriminates whether the nonterminal (pMetaSym) refered by pNonterminalCall matches with the input HIR tree pHir. A new instance of the nonterminal is made and all of its parameters are also instanciated so that the same nonterminal refered in the same form of call expression may match with different HIR if its instance differs. Similarly, the same parameter may have different actual parameter (matched input) if they have multiple instances. The input expression/statement corresponding to the pattern is recorded in pData.expandedHir which may contain pattern parameter so that further replacement of the parameter is possible.

パラメータ:
pData - MatchingData to be refered and updated in the matching.
pNontermInstance - Nonterminal instanciated for this call (pNontermCall) which may be defined nonterminal or meta symbol (_bnfOr, _bnfSeq, _reform).
pNontermCall - Expression calling pMetaSym.
pHir - Input HIR to be matched with the nonterminal.
pAncestorNontermPatInstance - Nonterminal instance in which body the current nonterminal is instanciated (by pNontermCall).
戻り値:
true if matched nonterminal.

isMatchedAssignStmt

protected boolean isMatchedAssignStmt(GlobalReform.MatchingData pData,
                                      GlobalReform.NontermPatInstance pNontermInstance,
                                      HIR pNontermCall,
                                      HIR pHir,
                                      GlobalReform.NontermPatInstance pAncestorNontermPatInstance)
Examine whether the assign statement pHir matches with the pattern specified by _assignStmt.

パラメータ:
pData - Matching data to be used.
pNontermInstance - Instance of the nonterminal (_assignStmt) representing the pattern.
pNontermCall - HIR expression calling _assignStmt.
pHir - HIR to be matched with the pattern.
pAncestorNontermPatInstance - Ancestor pattern or ancestor nonterminal.
戻り値:
true if matched, false otherwise.

transformByPatternSym

protected HIR transformByPatternSym(GlobalReform.MatchingData pData,
                                    Subp pPatternSym,
                                    HIR pInHir)
transformByPatternSym transforms pInHir according to the pair of in-pattern and out-pattern defined by pPatternSym. It is called from tryToReform. For each parameter in in-pattern, corresponding expression/statement in pInHir should be already recorded in pData by isMatchedPattern method. Usually, transformByPatternSym is invoked in tryToReform when an expression or statement is discriminated to be matched with some pattern by isMatchedPattern. The transformed result raise the flag FLAG_NOCHANGE to show that further optimization is not desirable. //REFINE

パラメータ:
pData - matching data.
pPatternSym - pattern symbol showing in-pattern and out-pattern to be used in transformation.
pInHir - a part of input program to be transformed.
戻り値:
HIR subtree generated as the result of the transformation.

expandOutPattern

protected HIR expandOutPattern(GlobalReform.MatchingData pData,
                               HIR pOutHir,
                               java.util.Set pTraversedNonterminals)
expandOutPattern expands pOutHir according to pData. Fitting symbols and nonterminal parameters are replaced by the corresponding HIR recorded in pData. If pOutHir contains a nonterminal call, a new instance of the nonterminal is created and its expansion is determinde by Nonterminal calls are replaced by the corresponding HIR determined by expandNonterminal (or getExpandedHir). Pattern parameters and other expressions contained in pOutHir are left unchanged.

パラメータ:
pData - Matching data to be used.
pOutHir - HIR to be expanded.
pTraversedNonterminals - Set of traverced nonterminal instances (used to avoid infinite loop).
戻り値:
the expanded result.

expandNonterminal

protected HIR expandNonterminal(GlobalReform.MatchingData pData,
                                GlobalReform.NontermPatInstance pNontermPatInstance,
                                HIR pCallExp,
                                java.util.Set pTraversedNonterminals)
expandNonterminal expands the right hand side of the selected productin of the nonterminal pNontermPatInstance and return it. If the result of previous expansion is recorded in pData, then return it. If it is a recursive call, do not expand.

パラメータ:
pData - MatchingData to be used.
pNontermPatInstance - Instance of a nonterminal.
pCallExp - Expression that calls the nonterminal.
pTraversedNonterminals - Set of traverced nonterminal instances (used to avoid infinite loop).
戻り値:
the expanded result.

adjustOutPattern

protected HIR adjustOutPattern(GlobalReform.MatchingData pData,
                               HIR pOutHir,
                               java.util.Set pTraversedMatchingData,
                               int pNthInstance)
Adjust the out pattern pOutHir corresponding to the pattern/nonterminal represented by pData, that is, If pOutHir is a pattern/nonterminal param node, then replace it by the HIR corresponding to it; If pOutHir represents a nonterminal, then replace it by the expanded HIR corresponding to it invoking adjustNonterminal with a MachingData obtained by copying pData; If pOutHir represents _reform(n_th_instance, patternParam, replacementExp, nonterminalCallExp), then expand the nonterminal and then replace the pattern parameter (patternParam) contained in it with replacementExp and then replace the pattern parameters according to the correspondence given in pData. If there are several nonterminal calls having the same form in a pattern definition, then the nonterminal instance corresponding to the i-th nonterminal call is selected where the sequence number i is given by the parameter pNthInstance. If pOutHir is a list, then replace each element by applying adjustOutPattern to the element; If pOutHir is a block, then replace each statement by applying adjustOutPattern to the statement; If pOutHir is other subtree, then replace each child by applying adjustOutPattern to the child;

パラメータ:
pData - Matching data to be used.
pOutHir - Out pattern corresponding to the pattern/nonterminal represented by pData (it is already a copy and unnecessary to be copied in this method).
pTraversedMatchingData - Set of traversed matching data to be used to avoid the application of the same matching data.
pNthInstance - Sequence number (0, 1, 2, ...) assigned to a nonterminal call to distinguish it from other nonterminal calls having the same form in the definiton of a pattern.
戻り値:
the adjusted HIR.

adjustNonterminal

protected HIR adjustNonterminal(GlobalReform.MatchingData pData,
                                GlobalReform.NontermPatInstance pNontermPatInstance,
                                HIR pCallNode,
                                java.util.Set pTraversedMatchingData,
                                int pNthInstance,
                                boolean pRevisedMatchingData)
Change a nonterminal call to a plain HIR subtree that has resolved parameters and nonterminal calls by executing following steps: (1) Get the instance of MatchingData lData1 corresponding to the nonterminal call pCallNode. Get the expanded Hir lExpandedHir corresponding to the nonterminal instance pNontermPatInstance. (2) Make the matching data complete, that is, trace the mapping sequence of nonterminal parameters and if it reaches to a pattern parameter, then make the nonterminal parameter corresponds to the HIR corresponding to the pattern parameter. (3) Get the expanded HIR corresponding to the nonterminal instance pNontermPatInstance. (4) Replace parameters in the expanded HIR. (5) Return the resultant expanded HIR. This is called from adjustOutPattern.

パラメータ:
pData - MatchingData instance to be used.
pNontermPatInstance - Nonterminal instance.
pCallNode - Nonterminal call node that instanciated pNontermPatInstance.
pTraversedMatchingData -
pNthInstance - Sequence number (0, 1, 2, ...) assigned to a nonterminal call to distinguish it from other nonterminal calls having the same form in the definiton of a pattern.
pRevisedMatchingData - true if pData is a revised one and unnecessary to use getMatchingData method.
戻り値:
Resultant HIR subtree adjusted.

evaluateReform

protected HIR evaluateReform(GlobalReform.MatchingData pData,
                             HIR pOutHir,
                             java.util.Set pTraversedMatchingData)
Evaluate the special function _reform by calling reformByChangingParam( ... ) after examining given arguments. The parameter pOutHir is an expanded HIR that may contain pattern parameters and _assignStmt function.

パラメータ:
pData - Matching data to be used.
pOutHir - expanded HIR to be transformed.
pTraversedMatchingData - Set of traversed matching data.
戻り値:
the transformed HIR.

adjustMatchingData

protected java.util.Map adjustMatchingData(GlobalReform.MatchingData pData,
                                           java.util.Map pParamCorresp)
Get the HIR corresponding to pattern parameters that are given as keys of pParamCorresp which maps pattern parameters to primary HIR that may contain parameters. The resultant HIR does not nontain parameters any more. In this processing, the correspondence of parameter replacement sequence is traced and if the HIR given by pData (as the one corresponding to a parameter) contains a parameter node, then the parameter node is replaced with corresponding HIR. (This method is called in adjustNonterminal.)

パラメータ:
pData - The instance of MatchingData to be used in tracing the correspondence of parameters.
pParamCorresp - Input correspondence of pattern parameters and replacement expressions.
戻り値:
Resultant correspondence of pattern parameters and replacement expressions.

traceReplacementSeq

protected HIR traceReplacementSeq(GlobalReform.MatchingData pData,
                                  Sym pParam,
                                  java.util.Set pTracedParam,
                                  java.util.Set pTraversedMatchingData,
                                  boolean pNontermParamOnly)
traceReplacementSeq gets replica HIR that is used to replace pParam which may be either a nonterminal parameter or a pattern parameter. If the HIR to be used to replace the parameter contains othter pattern/nonterminal parameters, then the contained parameters are replaced. This process continues successively until there remains no pattern/nonterminal parameters except the case where some parameter is contained in the replica HIR recursively.

パラメータ:
pData - Matching data used in the replacement.
pParam - a pattern parameter or a nonterminal parameter.
pTracedParam - Set of traced parameters.
pTraversedMatchingData - Set of traversed matching data.
pNontermParamOnly - true if replacement is to be done for nonterminal parameters and leave pattern parameters unchanged, false if both of pattern parameters and nonterminal parameters are to be replaced.
戻り値:
the replica to be used to replace pParam.

traceParamCorresp

protected HIR traceParamCorresp(GlobalReform.MatchingData pData,
                                Var pParamInstance,
                                HIR pMatchedHir,
                                boolean pAdjustPhase)
Trace the sequence of nonterminal parameter replacement and return the HIR that corresponds to the parameter pParamInstance directly or indirectly. The result will not contain nonterminal parameters but may contain pattern parameter or the result does not contain pattern/nonterminal parameters. pData.succeeded is set true if no discrepancy was found, false otherwise. At first, the sequence of nonterminal parameter replacement is traced. It stops to trace when a pattern parameter is reached or an HIR that is not a parameter node is reached. The 2nd phase differs according to the value of pAdjustPhase. If pAdjustPhase is false (called in matching phase), then if pParamInstance is a pattern parameter and the HIR corresponding to pParamInstance takes the same form as pMatchedHir, then the result is a parameter node representing pParamInstance and pData.succeeded is set true. If the HIR corresponding to pParamInstance has different form compared to pMatchedHir, then the result is a parameter node representing pParamInstance and pData.succeeded is false. If pAdjustPhase is true (called in adjustOutPattern directly or indirectly), then the result is the parameter node representing pParamInstance if pParamInstance is a pattern parameter or the result is the copy of pMatchedHir if not. In any case pData.succeeded is set true if pAdjustPhase is true.. The resultant HIR is adjusted according to the type of pParamInstance by applying decay/undecay/conv operation if necessary. If discrepancy was found in the above processing, then the the result may be wrong.

パラメータ:
pData - Matching data to be used in tracing the replacement sequence.
pParamInstance - Instance of nonterminal parameter or pattern parameter.
pMatchedHir - Input HIR that matched to pParam.
pAdjustPhase - true if called in adjustOutPattern/adjustNonterminal, false otherwize.
戻り値:
(copy of) the HIR corresponding to pParamInstance or a parameter node representing pParamInstance.

traceParamCorrespSimply

protected HIR traceParamCorrespSimply(GlobalReform.MatchingData pData,
                                      Var pParamInstance)

makeParamCorrespComplete

protected void makeParamCorrespComplete(GlobalReform.MatchingData pData)
If a nonterminal param is mapped to a pattern param directly or indirectly (by tracing the sequence of nontermParam-to-nontermParam correspondence), then record the HIR corresponding to the nonterm parameter as the HIR corresponding to the pattern parameter.

パラメータ:
pData - Matching data in which nontermParam-to-nontermParam correspondence is to be traced.

replaceParameters

protected HIR replaceParameters(GlobalReform.MatchingData pData,
                                HIR pOutHir,
                                java.util.Set pTraversedMatchingData,
                                boolean pNontermParamOnly)
Replace nonterminal/pattern parameters and fitting symbols contained in pOutHi by the HIR correnponding to the parameters or fitting symbols where the correspondence is given by pData. if (pOutHir instanceof SymNode) { if (it is a parameter or fitting symbol) { if (pNontermParamOnly&&(it is a pattern parameter)) { return pOutHir; // Do not replace pattern parameter. } It is a parameter or fitting symbol. Get the HIR subtree that corrresponds to the parameter in the form all parameters contained in it are already replaced by using traceReplacementSeq. if (its type is not VectorType) { Replace the node by the HIR subtree obtained by traceReplacementSeq. }else { It is an array parameter (parameter node of VectorType). Construct the resultant HIR subtree by replacing the parameter node or its parent expression considering that the array parameters may appear in such form as (subs subscriptExp) (subs (undecay varOfPointerType elemCount) subscriptExp) (contents (add (mult elemSize subscriptExp))) (decay arrayExp) (addr variableExp) (conv ) (list ... ) (list ... ) }else { Other symbol node. if (the symbol is a variable that is not defined in the subprogram under transformation) { (! lCorrespKeySet.contains(lSym))) { Generate a temporal variable and replace the variable node and register the correspondence in pParamCorresp. }else if (correspondence is given in pData) { Make the resultant expression by getting the expression corresponding to the symbol using pData. } } } // end of SymNode else if (pOutHir instanceof HirList) { Make a list by replacing all of its elements. }else if (pOutHir instanceof BlockStmt) { Make a block by replacing all statements contained in it. }else if (pOutHir instanceof LabeledStmt) { Make a labeled statement generating new label and replacing is body statement. }else { For other HIR having children, make the resultant HIR by replacing its children. } if (succeeded to get the resultant HIR lReplica) { return lReplica; }else { return pOutHir; }

パラメータ:
pData - Matching data giving the correspondence of parameters and HIR subtrees.
pOutHir - HIR subtree whose parameter nodes are to be replaced (copy should be given if original HIR subtree should not be changed).
pTraversedMatchingData - Set of matching data already traversed (used to escape from infinite loop).
pNontermParamOnly - Set true if only nonterminal parameter nodes are to be replaced and leave pattaern parameter nodes are to be left unchanged, set false if both of nonterminal/pattern parameter nodes are to be replaced.
戻り値:
the result of replacement (return pOutHir if no replacement is taken).

replaceStatementParameter

protected HIR replaceStatementParameter(GlobalReform.MatchingData pData,
                                        SymNode pSymNode,
                                        java.util.Set pTraversedMatchingData,
                                        boolean pNontermParamOnly)
Replace the node of statement parameter with the sequence of statements corresponding to it.

パラメータ:
pData - MatchingData to be used.
pSymNode - Statement parameter node.
pTraversedMatchingData - Set of matching data already traversed (used to escape from infinite loop).
pNontermParamOnly - Set true if only nonterminal parameter nodes are to be replaced and leave pattaern parameter nodes are to be left unchanged, set false if both of nonterminal/pattern parameter nodes are to be replaced.
戻り値:
The replaced result.

reformByChangingParam

protected HIR reformByChangingParam(GlobalReform.MatchingData pData,
                                    HIR pNontermCall,
                                    HIR pParamNode,
                                    HIR pRewriteExp,
                                    java.util.Set pTraversedMatchingData,
                                    int pNthInstance)
reformByChangingParam does the transformation specified by _reform(n_th_instance, patternParam, replacementExp, nonterminalCallExp). (1) Get the nonterminal instance specified by nonterminalCallExp and n_th_instance. (2) Get the matching data corresponding to the nonterminal instance. (2) Replace all parameter nodes same as pParamNode in pRewriteExp by the corresponding HIR given by the matching data and record the revised rewrite-expression as the new HIR corresponding to the parameter in local MatchingData. pRewriteExp may contain pattern parameters and _assignStmt function. (3) Adjust the expanded HIR of the nonterminal instance using the revised local MatchingData (by adjustnonterminal). (4) Return the result of adjustNonterminal. (This method is called in adjustOutPattern.)

パラメータ:
pData - Matching data to be used.
pNontermCall - Nonterminal call expression specified in _reform expression.
pParamNode - Parameter node to be rewritten as as specified in _reform expression.
pRewriteExp - HIR to be used to replace pParamNode as specified in _reform expression.
pTraversedMatchingData - Set of matching data already traversed (used to convey information to adjustNonterminal).
pNthInstance - Sequence number of nonterminal instance among the instances having the same form of call expression in the in-pattern.
戻り値:
The resultant HIR subtree for the given _reform expression.

transformStmtSeq

protected HIR transformStmtSeq(GlobalReform.MatchingData pData,
                               Subp pPatternSym,
                               Stmt pInStmt)
Transform the statement sequence beginning with pInStmt that matched with the statement pattern pPatternsym by applying adjustOutPattern to the corresponding out-pattern and then applying replaceParameters to the adjusted result. At return, fTailStmtMatched represents the last statement in the matched input statement sequence. (This method is called in tryToReform.)

パラメータ:
pData - MatchingData instance to be used.
pPatternSym - Pattern symbol representing a statement pattern.
pInStmt - Heading statement of the matched statement sequence.
戻り値:
The resultant HIR.

getFormalActualParamCorrespondence

protected java.util.Map getFormalActualParamCorrespondence(GlobalReform.MatchingData pData,
                                                           GlobalReform.NontermPatInstance pNontermPat,
                                                           HIR pCallNode,
                                                           boolean pAdjustPhase)
Get formal-actual parameter correspondence for the nonterminal pNontermPat that is called by the node pCallNode and return the correspondence. If the caller argument contains child nonterminal call, then formal-actual parameter correspondence for the child nonterminal is computed by getParamCorrespForArgWithNonterm. The result is not reflected to pData in this method.

パラメータ:
pData - MatchingData inherited.
pNontermPat - nonterminal instance.
pCallNode - Node calling the nonterminal.
pAdjustPhase - True if called in adjust phase, false otherwise.
戻り値:
the resultant correspondence.

getParamCorrespForArgWithNonterm

protected java.util.Map getParamCorrespForArgWithNonterm(GlobalReform.MatchingData pData,
                                                         HIR pArgExp,
                                                         Sym pCallerFormalParam,
                                                         GlobalReform.NontermPatInstance pParentNonterm,
                                                         boolean pAdjustPhase)
Get formal-actual parameter correspondence for the formal parameter pCallerFormalParam and actual parameter pArgExp that calls child nonterminal. The matching data pData is not changed.

パラメータ:
pData - Inherited MatchingData.
pArgExp - Actual parameter that calls child nonterminal.
pCallerFormalParam - Formal parameter corresponding to pArgExp.
pParentNonterm - Nonterminal that calls the child nonterminal.
戻り値:
formal-actual parameter correspondence.

expandExp

protected HIR expandExp(GlobalReform.MatchingData pData,
                        HIR pExp,
                        GlobalReform.NontermPatInstance pParentNonterm)
Expand all nonterminal calls in pExp to the the expandedExp of the nonterminal instance corresponding to the nonterminal call. (Called in getFormalActualParamCorrespondence.)

パラメータ:
pData - MatchingData to be used.
pExp - HIR to be expanded.
pParentNonterm - Nonterminal instance
戻り値:
the resultant expanded HIR.

checkConsistency

protected boolean checkConsistency(Subp pPattern,
                                   java.util.List pLocalVarList,
                                   HIR pInPattern,
                                   HIR pOutPattern)
Check the consistency of parameters in in-pattern and out-pattern. Any of following cases are treated as inconsistent usage: Some parameter in the out-pattern does not appear in the in-pattern. Some parameter in the in-pattern does not appear in the out-pattern.

パラメータ:
pPattern - subprogram representing a pattern.
pLocalVarList - list of variables declared locally in pOutPattern.
pInPattern - in-pattern.
pOutPattern - out-pattern.
戻り値:
true if no inconsistency is found, false if some inconsistency is found.

patternCode

protected double patternCode(HIR pHir)
Compute the pattern code of pHir digging out up to 2 levels of children.

パラメータ:
pHir - geven HIR subtree.
戻り値:
pattern code of pHir.

computePatternCodeRange

protected void computePatternCodeRange()
computePatternCodeRange compute pattern code range (fPatternCodeUpper and fPatternCodeLower) of all patterns. If the pattern is a block statement containing multiple statements, then compute code range of its 1st statement and 2nd statement (fStmt1CodeUpper/Lower and fStmt2CodeUpper/Lower) and the number of statements in the pattern (fStmtsInPattern). The pattern code of HIR subtree c0 --- c1 --- c11 | |-- c12 | |-- c2 --- c21 |-- c22 is computed as c0*L*L*L*L*L*L + c1*L*L*L*L*L + c2*L*L*L*L + c11*L*L*L + c12*L*L + c21*L + c22 where, c0, c1, etc. are operator code and L is fHirCodeLim (greater than any HIR operator code). If some child in above tree is a parameter, then fDontCareCode (greater than any opCode) is used as its operator code for computing upper code and 0 is used as its operator (corresponding to the case where the child is null) for computing lower code.


computePatternCodeRangeOf

protected GlobalReform.PatternCodeRange computePatternCodeRangeOf(HIR pHir)
computePatternCodeRangeOf(.....) computes pattern code range of pHir and set upper to pUpper[0], loper to pLower[0].

パラメータ:
pHir - HIR for which the pattern code range is to be computed.

setPatternCodeRange

int setPatternCodeRange(int pStartIndex,
                        java.util.List pRangeList)
Set the pattern code ranges in pRangeList to fPatternCodeUpper/Lower starting from pStartIndex and return the updated next index value.

パラメータ:
pStartIndex - start position to store the pattern codes.
pRangeList - list of pattern codes.
戻り値:
the updated next position.

replaceExpAdjustingType

protected HIR replaceExpAdjustingType(Exp lOld,
                                      Exp lNew)
Replace expression lOld by lNew adjusting type to that of lOld.

パラメータ:
lOld - old expression to be replaced.
lNew - new expression for replacement.
戻り値:
replaced expression.

adjustType

protected HIR adjustType(Exp pExp,
                         Type pType)

replaceHirTree

protected HIR replaceHirTree(HIR pOld,
                             HIR pNew)
Replace pOld with pNew according to their kind. If isSameTree(pOld,pNew), do not replace.

パラメータ:
pOld - Old HIR to be replaced.
pNew - New HIR used to replace.
戻り値:
the replaced result.

isSameTree

protected boolean isSameTree(HIR pTree1,
                             HIR pTree2)
isSameTree is a little different from that of coins.flow.HirSubpFlowImpl.

パラメータ:
pTree1 - HIR tree to be compared.
pTree2 - Another HIR tree to be compared.
戻り値:
true if pTree1 and pTree2 have the same shape and contents, false otherwise.

processTransparent

protected void processTransparent(Subp pPattern,
                                  java.lang.String pOptionName,
                                  IrList pOptionList)
Process the pragma specifications such as #pragma globalReform transparentFitting pc (pzz2, pi2) and record the transparency relations to fTransparentMap.

パラメータ:
pPattern - Pattern symbol.
pOptionName - Option name ("transparentFitting", etc.).
pOptionList - List of the transparency relation.

setNonterminalFlag

protected void setNonterminalFlag(HIR pPattern)
Set FLAG_NONTERMINAL to all call nodes that call _bnfOr, _bnfSeq, or _assignStmt contained in pPattern.

パラメータ:
pPattern - HIR to which nodes nonterminal flag is to be attached.

getIndex

int getIndex(Subp pSubp)
Get the index number of a pattern or a nonterminal.

パラメータ:
pSubp - is a pattern or a nonterminal.
戻り値:
the index value.

isTransparent

protected boolean isTransparent(Var pDeclVar,
                                HIR pHir,
                                GlobalReform.MatchingData pData)
If pDeclVar is declared as transparent to some variables and if pHir contains any of such variables or pDeclVar is included in pHir then pHir is treated as not transparent to pDeclVar

パラメータ:
pDeclVar - variable that should be transparent.
pHir - HIR to be examined.
戻り値:
true if tranparent.

getLeafOperands

protected java.util.Set getLeafOperands(HIR pHir)
Get the set of leaf operands of pHir. Constant operands are excluded.

パラメータ:
pHir - HIR subtree.
戻り値:
the set of leaf operands.

listUpHeadingHir

protected void listUpHeadingHir(Subp pNontermPatSym,
                                java.util.List pHeadingHirList,
                                HIR pHir)
List up top subtrees for pHir and add the subtrees to pHeadingHirList. A pattern or nonterminal may have multiple top subtrees if the right-hand side of their production begins with _bnfOr or begins with a nonterminal having multiple top subtrees.

パラメータ:
pNontermPatSym - pattern symbol or nonterminal symbol.
pHeadingHirList - is a list to which top subtrees are to be added.
pHir - is the right-hand side of the production corresponding to the pattern or the nonterminal.

recordParamCorresp

protected boolean recordParamCorresp(GlobalReform.MatchingData pData,
                                     Sym pParam,
                                     HIR pHir)
Record the correspondence between the parameter pParam and the (matched) input pHir. This method also records matchedInput and expandedHir to pData.

パラメータ:
pData - matching data inherited.
pParam - symbol that may be (1) a pattern/nonterminal parameter instance or (2) a pattern symbol itself representing recursive function or (3) a fitting symbol instance.
pHir - input HIR that is treaded as matched with pParam.
戻り値:
true if correspondence was found false if not found.

putToMap

protected void putToMap(java.util.Map pMap,
                        Sym pSym,
                        HIR pHir)
Put the correspondence of pSym-pHir to pMap if it is not a circular reference that is, if pSym is not an operand of pHir. If the correspondence is not recorded in fGlobalPatternParamMap, then record it. If pSym is recorded in fGlobalPatternParamMap as different tree, then "Inconsistent with previous value" message is issued.

パラメータ:
pMap - map to record the correspondence.
pSym - variable (usually a parameter instance).
pHir - HIR subtree that corresponds to pSym.

dbgOut

protected void dbgOut(int pLevel,
                      java.lang.String pMessage)

dbgOut

protected void dbgOut(int pLevel,
                      java.lang.String pMessageClass,
                      java.lang.String pMessage)

dbgMap

protected java.lang.String dbgMap(java.util.Map pMap)
make the text string showing the contents of the map pMap.

パラメータ:
pMap - Map to be displayed in the form of text string.
戻り値:
the resultant test string.

dbgSet

protected java.lang.String dbgSet(java.util.Set pSet)

hirToString

public java.lang.String hirToString(HIR pHir)

recordExpandedHir

protected void recordExpandedHir(HIR pCallExp,
                                 HIR pExpandedHir,
                                 GlobalReform.NontermPatInstance pNontermPatInstance)
Record the copy of pExpandedHir to fExpandedNontermInstance using pNontermPatInstance as key and fExpandedNonterm using makeHirKey(pCallExp) as key.

パラメータ:
pCallExp - call expression for the nonterminal.
pExpandedHir - expanded HIR for the nonterminal.
pNontermPatInstance - nonterminal instance.

getExpandedHir

protected HIR getExpandedHir(HIR pCallExp,
                             GlobalReform.NontermPatInstance pNontermInstance)
Get the expanded HIR corresponding to pCallExp calling pNonterminal. The same nonterminal may have different expansion according to its actual parameter list. //##86 REFINE Is there anay case where call expressions // of the same type has different expansion ?

パラメータ:
pCallExp - expression calling pNonterminal.
戻り値:
the expanded HIR corresponding to pCallExp.

makeHirKey

protected HIR makeHirKey(HIR pExp)
Make an HIR that can be used as a key of maps so that there is only one instance for each group of HIR subtrees where member subtrees have the same shape when they are included in the same group (keeping one to one correspondence between key and group).

パラメータ:
pExp - HIR subtree to which key is to be searched.
戻り値:
the key corresponding to the group to which pExp belongs.

getNontermInstance

protected GlobalReform.NontermPatInstance getNontermInstance(Subp pNonterm,
                                                             HIR pCallExp,
                                                             GlobalReform.NontermPatInstance pParentInstance)
Get the instance of the nonterminal pNonterm corresponding to the nonterminal call expression pCallExp seeing callToNontermInstanceMap of the parent nonterminal pParentInstance. If it is not found then look for the ancestor of the parent (parent of the parent, etc.). (This method is refered in expandExp.)

パラメータ:
pNonterm - Nonterminal symbol.
pCallExp - Nonterminal call expression.
pParentInstance - Instance of parent nonterminal or pattern whose definition body contains the nonterminal call pCallExp.
戻り値:
the nonterminal instance.

instanciateParam

protected Param instanciateParam(Subp pNonterm,
                                 Param pParam,
                                 int pInstanceNumber)
Get a new instance of the parameter pParam used in the nonterminal pnonterm.

パラメータ:
pNonterm - Nonterminal symbol.
pParam - Formal parameter of pNonterm.
pInstanceNumber - Instance number.
戻り値:
the instanciated parameter.

instanciateVar

protected Var instanciateVar(Subp pNonterm,
                             Var pVar,
                             int pKind,
                             int pInstanceNumber)
Get the new instance of the variable pVar.

パラメータ:
pNonterm - Nonterminal containing the variable pVar.
pVar - Variable symbol.
pKind - Symbol kind of the variable.
pInstanceNumber - Instance number within the nonterminal (this parameter is not yet used).
戻り値:
the instanciated variable.

getParamInstance

protected Param getParamInstance(Param pParam,
                                 GlobalReform.NontermPatInstance pNontermInstance)
Get the parameter instanciated from pParam for the instance of the nonterminal pNontermInstance. (Formal parameters are instanciated for each nonterminal instance.)

パラメータ:
pParam - Formal parameter from which new parameter is instanciated.
pNontermInstance - Instance of a nonterminal.
戻り値:
the instance of the parameter.

getVarInstance

protected Var getVarInstance(Var pVar,
                             GlobalReform.NontermPatInstance pNontermInstance)
Get the variable instanciated from pVar for the instance of the nonterminal pNontermInstance. (Local variables (including formal parameters) are instanciated for each nonterminal instance.) If not found, then search among variables instanciated for ancestor nonterminal instances.

パラメータ:
pVar - Variable from which new variable is instanciated.
pNontermInstance - Instance of a nonterminal.
戻り値:
the instance of the variable.

getOriginalParam

protected Param getOriginalParam(Param pParam)
Get the original parameter from which pParam is instanciated. If pParam is already the original parameter, then return it.

パラメータ:
pParam - Instance of a formal parameter.
戻り値:
the original parameter.

getOriginalVar

protected Var getOriginalVar(Var pVar)
Get the original variable from which pVar is instanciated. If pVar is already the original variable, then return it.

パラメータ:
pVar - Instance of a variable.
戻り値:
the original variable.

isPatternParam

protected boolean isPatternParam(Sym pSym)
If pSym is a pattern parameter or an instance of a pattern parameter, then return true, else return false.

パラメータ:
pSym - Symbol to be examined.
戻り値:
true or false.

isNontermParam

protected boolean isNontermParam(Sym pSym)
If pSym is a nonterminal parameter or an instance of a nonterminal parameter, then return true, else return false.

パラメータ:
pSym - Symbol to be examined.
戻り値:
true or false.

isFittingSym

protected boolean isFittingSym(Sym pSym)
If pSym is a fitting symbol or an instance of a fitting symbol, then return true, else return false.

パラメータ:
pSym - Symbol to be examined.
戻り値:
true or false.