coins.ir.hir
インタフェース LoopStmt

すべてのスーパーインタフェース:
java.lang.Cloneable, HIR, HIR0, IR, IR0, Stmt
既知のサブインタフェースの一覧:
ForStmt, IndexedLoopStmt, RepeatStmt, UntilStmt, WhileStmt
既知の実装クラスの一覧:
ForStmtImpl, IndexedLoopStmtImpl, LoopStmtImpl, RepeatStmtImpl, UntilStmtImpl, WhileStmtImpl

public interface LoopStmt
extends Stmt

  LoopStmt ->  // Loop statement is either for-loop, while-loop,
               // repeat-loop, indexed loop, or other general loop.
               // All of them are implemented as a general loop
               // with some restriction depending on the loop type.
               // Compiler components (other than front part) should
               // treat general loop, that is, do not assume some child
               // is null without checking whether the child is null
               // or not.
    ( LoopCode_ attr     // Loop kind code.
      LoopInitPart_ @    // Loop initiation part to be executed
                         // before repetition. This may be null.
      ConditionalInitPart_ @ // Old conditional initiation part.
                         // Give null for this item but use
                         // addToConditionalInitPart method.
      StartConditionPart_ @  // Loop start conditional expression
                         // with loopBackLabel.
                         // If true, pass through to LoopBody_,
                         // otherwise transfer to LoopEndPart_.
                         // If loop start condition part is null,
                         //  pass through to LoopBody_.
      LoopBody_ @        // Loop body repetitively executed.
                         // Pass through to EndCondition_.
                         // It is a block statement (BlockStmt)
                         // with loop start label and the blcok
                         // statement contains a labeled statement
                         // with loopStepLabel as its last statement.
                         // This should not be null but the block may
                         // have no executable statement and contains
                         // only a labeled statement with loopStepLabel.
                         // "continue" jumps to the loopStepLabel.
                         // The loopStepLabel may be omitted if
                         // there is no "jump loopStepLabel".
     EndCondition_ @     // Loop end condition expression.
                         // If true, transfer to LoopEndPart_,
                         // otherwise pass through to
                         // LoopStepPart_.
     LoopStepPart_ @     // Loop step part executed
                         // before jumping to loopBackLabel.
     LoopEndPart_ @ )    // Loop end part
                         // with loopEndLabel.
                         // "exit" (break in C) jumps to here.
     IndexedLoop_ attr   // Attributes for IndexedLoop.
                         // Not given for other loops.
    // IndexRange_ @ )   // Index range may be null in general loop.
  LoopCode_ attr ->
     whileCode attr      // while-loop
   | forCode attr        // for-loop
   | repeatCode attr      // repeat-loop
   | indexedLoopCode attr// indexed-loop
   | loopCode attr       // general loop other than above loops.
  LoopInitPart_   ->  // Loop initiation part.
     Stmt
   | null
  ConditionalInitPart_ ->  // Executed at first time only.
     Stmt              // Semantics of this is the same
   | null              // to the following if-statement with label:
                       //   if (exp_of_StartCondition_) {
                       //     statement of ConditionalInitPart_;
                       //     goto loopStartlabel of LoopBody_;
                       //   }else
                       //     goto loopEndlabel:
                       // where, statement of ConditionalInitPart_
                       // is executed once if start condition
                       // (exp_of_StartCondition_) is true.
                       // Control transfers to LoobBody_
                       // if the exp_of_StartCondition_ is true.
  StartConditionPart_ ->      // Show start condition with
     ( labeledStmtCode attr   // loopBacklabel.
       LabelDefinitionList_ @
       ExpStmtOrNull_ @ )     // loopStartConditionExpression.
  LoopBody_  ->               // Block statement with loopBodyLabel.
     ( labeledStmtCode attr   // The last statement of the block
       LabelDefinitionList_ @ // is a LabeledNull_ statement with
       BlockStmt_ @ )         // loopStepLabel.
  EndCondition_ ->            // ExpStmt showing loop end condition.
     ExpStmtOrNull_
  LoopStepPart_  ->           // Statement to be executed before jumping
     Stmt                     // to loopBackLabel.
   | null
  LoopEndPart_  ->            // LabeledNull_ statement with loopEndLabel.
     LabeledNull_
  NullOrStmt_ ->       // Usually null but it may be
     null              // a statement (created during
   | Stmt              // HIR transformation).
  ExpStmtOrNull_ ->    // Expression statement or null.
     ExpStmt
   | null
  IndexedLoop_ attr  -> // Attributes for IndexedLoop.
     loopIndex attr     // Loop index (induction variable).
                        // See getLoopIndex().
     startValue attr    // Start value of the loop index.
                        // See getStartValue().
     endValue attr      // End value of the loop index.
                        // See getEndValue().
     stepValue attr     // Step value for the loop index.
                        // See getStepValue().

  // Note. LoopInf may contain goto-loop that is difficult or
  //   impossible to be represent by above LoopStmt.
  //   (goto-loop is not implemented by LoopStmt.)

  // LoopStmt is executed as follows:
  //   LoopInitPart_;
  //   if (loopStartConditionExpression == null) {
  //     Sequence of statements added by addToConditionalInitPart();
  //   }else {
  //     if (loopStartConditionExpression == false) {
  //       jump to loopEndLabel;
  //     }else { // ConditionalInitBlock
  //       Sequence of statements added by addToConditionalInitPart().
  //       jump to loopBodyLabel;
  //     }
  //   }
  //   loopBackLabel:
  //     if ((loopStartConditionExpression != null)&&
  //         (loopStartConditionExpression == false))
  //       jump to loopEndLabel;
  //   loopBodyLabel:
  //     Start of BlockStmt of LoopBody_
  //       Stastement sequence of the BlockStmt;
  //       (break statement jumps to loopEndLabel;)
  //       (continue statement jumps to loopStepLabel;)
  //       Rest of stastement sequence of the LoopBody_;
  //       loopStepLabel:;
  //     End of BlockStmt of LoopBody_
  //     if ((loopEndConditionExpression != null)&&
  //         (loopEndConditionExpression == false))
  //       jump to loopEndLabel;
  //     LoopStepPart;
  //     jump to loopBackLabel;
  //   loopEndLabel:
  //     Loop end part;

  // BEGIN #21
  // ForStmt is created as a general loop where contents of
  //   ConditionalInitPart_, EndCondition_, LoopEndPart_
  //   are null at first (but they may become not null
  //   by some optimizing transformation).
  //   See isSimpleForLoop().
  // WhileStmt is created as a general loop where contents of
  //   LoopInitPart_, ConditionalInitPart_, EndCondition_,
  //   LoopStepPart_, LoopEndPart_
  //   are null at first (but they may become not null
  //   by some optimizing transformation).
  //   See isSimpleWhileLoop().
  // UntilStmt is created as a general loop where contents of
  //   LoopInitPart, ConditionalInitPart_, StartCondition_,
  //   LoopStepPart_, LoopEndPart_
  //   are null at first (but they may become not null
  //   by some optimizing transformation).
  //   See isSimpleUntilLoop().
  // IndexedLoopStmt is created as a general loop where contents of
  //   ConditionalInitPart_, EndCondition_, LoopEndPart_
  //   are null at first (but they may become not null
  //   by some optimizing transformation).
  //   See isSimpleIndexedLoop().
  // IndexedLoopStmt represents a Fortran type loop where
  //   value of loop index is incremented or decremented by loop
  //   step value starting from loop start value and stops
  //   to loop before crossing the barrier of loop end value.
  //   (See IndexedLoopStmt interface.)
  // Indexed loop attributes (IndexedLoopAttr_) are available
  // only for IndexedLoopStmt.
  // END #21

 // Components of loop statement:
