coins.ir.hir
Class SimplifyHir

java.lang.Object
  extended bycoins.ir.hir.SimplifyHir

public class SimplifyHir
extends java.lang.Object

SimplifyHir:

 This class simplifies HIR by deleting labeled statements with
 null statement body if the label is not explicitly refered,
 in order to suppress the generation of useless basic blocks
 in converting HIR to LIR. If HIR is changed by this class,
 finishHir() is called in this class so that HIR may keep
 consistency.
 This is invoked just before HIR-to-LIR conversion by the
 compiler driver. This does nothing if the compiler option
   -coins:hirOpt=noSimplify
 is specified and pForceSimplify is false.
 It is not recommended to invoke this before HIR transformations
 such as optimization and parallelization because the simplified
 HIR may be unsuitablbe for such HIR transformations.

 Description of simplifications

 If-statement:

  (if (condition)
   (labeledStmt (thenLabel) thenPartStatement)
   (labeledStmt (elseLabel) )
   (labeledStmt (endLabel) ))
  -->
  (if (condition)
   (labeledStmt (thenLabel) thenPartStatement)
   
   (labeledStmt (endLabel) ))

  (if (condition)
   (labeledStmt (thenLabel) )
   (labeledStmt (elseLabel) elsePartStatement)
   (labeledStmt (endLabel) ))
  -->
  (if (condition)
   
   (labeledStmt (elseLabel) elsePartStatement)
   (labeledStmt (endLabel) ))

 Loop-statement:
  The general form of a loop statement is
   (loop
    LoopInitPart
    ConditionalInitPart -- usually null
    (labeledStmt (loopBackLabel)
     (expStmt ... )) -- loop-start conditionPart
    (labeledStmt (loopBodyLabel)
     (block
       ... -- loop body part
      (labeledStmt (loopStepLabel) ))
    (expStmt ... ) -- loop-end condition
    (labeledStmt (loopEndLabel) ))
  If loop-start condition is null, remove loopBodylabel
   by changing (labeledStmt (loopBodyLabel) (block ...))
            to (block ... ).
  If loopStepLabel is not explicitly refered (that is,
  the loop does not contain continue-statement), then
  (labeledStmt (loopStepLabel) ) is deleted.

 Switch-statement:
  The simplification of switch-statement is covered
  by the simplification of labeled statement.

 Labeled-satement:

  Simplify LabeledStmt having LabeledStmt as its body:

  (labelDef (lab1) (labelDef (lab2) stmtBody))
  -->
  (labelDef (lab1 lab2) stmtBody)

  (labelDef (lab1)
   (block
    (labelDef (lab2) stmtBody)
         .... ))
  -->
  (labelDef (lab1 lab2)
   (block
    stmtBody
     .... ))

 After above simplifications, change statements with multiple
 labels to statements with single label and rewrite HIR nodes
 refering erazed labels to the remaining label, that is,
  (labelDef (lab1 lab2 ... labn) stmtBody)
  -->
   (labelDef (lab1) stmtBody)
    and change references to lab2, ..., labn to lab1.


Field Summary
(package private)  boolean fChanged
           
(package private)  int fDbgLevel
           
(package private)  java.util.ArrayList fLabelDefToBeDeleted
           
(package private)  java.util.ArrayList fLabeledStmt
           
(package private)  java.util.ArrayList fLabelRef
           
(package private)  java.util.HashMap fReplaceLabel
           
(package private)  boolean fSomeSubpChanged
           
(package private)  java.util.ArrayList fStmtToBeDeleted
           
(package private)  java.util.ArrayList fStmtWithMultipleLabels
           
(package private)  Subp fSubp
           
(package private)  HirRoot hirRoot
           
(package private)  IoRoot ioRoot
           
 
Constructor Summary
SimplifyHir(HirRoot pHirRoot, boolean pForceSimplify)
           
 
Method Summary
(package private)  void deleteIfNull(LabeledStmt pStmt)
           
 void deleteUnusedLabelsOfIfStmt(IfStmt pIfStmt)
           
 void deleteUnusedLabelsOfLoopStmt(LoopStmt pLoopStmt)
           
 void recordLabelRefOfSwitchStmt(SwitchStmt pSwitchStmt)
           
(package private)  boolean shouldHaveLabel(LabeledStmt pStmt)
           
 void simplifyHir(Subp pSubp)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hirRoot

HirRoot hirRoot

ioRoot

IoRoot ioRoot

fSubp

Subp fSubp

fLabelDefToBeDeleted

java.util.ArrayList fLabelDefToBeDeleted

fStmtToBeDeleted

java.util.ArrayList fStmtToBeDeleted

fLabeledStmt

java.util.ArrayList fLabeledStmt

fStmtWithMultipleLabels

java.util.ArrayList fStmtWithMultipleLabels

fLabelRef

java.util.ArrayList fLabelRef

fReplaceLabel

java.util.HashMap fReplaceLabel

fChanged

boolean fChanged

fSomeSubpChanged

boolean fSomeSubpChanged

fDbgLevel

int fDbgLevel
Constructor Detail

SimplifyHir

public SimplifyHir(HirRoot pHirRoot,
                   boolean pForceSimplify)
Method Detail

simplifyHir

public void simplifyHir(Subp pSubp)

deleteUnusedLabelsOfIfStmt

public void deleteUnusedLabelsOfIfStmt(IfStmt pIfStmt)

deleteUnusedLabelsOfLoopStmt

public void deleteUnusedLabelsOfLoopStmt(LoopStmt pLoopStmt)

recordLabelRefOfSwitchStmt

public void recordLabelRefOfSwitchStmt(SwitchStmt pSwitchStmt)

shouldHaveLabel

boolean shouldHaveLabel(LabeledStmt pStmt)

deleteIfNull

void deleteIfNull(LabeledStmt pStmt)