coins.opt
Class CommonSubexpElimHirE

java.lang.Object
  extended bycoins.opt.CommonSubexpElim
      extended bycoins.opt.CommonSubexpElimHir
          extended bycoins.opt.CommonSubexpElimHirE
Direct Known Subclasses:
PRE

public class CommonSubexpElimHirE
extends CommonSubexpElimHir

This class performs common subexpresssion elimination operations that are specific to HIR.


Field Summary
protected  AliasAnal fAlias
           
protected  java.util.Set fAvailableExps
          fAvailable Set of ExpId's for currently available expressions in BBlock .
protected  java.util.Set fAvailableTemps
          fAssigned: Set of available temporal variables in BBlock.
protected  boolean fBeforePRE
           
protected  int[] fExpCost
           
protected  int fIndexMax
           
protected  int fIndexMin
           
protected  java.util.Map fLatestNodeForExpId
           
protected  RecordAlias fRecordAlias
           
protected  java.util.Set fReplacedNodes
           
protected  int fThreshold
          fThreshold Replacement threshold.
 
Fields inherited from class coins.opt.CommonSubexpElimHir
fGlobalExpTempMap, fGlobalTempExpMap, hir
 
Fields inherited from class coins.opt.CommonSubexpElim
fDbgLevel, fFunctionsWithoutSideEffect, flowRoot, fSubpFlow, sym, symRoot
 
Constructor Summary
CommonSubexpElimHirE(FlowRoot pFlowRoot, int pThreshold)
           
CommonSubexpElimHirE(FlowRoot pFlowRoot, int pThreshold, boolean pBeforePRE)
          Constructor CommonSubexpElimHirE
 
Method Summary
protected  void adjustAvailability(HIR pExp, Stmt pStmt, BBlock pBBlock)
          adjustAvailability Add pExp and all its subexpressions to fAvailableExps.
 boolean containsCall(HIR pHir)
           
(package private)  void dbg(int level, java.lang.Object pObject)
           
(package private)  void dbg(int level, java.lang.String pHeader, java.lang.Object pObject)
           
 boolean doBBlockLocal(BBlock pBBlock)
          Performs the common subexpression elimination within the given BBlock.
 void estimateExpCost(SubpDefinition pSubpDef)
          estimateExpCost Estimate the approximate cost of subexpressions in the HIR body of pSubpDef by formula (Exp cost) = (node cost) + (cost of subexpressions) The costs of VarNode and contents node are machineParam.costOfInstruction(MachineParam.COST_INDEX_TEMP_LOAD).
protected  HIR getLatestCall(HIR pExp, BBlock pBBlock)
           
protected  HIR getLatestNodeOfExp(HIR pExp, BBlock pBBlock)
          getLatestNodeOfExp Get the latest node having maximum node index among the nodes whose node index is less than that of pExp.
protected  void insertTheStatement(Stmt pInsertionPoint, Stmt pStmtToBeInserted)
           
protected  boolean replaceAvailableExp(HIR pExp, BBlock pBBlock, Stmt pStmt)
          replaceAvailableExp Replace the computation of pExp by a temporal variable if all of its operands are in fAvailableExps.
protected  boolean replaceExp(HIR pExp, BBlock pBBlock, Stmt pStmt)
          replaceExp Replace the computation of pExp by a temporal variable.
protected  boolean replaceTheExpression(HIR pOldExp, HIR pNewExp, BBlock pBBlock)
          replaceTheExpression Replace pOldExp with pNewExp after recording all nodes of pOldExp to fReplacedNodes so that they should not be replaced in later processing.
(package private)  boolean toBeExcluded(HIR pHir)
          Expressions to be excluded from replacement are FunctionExp, List, comparison expression, undecay, BlockStmt, left hand side of AssignStmt, and expressions whose type is vector/struct/union/Subp.