//   child1: Initiation part.
//           This may be null.
//   child2: Conditional initiation part (may be null).
//           This is executed only once if loop condition is satisfied.
//           (At present, this is implemented by if-stmt attached to
//            LoopInitPart so that hir2lir has no need of
//            special treatment.
//            You should use addToConditionalInitPart(....)
//            without giving conditional init part in
//            new LoopStmtImpl(...). This restriction will be removed
//            when hir2lir supports ConditionalInitPart treatment.)
//   child3: Loop start condition part with loopBackLabel.
//           This should be given but its LabeledStmt may be null.
//   child4: Loop body part. It is a block statement (BlockStmt)
//           with loop start label and the blcok statement contains
//           a labeled statement with loopStepLabel as the last
//           statement of the block.
//           This should not be null but the block may have no
//           executable statement and contains only a labeled
//           statement with loopStepLabel.
//    child5: Loop end condition taking the form of ExpStmt.
//            If its statement body is null, control passes through
//            to LoopStep part.
//   child6: Loop step part jumping to loopBackLabel
//           This may be null.
//   child7: Loop end part with loopEndLabel
//           This should be given but its LabeledStmt may be null.


フィールドの概要
 
インタフェース coins.ir.hir.HIR から継承したフィールド
OP_CODE_NAME, OP_CODE_NAME_DENSE
 
