coins.opt
クラス GlobalReform

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

public class GlobalReform
extends java.lang.Object


入れ子クラスの概要
protected  class GlobalReform.MatchingData
           
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  Subp fCurrentPatternSym
           
protected  Stmt fCurrentStmt
           
protected  int fDbgLevel
           
(パッケージプライベート) static double fDontCareCode
           
protected  java.util.Map fExpandedNonterm
           
protected  java.util.Set fFittingSet
           
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  boolean fInconsistentMapping
           
protected  java.util.Map fInPatternMap
           
protected  java.util.Map[] fInputForArgList
           
protected  HIR[] fLastExpandedNonterm
           
protected  GlobalReform.MatchingData[] fLastMatchingDataForNonterm
           
protected  java.util.Map fLocalVarListMap
           
protected  java.util.Map fMatchingDataForNonterm
           
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  Subp[] fNontermPat
           
protected  int fNontermPatCount
           
protected  java.util.Map fOptionMap
           
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)
           
protected  HIR adjustNonterminal(GlobalReform.MatchingData pData, Subp pNonterminal, HIR pCallNode, java.util.Set pTraversedMatchingData)
           
protected  HIR adjustOutPattern(GlobalReform.MatchingData pData, HIR pOutHir, java.util.Set pTraversedMatchingData)
           
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)
           
protected  void dbgOut(int pLevel, java.lang.String pMessage)
           
protected  void dbgOut(int pLevel, java.lang.String pMessageClass, java.lang.String pMessage)
           
 boolean doReform(java.util.List pReformPatternList)
          doReform transforms subprograms listed up in #pragma globalReform target subp1 subp2 ...
protected  HIR expandNonterminal(GlobalReform.MatchingData pData, Subp pNonterminal, HIR pCallExp, java.util.Set pTraversedNonterminal)
           
protected  HIR expandOutPattern(GlobalReform.MatchingData pData, HIR pOutHir, java.util.Set pTraversedNonterminal)
           
protected  HIR getExpandedHir(HIR pCallExp, Subp pNonterminal)
           
protected  java.util.Map getFormalActualParamCorrespondence(GlobalReform.MatchingData pData, Subp 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  HIR getMatchedInputForNonterm(GlobalReform.MatchingData pData, HIR pNontermCall, Subp pNonterminal)
           
protected  java.util.Map getParamCorrespForArgWithNonterm(GlobalReform.MatchingData pData, HIR pArgExp, Sym pCallerFormalParam, Sym pParentNonterm, boolean pAdjustPhase)
          Get formal-actual parameter correspondence for the formal parameter pCallerFormalParam and actual parameter pArgExp that calls child nonterminal.
protected  Exp integralPromotion(int pOperator, Exp pOperand1)
           
protected  Exp integralPromotion(int pOperator, Exp pOperand1, Exp pOperand2)
           
protected  boolean isMatchedArray(GlobalReform.MatchingData pData, HIR pSubPattern, HIR pHir, HIR pAncestorCallNode)
          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 isMatchedCondition(GlobalReform.MatchingData pData, HIR pSubPattern, HIR pHir, HIR pAncestorCallNode)
          isMatchedCondition: Check comparison expression having different operation code, where either pSubPattern or pHir have comparison operator.
protected  boolean isMatchedNonterminal(GlobalReform.MatchingData pData, Sym pMetaSym, HIR pNontermCall, HIR pHir, HIR pBnfCallNode)
           
protected  boolean isMatchedPattern(GlobalReform.MatchingData pData, HIR pSubPattern, HIR pHir, HIR pAncestorCallNode)
          isMatchedPattern discriminates whether HIR subtree pHir matches with the pattern pSubPattern (in-pattern or part of in-pattern) comparing pHir with pSubPattern.
protected  boolean isMatchedStmtSeq(GlobalReform.MatchingData pData, HIR pSubPattern, Stmt pStmt, int pPatternIndex, HIR pAncestorCallNode)
           
protected  boolean isMatchedSubs(GlobalReform.MatchingData pData, HIR pSubPattern, HIR pHir, HIR pAncestorCallNode)
          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 isSameTree(HIR pTree1, HIR pTree2)
          isSameTree is a little different from that of coins.flow.HirSubpFlowImpl.
protected  boolean isTransparent(Var pDeclVar, HIR pHir)
          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  AssignStmt makeAssignStmt(Var pVariable, Exp pExp)
           
protected  HIR makeHirKey(HIR pExp)
           
protected  void makeParamCorrespComplete(GlobalReform.MatchingData pData)
           
protected  HIR matchInput(GlobalReform.MatchingData pData, Subp pPatternSym, HIR pOutHir, java.util.Map pParamRewrite)
          transform the expression/statement pOutHir according to pParamCorresp and pArrayCorresp, where pOutHir is an out-pattern or a part of out-pattern and the maps pParamCorresp and pArrayCorresp show the expression/ statement corresponding to each parameter in pOutHir.
protected  HIR matchInputStmtSeq(GlobalReform.MatchingData pData, Subp pPatternSym, Stmt pInStmt, java.util.Map pParamRewrite)
          matchInputStmtSeq transforms a sequence of statements starting at pInStmt by the in-pattern pPatternSym generating a statement (usually a block statement containing the sequence of statements) corresponding to the pattern.
protected  HIR matchInputWithNonterm(GlobalReform.MatchingData pData, HIR pOutHir, Subp pNonterminal, java.util.Map pParamRewrite)
           
protected  java.util.Map mismatch(java.util.Map pParamCorresp, HIR pInPattern, HIR pInHir)
           
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, boolean pInconsistentMapping)
           