protected  boolean tryToEliminateExp(HIR pExp, BBlock pBBlock, Stmt pStmt)
          tryToEliminateExp //##25 Try to eliminate pExp or its subexpressions if their values are already computed in pBBlock.
protected  boolean tryToEliminateSubexp(HIR pExp, BBlock pBBlock, Stmt pStmt)
          tryToEliminateSubexp //##25 Try to eliminate subexpressions of pExp if their values are already computed in pBBlock.
protected  boolean tryToReplaceSubexp(HIR pExp, BBlock pBBlock, Stmt pStmt)
          tryToReplaceSubexp Try to replace subexpressions of pExp which is to be replaced.
 
Methods inherited from class coins.opt.CommonSubexpElimHir
eliminateComplex, eliminateSimple, operandSet, recordTempExpCorrespondence, registerUseSyms, reregisterSubexps
 
Methods inherited from class coins.opt.CommonSubexpElim
doBBlockLocal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fAlias

protected AliasAnal fAlias

fRecordAlias

protected RecordAlias fRecordAlias

fAvailableExps

protected java.util.Set fAvailableExps
fAvailable Set of ExpId's for currently available expressions in BBlock .


fAvailableTemps

protected java.util.Set fAvailableTemps
fAssigned: Set of available temporal variables in BBlock.


fReplacedNodes

protected java.util.Set fReplacedNodes

fLatestNodeForExpId

protected java.util.Map fLatestNodeForExpId

fExpCost

protected int[] fExpCost

fIndexMin

protected int fIndexMin

fIndexMax

protected int fIndexMax

fBeforePRE

protected boolean fBeforePRE

fThreshold

protected int fThreshold
fThreshold Replacement threshold. Expressions with cost less than fThreshold are not replaced by temporal but recomputed each time.

Constructor Detail

CommonSubexpElimHirE

public CommonSubexpElimHirE(FlowRoot pFlowRoot,
                            int pThreshold)

CommonSubexpElimHirE

public CommonSubexpElimHirE(FlowRoot pFlowRoot,
                            int pThreshold,
                            boolean pBeforePRE)
Constructor CommonSubexpElimHirE

Parameters:
pBeforePRE - true if invoked as the preparatory optimization for partial redundancy elimination, false otherwise.
Method Detail

doBBlockLocal

public boolean doBBlockLocal(BBlock pBBlock)
Performs the common subexpression elimination within the given BBlock. If call encountered,global variable values are assumed to be not available.

Overrides:
doBBlockLocal in class CommonSubexpElim
Returns:
true if the underlying IR has changed (optimized).

tryToEliminateExp

protected boolean tryToEliminateExp(HIR pExp,
                                    BBlock pBBlock,
                                    Stmt pStmt)
tryToEliminateExp //##25 Try to eliminate pExp or its subexpressions if their values are already computed in pBBlock. Adjust available expressions at exit.

Parameters:
pExp - expression to be examined for elimination.
pBBlock - basic block containing pExp.
pStmt - statement containing pExp.
Returns:
true if elimination is done, false if no elimination is done.

tryToEliminateSubexp

protected boolean tryToEliminateSubexp(HIR pExp,
                                       BBlock pBBlock,
                                       Stmt pStmt)
tryToEliminateSubexp //##25 Try to eliminate subexpressions of pExp if their values are already computed in pBBlock. If pExp is HirList, then try for each list element. Availability adjustment is done for each subexpression (not for pExp).

Parameters:
pExp - expression whose subexpression are to be examined for elimination.
pBBlock - basic block containing pExp.
pStmt - statement containing pExp.
Returns:
true if elimination is done, false if no elimination is done.

toBeExcluded

boolean toBeExcluded(HIR pHir)
Expressions to be excluded from replacement are FunctionExp, List, comparison expression, undecay, BlockStmt, left hand side of AssignStmt, and expressions whose type is vector/struct/union/Subp.

Returns:
true if pHir should be excluded from elimination else return false.

containsCall