インタフェース coins.ir.IR から継承したフィールド
OP_INF, OP_LIST, OP_PROG, OP_SUBP_DEF
 
インタフェース coins.ir.hir.HIR0 から継承したフィールド
FLAG_C_PTR, FLAG_CONST_EXP, FLAG_INIT_BLOCK, FLAG_LOOP_WITH_CONDITIONAL_INIT, FLAG_NOCHANGE, FLAG_NONTERMINAL, OP_ADD, OP_ADD_ASSIGN, OP_ADDR, OP_AND, OP_AND_ASSIGN, OP_ARROW, OP_ASM, OP_ASSIGN, OP_BLOCK, OP_CALL, OP_CMP_EQ, OP_CMP_GE, OP_CMP_GT, OP_CMP_LE, OP_CMP_LT, OP_CMP_NE, OP_COMMA, OP_CONST, OP_CONTENTS, OP_CONV, OP_DECAY, OP_DIV, OP_DIV_ASSIGN, OP_ELEM, OP_ENCLOSE, OP_EQ_ZERO, OP_EXP_STMT, OP_EXPLIST, OP_EXPREPEAT, OP_FOR, OP_IF, OP_INDEX, OP_INDEXED_LOOP, OP_JUMP, OP_LABEL, OP_LABEL_DEF, OP_LABELED_STMT, OP_LG_AND, OP_LG_OR, OP_MOD, OP_MOD_ASSIGN, OP_MULT, OP_MULT_ASSIGN, OP_NEG, OP_NOT, OP_NULL, OP_OFFSET, OP_OR, OP_OR_ASSIGN, OP_PARAM, OP_PHI, OP_POST_DECR, OP_POST_INCR, OP_PRE_DECR, OP_PRE_INCR, OP_QUAL, OP_REPEAT, OP_RETURN, OP_SELECT, OP_SEQ, OP_SETDATA, OP_SHIFT_L_ASSIGN, OP_SHIFT_LL, OP_SHIFT_R, OP_SHIFT_R_ASSIGN, OP_SHIFT_RL, OP_SIZEOF, OP_STMT, OP_STMT_UPPER, OP_SUB, OP_SUB_ASSIGN, OP_SUBP, OP_SUBS, OP_SWITCH, OP_SYM, OP_TYPE, OP_UNDECAY, OP_UNTIL, OP_VAR, OP_WHILE, OP_XOR, OP_XOR_ASSIGN
 
メソッドの概要
 void addToConditionalInitPart(Stmt pStmt)
          addToConditionalInitPart ConditionalInitPart is executed once if the LoopStartCondition is satisfied.
 void addToLoopBodyPart(Stmt pStmt)
           
 void addToLoopEndPart(Stmt pStmt)
           
 void addToLoopInitPart(Stmt pStmt)
          Add pStmt as the last statement of loop-init-part.
 void addToLoopStepPart(Stmt pStmt)
           
 BlockStmt getConditionalInitPart()
          getConditionalInitPart Get the BlockStmt containing the statements added by addToConditionalInitPart.
 Label getLoopBackLabel()
           
 LabeledStmt getLoopBackPoint()
          getLoopBackPoint Get the statement with loopBackLabel.
 Label getLoopBodyLabel()
           
 Stmt getLoopBodyPart()
           
 Exp getLoopEndCondition()
           
 Label getLoopEndLabel()
           
 LabeledStmt getLoopEndPart()
           
 LoopInf getLoopInf()
           
 Stmt getLoopInitPart()
           
 Exp getLoopStartCondition()
           
 Label getLoopStepLabel()
           
 Stmt getLoopStepPart()
           
 boolean isSimpleForLoop()
          isSimpleForLoop Check if this is a simple for loop, that is, an instance of ForStmt and conditional init part is null and loop end condition is null.
 boolean isSimpleIndexedLoop()
          isSimpleIndexedLoop Check if this is a simple indexed loop, that is, an instance of IndexedLoopStmt and conditional init part is null and loop end condition is null.
 boolean isSimpleRepeatLoop()
          isSimpleRepeatLoop Check if this is a simple repeat-while-true loop, that is, an instance of RepeatStmt and conditional init part is null and loop start condition is null and loop step part is null.
 boolean isSimpleWhileLoop()
          isSimpleWhileLoop Check if this is a simple while loop, that is, an instance of WhileStmt and conditional init part is null and loop step part is null and loop end condition is null.
 void replaceBodyPart(LabeledStmt pNewStmt)
           
 void setLoopEndCondition(Exp pCondition)
           
 void setLoopInf(LoopInf pLoopInf)
           
 void setLoopStartCondition(Exp pCondition)
           
 