protected  void processTransparent(Subp pPattern, java.lang.String pOptionName, IrList pOptionList)
           
 void putMessage(int pLevel, java.lang.String pMessage)
           
protected  void putToMap(java.util.Map pMap, Sym pSym, HIR pHir)
           
protected  void recordExpandedHir(HIR pCallExp, HIR pExpandedHir, Subp pNonterminal)
           
protected  boolean recordParamCorresp(GlobalReform.MatchingData pData, Sym pParam, HIR pHir)
          Record the correspondence between the parameter pParam and the (matched) input pHir.
protected  HIR replaceExpAdjustingType(Exp lOld, Exp lNew)
          Replace expression lOld by lNew adjusting type to that of lOld.
protected  HIR replaceHirTree(HIR lOld, HIR lNew)
           
protected  HIR replaceParameters(GlobalReform.MatchingData pData, HIR pOutHir, java.util.Set pTraversedMatchingData, boolean pNontermParamOnly)
           
protected  HIR replaceStatementParameter(GlobalReform.MatchingData pData, SymNode pSymNode, java.util.Set pTraversedMatchingData, boolean pNontermParamOnly)
           
protected  void setNonterminalFlag(HIR pPattern)
          Set FLAG_NONTERMINAL to all call nodes that call _bnfOr or _bnfSeq 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  boolean shouldChangeParamNode(GlobalReform.MatchingData pData, Param pParam, HIR pParamReplacer, java.util.Map pRewriteCorresp)
          Change pParam contained in pParamReplacer to pParamMod and return the changed pParamReplacer.
protected  HIR traceParamCorresp(GlobalReform.MatchingData pData, Var pParam, HIR pMatchedHir, boolean pAdjustPhase)
          Trace the sequence of nonterminal parameter replacement and return the HIR that corresponds to the parameter pParam.
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, java.util.Map pParamRewrite)
           
protected  HIR tryToReform(GlobalReform.MatchingData pData, HIR pHir)
          Try to transform given HIR subtree pHir.
protected  Type typeForArithmeticExp(Type pType)
           
 
クラス 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

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

fMatchingDataForNonterm

protected java.util.Map fMatchingDataForNonterm

fLastMatchingDataForNonterm

protected GlobalReform.MatchingData[] fLastMatchingDataForNonterm

fGlobalPatternParamMap

protected java.util.Map fGlobalPatternParamMap

fInconsistentMapping

protected boolean fInconsistentMapping

fExpandedNonterm

protected java.util.Map fExpandedNonterm

fLastExpandedNonterm

protected HIR[] fLastExpandedNonterm

fInputForArgList

protected java.util.Map[] fInputForArgList

fHirKeys

protected java.util.Set fHirKeys

fFormalParams

protected java.util.Set[] fFormalParams

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 -
メソッドの詳細

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,
                                   HIR pAncestorCallNode)