public boolean containsCall(HIR pHir)

adjustAvailability

protected void adjustAvailability(HIR pExp,
                                  Stmt pStmt,
                                  BBlock pBBlock)
adjustAvailability Add pExp and all its subexpressions to fAvailableExps. If pExp modifies some variable, then remove all expressions using it as a leaf operand from fAvailableExps; and remove the variable from fAvailableTemps.

Parameters:
pExp - Expression to be adjusted.
pStmt - Statement including pExp. //##65

replaceAvailableExp

protected boolean replaceAvailableExp(HIR pExp,
                                      BBlock pBBlock,
                                      Stmt pStmt)
replaceAvailableExp Replace the computation of pExp by a temporal variable if all of its operands are in fAvailableExps.

Parameters:
pExp - expression to be examined for replacement.
pBBlock - basic block containing pExp.
pStmt - statement containing pExp.
Returns:
true if actually replaced, false otherwise.

replaceExp

protected boolean replaceExp(HIR pExp,
                             BBlock pBBlock,
                             Stmt pStmt)
replaceExp Replace the computation of pExp by a temporal variable. If pExp has no corresponding temporal, generate a temporal. If the corresponding temporal is already available, just replece by it. If the corresponding temporal is not available, insert the computation of the temporal in front of pStmt and replace by it. Add the temporal to the set of availabel temporals.

Parameters:
pExp - expression to be replaced.
pBBlock - basic block containing pExp.
pStmt - statement containing pExp.
Returns:
true if actually replaced, false otherwise.

tryToReplaceSubexp

protected boolean tryToReplaceSubexp(HIR pExp,
                                     BBlock pBBlock,
                                     Stmt pStmt)
tryToReplaceSubexp Try to replace subexpressions of pExp which is to be replaced. (By the modification for speeding up SetRefRepr computation, this method will always return without replacing subexpressions. 0601)

Parameters:
pExp - expression whose subexpression are to be examined for relacement.
pBBlock - basic block containing pExp.
pStmt - statement containing pExp.

replaceTheExpression

protected boolean replaceTheExpression(HIR pOldExp,
                                       HIR pNewExp,
                                       BBlock pBBlock)
replaceTheExpression Replace pOldExp with pNewExp after recording all nodes of pOldExp to fReplacedNodes so that they should not be replaced in later processing.

Parameters:
pOldExp - expression to be replaced.
pNewExp - expression to be used in replacement.
pBBlock - basic block containing pOldExp.

insertTheStatement

protected void insertTheStatement(Stmt pInsertionPoint,
                                  Stmt pStmtToBeInserted)

getLatestNodeOfExp

protected HIR getLatestNodeOfExp(HIR pExp,
                                 BBlock pBBlock)
getLatestNodeOfExp Get the latest node having maximum node index among the nodes whose node index is less than that of pExp. It is assumed that the node index shows the order of execution within a basic block.

Parameters:
pExp - expression to be replaced.
pBBlock - basic block containing pExp.
Returns:
the latest node if found, null if not found.

getLatestCall

protected HIR getLatestCall(HIR pExp,
                            BBlock pBBlock)

estimateExpCost

public void estimateExpCost(SubpDefinition pSubpDef)
estimateExpCost Estimate the approximate cost of subexpressions in the HIR body of pSubpDef by formula (Exp cost) = (node cost) + (cost of subexpressions) The costs of VarNode and contents node are machineParam.costOfInstruction(MachineParam.COST_INDEX_TEMP_LOAD). The cost of nodes producing no instructions (DECAY, UNDECAY, EXP_STMT, SEQ, etc.) is 0 (child cost only). The costs of other executable nodes are 1. The node costs are recorded in fExpCost array.

Parameters:
pSubpDef - Subprogram definition.

dbg

void dbg(int level,
         java.lang.Object pObject)

dbg

void dbg(int level,
         java.lang.String pHeader,
         java.lang.Object pObject)