インタフェース coins.ir.hir.Stmt から継承したメソッド
addNextStmt, ancestorControlStmtOfConditionalExp, attachLabel, attachLabelAsFirstOne, combineStmt, combineWithConditionalExp, copyPosition, cutLabelLinkOfStmt, deleteThisStmt, getBlockStmt, getFileName, getLabel, getLabelDefList, getLabeledStmt, getLineNumber, getPreviousStmt, getUpperStmt, insertPreviousStmt, insertPreviousStmt, isBranchStmt, isMultiBlock, isolateThisStmt, replaceThisStmtWith, setFileName, setLineNumber
 
インタフェース coins.ir.hir.HIR から継承したメソッド
addrExp, asmStmt, checkLinkage, conditionalExp, contains, copyInfListFrom, cutParentLink, exp, expList, expRepeat, forStmt, getExpId, getFlowAnalSym, getIndentSpace, getInfString, getIrName, getSourceNode, getSourceNode1, getSourceNode2, getSymOrExpId, getWork, hirNodeClone, hirSeq, hirSeq, indexedLoopStmt, indexedLoopStmt, infStmt, infStmt, intConstNode, irList, isEmpty, isStmt, isTree, nullNode, nullStmt, offsetConstNode, phiExp, repeatStmt, replaceSource, replaceSource1, replaceSource2, returnStmt, setChild1, setChild2, setChildren, setChildren, setDataStmt, setIndex, setIndexNumberToAllNodes, setParent, setType, setWork, subpDefinition, subpIterator, subscriptedExp, toString, toStringDetail, toStringShort, toStringWithChildren, undecayExp, undecayExp, undecayExp, whileStmt
 
インタフェース coins.ir.IR から継承したメソッド
addInf, getChild1, getChild2, getInf, getInfList, getParent, getSym, print, print, removeInf
 
インタフェース coins.ir.IR0 から継承したメソッド
getChild, getChildCount, getIndex, getOperator, setChild
 
インタフェース coins.ir.hir.HIR0 から継承したメソッド
accept, assignStmt, blockStmt, callStmt, constNode, contentsExp, convExp, copyWithOperands, copyWithOperandsChangingLabels, decayExp, elemNode, exp, exp, expStmt, falseNode, finishHir, forStmt, functionExp, getChildNumber, getFlag, getFlagBox, getNextStmt, getStmtContainingThisNode, getType, hirClone, hirIterator, hirList, hirSeq, ifStmt, intConstNode, irList, isSameAs, jumpStmt, labelDef, labeledStmt, labelNode, pointedExp, print, program, qualifiedExp, repeatStmt, replaceThisNode, returnStmt, setFlag, setIndexNumberToAllNodes, sizeofExp, sizeofExp, subpDefinition, subpNode, subscriptedExp, switchStmt, symNode, trueNode, undecayExp, varNode, whileStmt
 

メソッドの詳細

getLoopInitPart

public Stmt getLoopInitPart()

getConditionalInitPart

public BlockStmt getConditionalInitPart()
getConditionalInitPart Get the BlockStmt containing the statements added by addToConditionalInitPart. If there is no such statements, then return null.

戻り値:
ConditionalInitBlock containing statements added by addToConditionalInitPart.

getLoopStartCondition

public Exp getLoopStartCondition()

getLoopBackPoint

public LabeledStmt getLoopBackPoint()
getLoopBackPoint Get the statement with loopBackLabel. Even empty loop has a LabeledStmt with loopBackLabel where its statement body may be null.


getLoopBodyPart

public Stmt getLoopBodyPart()

getLoopEndCondition

public Exp getLoopEndCondition()

getLoopStepPart

public Stmt getLoopStepPart()

getLoopEndPart

public LabeledStmt getLoopEndPart()

getLoopBackLabel

public Label getLoopBackLabel()

getLoopBodyLabel

public Label getLoopBodyLabel()

getLoopStepLabel