isMatchedPattern discriminates whether HIR subtree pHir matches with the pattern pSubPattern (in-pattern or 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 pParamCorresp. 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. To solve the problem, the correspondence of array elements in pSubPattern and pHir is recorded in pArrayCorresp so that it is treated in different mannar. Note that the parameter and corresponding expression should be registered in pArrayCorresp as the node (position) in pSubPattern and in pHir so that upper construct containing the parameter and expression can be traced in further processing.

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

postProcess

boolean postProcess(boolean pMatched,
                    java.util.Map pGlobalPatternParamMap,
                    boolean pInconsistentMapping)

isMatchedSubs

protected boolean isMatchedSubs(GlobalReform.MatchingData pData,
                                HIR pSubPattern,
                                HIR pHir,
                                HIR pAncestorCallNode)
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.
戻り値:
true if pHir matched with pSubPattern.

isMatchedArray

protected boolean isMatchedArray(GlobalReform.MatchingData pData,
                                 HIR pSubPattern,
                                 HIR pHir,
                                 HIR pAncestorCallNode)
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.
戻り値:
true if pHir matched with pSubPattern.

isMatchedStmtSeq

protected boolean isMatchedStmtSeq(GlobalReform.MatchingData pData,
                                   HIR pSubPattern,
                                   Stmt pStmt,
                                   int pPatternIndex,
                                   HIR pAncestorCallNode)

isMatchedCondition

protected boolean isMatchedCondition(GlobalReform.MatchingData pData,
                                     HIR pSubPattern,
                                     HIR pHir,
                                     HIR pAncestorCallNode)
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.
戻り値:
true if pHir matched with pSubPattern false if no.

isMatchedNonterminal

protected boolean isMatchedNonterminal(GlobalReform.MatchingData pData,
                                       Sym pMetaSym,
                                       HIR pNontermCall,
                                       HIR pHir,
                                       HIR pBnfCallNode)

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. For each parameter in in-pattern, corresponding expression/statement in pInHir should be already recorded in pParamCorresp and pArrayCorresp 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 has 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 transformation.

expandOutPattern

protected HIR expandOutPattern(GlobalReform.MatchingData pData,
                               HIR pOutHir,
                               java.util.Set pTraversedNonterminal)

expandNonterminal

protected HIR expandNonterminal(GlobalReform.MatchingData pData,
                                Subp pNonterminal,
                                HIR pCallExp,
                                java.util.Set pTraversedNonterminal)

adjustOutPattern

protected HIR adjustOutPattern(GlobalReform.MatchingData pData,
                               HIR pOutHir,
                               java.util.Set pTraversedMatchingData)

adjustNonterminal

protected HIR adjustNonterminal(GlobalReform.MatchingData pData,
                                Subp pNonterminal,
                                HIR pCallNode,
                                java.util.Set pTraversedMatchingData)

adjustMatchingData

protected java.util.Map adjustMatchingData(GlobalReform.MatchingData pData,
                                           java.util.Map pParamCorresp)

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 pParam,
                                HIR pMatchedHir,
                                boolean pAdjustPhase)
Trace the sequence of nonterminal parameter replacement and return the HIR that corresponds to the parameter pParam. If discrepancy was found in the replacement sequence, then the replacement sequence stops and The result will not contain nonterminal parameters but may contain pattern parameter or the result does not contain pattern/nonterminal parameters.

パラメータ:
pData - Matching data to be used in tracing the replacement sequence.
pParam - 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 pParam.

makeParamCorrespComplete

protected void makeParamCorrespComplete(GlobalReform.MatchingData pData)

replaceParameters

protected HIR replaceParameters(GlobalReform.MatchingData pData,
                                HIR pOutHir,
                                java.util.Set pTraversedMatchingData,
                                boolean pNontermParamOnly)

replaceStatementParameter

protected HIR replaceStatementParameter(GlobalReform.MatchingData pData,
                                        SymNode pSymNode,
                                        java.util.Set pTraversedMatchingData,
                                        boolean pNontermParamOnly)

matchInput

protected HIR matchInput(GlobalReform.MatchingData pData,
                         Subp pPatternSym,
                         HIR pOutHir,
                         java.util.Map pParamRewrite)
transform the expression/statement pOutHir according to pParamCorresp and pArrayCorresp, where pOutHir is an out-pattern or a part of out-pattern and the maps pParamCorresp and pArrayCorresp show the expression/ statement corresponding to each parameter in pOutHir. This method is called from transformByPatternSym to transform the out-pattern corresponding to the in-pattern that is selected as the pattern matching to a part of input program, or called from the method transform recursively to transform a part of out-pattern. In the process of transfromation, each parameter encountered in pOutHir is replaced with the expression/statement that is located at the position of the parameter in in-pattern as it is registered in pParamCorresp or pArrayCorresp. Parameters registered in pParamCorresp are replaced with the copy of corresponding expression/statement registered in pParamCorresp. As for a parameter registered in pArrayCorresp, at first, array element expression containing the parameter is looked for in the in-pattern and the expression located at the array element expression in the input program is looked for and also the array element expression containing the parameter is looked for in out-pattern, and then the array element expression in pOutHir is repleced with the copy of the expression corresponding to the array element expression in in-pattern. If pOutHir contains a variable that is neither a parameter nor a variable defined in the input subprogram under transformation, then a temporal variable of the same type is generated and the variable is replaced with the temporal variable. Variables declared local in out-pattern are not defined in the subprogram under transformation and they are treated as temporal variable. The temporal variable corresponding to the local variable is registered in pParamCorresp in the process of transformation.