public Label getLoopStepLabel()

getLoopEndLabel

public Label getLoopEndLabel()

getLoopInf

public LoopInf getLoopInf()

setLoopInf

public void setLoopInf(LoopInf pLoopInf)

isSimpleForLoop

public boolean isSimpleForLoop()
isSimpleForLoop Check if this is a simple for loop, that is, an instance of ForStmt and conditional init part is null and loop end condition is null.

戻り値:
true if above conditions are satisfied, else return false.

isSimpleWhileLoop

public boolean isSimpleWhileLoop()
isSimpleWhileLoop Check if this is a simple while loop, that is, an instance of WhileStmt and conditional init part is null and loop step part is null and loop end condition is null.

戻り値:
true if above conditions are satisfied, else return false.

isSimpleRepeatLoop

public boolean isSimpleRepeatLoop()
isSimpleRepeatLoop Check if this is a simple repeat-while-true loop, that is, an instance of RepeatStmt and conditional init part is null and loop start condition is null and loop step part is null.

戻り値:
true if above conditions are satisfied, else return false.

isSimpleIndexedLoop

public boolean isSimpleIndexedLoop()
isSimpleIndexedLoop Check if this is a simple indexed loop, that is, an instance of IndexedLoopStmt and conditional init part is null and loop end condition is null.

戻り値:
true if above conditions are satisfied, else return false.

addToLoopInitPart

public void addToLoopInitPart(Stmt pStmt)
Add pStmt as the last statement of loop-init-part. If there is no loop-init-part, then pStmt is attached as the new loop-init-part. If there is already loop-init-part, then pStmt is added as the last statement of the loop-init-part.

パラメータ:
pStmt - statement to be added to loop-init-part.

addToConditionalInitPart

public void addToConditionalInitPart(Stmt pStmt)
addToConditionalInitPart
 ConditionalInitPart is executed once if the LoopStartCondition
 is satisfied. It is a block to where loop invariant expressions
 are to be moved so that they are executed only once. The
 ConditionalInitPart is created by addToConditionalInitPart(pStmt)
 as a block containing ConditionalInitBlock in the LoopInitPart
 in the following way:
 Case 1: LoopStartCondition is null:
   LoopInitPart_ is changed as follows:
     {
       oroginal LoopInitPart_;
       { // ConditionalInitBlock.
         // getConditionalInitPart() returns this else-block.
         Sequence of statements added by addToConditionalInitPart;
       }
     }
   The transformation procedure is:
     If ConditionalInitBlock is not yet created,
       create it as a BlockStmt and add it as the last statement
       of LoopInitBlock
     pStmt is added as the last statement of ConditionalInitBlock.
 case 2:  LoopStartCondition is not null and ConditionalInitPart
          is not yet created:
   LoopInitPart_ is changed as follows:
     {
       oroginal LoopInitPart_;
       if (loopStartConditionExpression == false) {
         jump to loopEndLabel;
       }else { // ConditionalInitBlock.
               // getConditionalInitPart() returns this else-block.
         Sequence of statements added by addToConditionalInitPart;
         jump to loopBodyLabel;
       }
     }

   The else-part of above if-statement is called as
   ConditionalInitBlock.
 case 3: ConditionalInitBlock is already created:
   pStmt is inserted before "goto loopBodyLabel" of ConditionalInitBlock.
 Expressions to be executed only once for this loop
 may be added to ConditionalInitBlock by calling
 addToConditionalInitPart successively.
 When ConditionalInitBlock with "jump to loopBodyLabel" is created,
   setFlag(HIR.FLAG_LOOP_WITH_CONDITIONAL_INIT, true)
 is executed to show that the loop became irreducible but
 it is a tame loop that can be treated in many optimization/
 parallelization procedures.
 No special treatment is required for ConditionalInitPart in
 HIR-to-LIR conversion, HIR-to-C conversion, HIR flow analysis,
 etc. because it takes a form of normal HIR expression.


addToLoopBodyPart

public void addToLoopBodyPart(Stmt pStmt)

addToLoopStepPart

public void addToLoopStepPart(Stmt pStmt)

addToLoopEndPart

public void addToLoopEndPart(Stmt pStmt)

setLoopStartCondition

public void setLoopStartCondition(Exp pCondition)

setLoopEndCondition

public void setLoopEndCondition(Exp pCondition)

replaceBodyPart

public void replaceBodyPart(LabeledStmt pNewStmt)