パラメータ:
pData - matching data.
pOutHir - out-pattern or a part of out-pattern.
戻り値:
HIR subtree generated as the result of transformation.

matchInputWithNonterm

protected HIR matchInputWithNonterm(GlobalReform.MatchingData pData,
                                    HIR pOutHir,
                                    Subp pNonterminal,
                                    java.util.Map pParamRewrite)

getMatchedInputForNonterm

protected HIR getMatchedInputForNonterm(GlobalReform.MatchingData pData,
                                        HIR pNontermCall,
                                        Subp pNonterminal)

shouldChangeParamNode

protected boolean shouldChangeParamNode(GlobalReform.MatchingData pData,
                                        Param pParam,
                                        HIR pParamReplacer,
                                        java.util.Map pRewriteCorresp)
Change pParam contained in pParamReplacer to pParamMod and return the changed pParamReplacer.

パラメータ:
pParam -
pParamReplacer -
戻り値:

transformStmtSeq

protected HIR transformStmtSeq(GlobalReform.MatchingData pData,
                               Subp pPatternSym,
                               Stmt pInStmt,
                               java.util.Map pParamRewrite)

matchInputStmtSeq

protected HIR matchInputStmtSeq(GlobalReform.MatchingData pData,
                                Subp pPatternSym,
                                Stmt pInStmt,
                                java.util.Map pParamRewrite)
matchInputStmtSeq transforms a sequence of statements starting at pInStmt by the in-pattern pPatternSym generating a statement (usually a block statement containing the sequence of statements) corresponding to the pattern.

パラメータ:
pData - matching data.
pPatternSym - name of the in-pattern.
pInStmt - header statement of the sequence of input statements to be transformed.
戻り値:
the generated statement.

getFormalActualParamCorrespondence

protected java.util.Map getFormalActualParamCorrespondence(GlobalReform.MatchingData pData,
                                                           Subp 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 symbol.
pCallNode - node calling the nonterminal.
戻り値:
the resultant correspondence.

getParamCorrespForArgWithNonterm

protected java.util.Map getParamCorrespForArgWithNonterm(GlobalReform.MatchingData pData,
                                                         HIR pArgExp,
                                                         Sym pCallerFormalParam,
                                                         Sym 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.
戻り値:

mismatch

protected java.util.Map mismatch(java.util.Map pParamCorresp,
                                 HIR pInPattern,
                                 HIR pInHir)

putMessage

public void putMessage(int pLevel,
                       java.lang.String pMessage)

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.

integralPromotion

protected Exp integralPromotion(int pOperator,
                                Exp pOperand1,
                                Exp pOperand2)

integralPromotion

protected Exp integralPromotion(int pOperator,
                                Exp pOperand1)

makeAssignStmt

protected AssignStmt makeAssignStmt(Var pVariable,
                                    Exp pExp)

typeForArithmeticExp

protected Type typeForArithmeticExp(Type pType)

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 lOld,
                             HIR lNew)

isSameTree

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

戻り値:
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)

setNonterminalFlag

protected void setNonterminalFlag(HIR pPattern)
Set FLAG_NONTERMINAL to all call nodes that call _bnfOr or _bnfSeq 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)
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.
戻り値:

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.

パラメータ:
pData - matching data inherited.
pParam - symbol that may be (1) a pattern/nonterminal parameter or (2) a pattern symbol itself representing retursive function or (3) a fitting symbol.
pHir - input HIR treaded as matched with pParam.
戻り値:

putToMap

protected void putToMap(java.util.Map pMap,
                        Sym pSym,
                        HIR pHir)

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)

recordExpandedHir

protected void recordExpandedHir(HIR pCallExp,
                                 HIR pExpandedHir,
                                 Subp pNonterminal)

getExpandedHir

protected HIR getExpandedHir(HIR pCallExp,
                             Subp pNonterminal)

makeHirKey

protected HIR makeHirKey(HIR pExp)