|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcoins.ir.hir.HIR_Impl
coins.ir.hir.StmtImpl
coins.ir.hir.LoopStmtImpl
Loop-statement class. // Components (children) of loop statement // child1: LoopInitPart. (Stmt) // This may be null. // getLoopInitPart returns this statement. // child2: ConditionalInitPart (This has been deleted. Give 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.) // child3: StartConditionPart with loopBackLabel. (LabeledStmt) // This should be given but its LabeledStmt may be null. // getLoopBackPoint() returns this LabeledStmt. // child4: LoopBody that is a LabeledStmt with loopBodyLabel. // StmtBody part of the LabeledStmt is BlockStmt // having LabeledStmt with loopStepLabel (LabeledStmt) // as the last statement of the loop-body BlockStmt. // An implementation of the LoopBody is // (labeledStmt // (list) // (block // sequence of statements given as pLoopBody parameter // of setChildrenOfLoop // (labeledStmt // (list ) // null))) // LoopBody should be given but its BlockStmt may have // no executable statements. // getLoopBodyPart() returns this LabeledStmt. // child5: EndCondition. (ExpStmt) // This may be null. // getLoopEndCondition() returns the expression of the ExpStmt. // child6: LoopStepPart jumping to loopBackLabel. (Stmt) // This may be null. // getLoopStepPart() returns this statement. // child7: LoopEndpart with loopEndLabel. (LabeledStmt) // This should be given but its LabeledStmt may be null. // getLoopEndPart() returns this LabeledStmt.
| Field Summary | |
Label |
fLoopBackLabel
|
Label |
fLoopEndLabel
|
(package private) LoopInf |
fLoopInf
|
Label |
fLoopStepLabel
|
| Fields inherited from class coins.ir.hir.StmtImpl |
fMultiBlock, fNextStmt, fPrevStmt |
| Fields inherited from class coins.ir.hir.HIR_Impl |
fAdditionalChild, fChildCount, fChildNode1, fChildNode2, fDbgLevel, fHirAnnex, fOperator, fParentNode, fType, hirRoot, inversionTable, machineParam, sourceLanguage |
| Fields inherited from interface coins.ir.hir.HIR |
OP_CODE_NAME, OP_CODE_NAME_DENSE |
| Fields inherited from interface coins.ir.IR |
OP_INF, OP_LIST, OP_PROG, OP_SUBP_DEF |
| Constructor Summary | |
LoopStmtImpl()
|
|
LoopStmtImpl(HirRoot pHirRoot)
|
|
| Method Summary | |
void |
accept(HirVisitor pVisitor)
accept Acceptor used in HIR visitor. |
void |
addToConditionalInitPart(Stmt pStmt)
addToConditionalInitPart |
void |
addToLoopBodyPart(Stmt pStmt)
Add the statement pStmt before the step-labeled statement (as the last statement except the null statement with the loop-step label). |
void |
addToLoopEndPart(Stmt pStmt)
Add pStmt as the statement next to the existing loop-end statement. |
void |
addToLoopInitPart(Stmt pStmt)
Add pStmt as the last statement of loop-init-part. |
void |
addToLoopStepPart(Stmt pStmt)
Add the statement pStmt to the loop-step part (add as the statement next to the existing statement of the loop-step part). |
java.lang.Object |
clone()
clone Override Object.clone in HIR. |
void |
combineWithConditionalExp(Stmt pStmt,
HIR pCond)
Combine pStmt with conditional expression part pCond of control statement so that pStmt should be executed before pCond. |
BlockStmt |
getConditionalInitPart()
getConditionalInitPart Get the BlockStmt containing the statements added by addToConditionalInitPart. |
Stmt |
getConditionalInitPart2()
|
Label |
getLoopBackLabel()
|
LabeledStmt |
getLoopBackPoint()
getLoopBackPoint Get the statement with loopBackLabel. |
Label |
getLoopBodyLabel()
|
Stmt |
getLoopBodyPart()
getLoopBodyPart |
Exp |
getLoopEndCondition()
getLoopEndCondition |
Label |
getLoopEndLabel()
|
LabeledStmt |
getLoopEndPart()
getLoopEndPart |
LoopInf |
getLoopInf()
This method is not used anymore. |
Stmt |
getLoopInitPart()
Get the loop initiation part that is executed before repetition. |
Exp |
getLoopStartCondition()
getLoopStartCondition |
Label |
getLoopStepLabel()
|
Stmt |
getLoopStepPart()
getLoopStepPart |
boolean |
isLoopStmt()
|
boolean |
isSimpleForLoop()
isSimpleForLoop |
boolean |
isSimpleIndexedLoop()
isSimpleIndexedLoop |
boolean |
isSimpleRepeatLoop()
isSimpleRepeatLoop |
boolean |
isSimpleUntilLoop()
|
boolean |
isSimpleWhileLoop()
isSimpleWhileLoop |
protected Stmt |
makeConditionalInitPart(Exp pStartCondition,
Stmt pConditionalInitPart)
|
void |
replaceBodyPart(LabeledStmt pNewStmt)
Replace the loop body with pNewStmt. |
void |
replaceConditionalInitPart(LabeledStmt pNewStmt)
|
void |
setChildrenOfLoop(Stmt pInitPart,
Label pLoopBackLabel,
Stmt pConditionalInitPart,
Exp pStartCondition,
Stmt pLoopBody,
Label pLoopStepLabel,
Exp pEndCondition,
Stmt pLoopStepPart,
Label pLoopEndLabel,
Stmt pLoopEndPart)
|
void |
setLoopEndCondition(Exp pCondition)
Set the expression pCondition as the loop-end condition expression. |
void |
setLoopInf(LoopInf pLoopInf)
This method is not used anymore. |
void |
setLoopStartCondition(Exp pCondition)
Set the expression pCondition as the loop-start condition expression. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface coins.ir.hir.Stmt |
addNextStmt, ancestorControlStmtOfConditionalExp, attachLabel, attachLabelAsFirstOne, combineStmt, copyPosition, cutLabelLinkOfStmt, deleteThisStmt, getBlockStmt, getFileName, getLabel, getLabelDefList, getLabeledStmt, getLineNumber, getPreviousStmt, getUpperStmt, insertPreviousStmt, insertPreviousStmt, isBranchStmt, isMultiBlock, isolateThisStmt, replaceThisStmtWith, setFileName, setLineNumber |
| Methods inherited from interface 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 |
| Methods inherited from interface coins.ir.IR |
addInf, getChild1, getChild2, getInf, getInfList, getParent, getSym, print, print, removeInf |
| Methods inherited from interface coins.ir.IR0 |
getChild, getChildCount, getIndex, getOperator, setChild |
| Methods inherited from interface coins.ir.hir.HIR0 |
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 |
| Field Detail |
public Label fLoopBackLabel
public Label fLoopStepLabel
public Label fLoopEndLabel
LoopInf fLoopInf
| Constructor Detail |
public LoopStmtImpl()
public LoopStmtImpl(HirRoot pHirRoot)
| Method Detail |
public void setChildrenOfLoop(Stmt pInitPart,
Label pLoopBackLabel,
Stmt pConditionalInitPart,
Exp pStartCondition,
Stmt pLoopBody,
Label pLoopStepLabel,
Exp pEndCondition,
Stmt pLoopStepPart,
Label pLoopEndLabel,
Stmt pLoopEndPart)
public Stmt getLoopInitPart()
LoopStmtGet the loop initiation part that is executed before repetition. Ex. For a loop statement for (i=0; i
- Specified by:
getLoopInitPartin interfaceLoopStmt
- Returns:
- the loop initiation part;
public BlockStmt getConditionalInitPart()
LoopStmt
getConditionalInitPart in interface LoopStmtpublic Stmt getConditionalInitPart2()
public Exp getLoopStartCondition()
LoopStmtGet the loop start conditional expression that has the loopBackLabel. For a loop statement for (i=0; i
- Specified by:
getLoopStartConditionin interfaceLoopStmt
- Returns:
- the loop start condition expression.
public LabeledStmt getLoopBackPoint()
LoopStmt
getLoopBackPoint in interface LoopStmtpublic Stmt getLoopBodyPart()
LoopStmt
Get the loop body that is repetitively executed.
It is a block statement (BlockStmt)
with loop start label and the blcok
statement contains a labeled statement.
with loopStepLabel as its last statement.
For a statement
for (i = 0; i < 10; i++)
a[i] = 0;
a labeled statement
_lab6: { a[i] = 0; }
will be returned where _lab6 is a loop start label
generated by the compiler.
For a statement
while (i < 10) {
a = a + b;
if (a >= 10) {
i = i + 1;
continue;
}
i = i + 1;
}
a labeled statement
_lab10: {
a = a + b;
if (a >= 10) {
i = i + 1;
goto _lab3;
}
i = i + 1;
_lab4:
}
will be returned where _lab10 is the loop start label
and _lab4 is the loop step label generated by the compiler.
getLoopBodyPart in interface LoopStmtpublic Exp getLoopEndCondition()
LoopStmt
Get the loop end conditional expression.
For a loop statement
do { ... }
while (i>0);
the expression i>0 is returned.
For a loop statement
for (i=0; i
- Specified by:
getLoopEndCondition in interface LoopStmt
- Returns:
- the loop end condition expression.
public Stmt getLoopStepPart()
LoopStmtGet the loop step part that is executed before jumping to loopBackLabel. For a loop statement for (i=0; i
- Specified by:
getLoopStepPartin interfaceLoopStmt
- Returns:
- the loop step part.
public LabeledStmt getLoopEndPart()
LoopStmtGet the loop end part having the loopEndLabel. For a loop statement for (i=0; i
- Specified by:
getLoopEndPartin interfaceLoopStmt
- Returns:
- the loop end part having the loopEndLabel.
public Label getLoopBackLabel()
getLoopBackLabel in interface LoopStmtpublic Label getLoopBodyLabel()
getLoopBodyLabel in interface LoopStmtpublic Label getLoopStepLabel()
getLoopStepLabel in interface LoopStmtpublic Label getLoopEndLabel()
getLoopEndLabel in interface LoopStmtpublic LoopInf getLoopInf()
LoopStmt
getLoopInf in interface LoopStmtpublic void setLoopInf(LoopInf pLoopInf)
LoopStmt
setLoopInf in interface LoopStmtpublic void addToLoopInitPart(Stmt pStmt)
LoopStmt
addToLoopInitPart in interface LoopStmtpStmt - statement to be added to loop-init-part.public void addToConditionalInitPart(Stmt pStmt)
LoopStmt
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.
addToConditionalInitPart in interface LoopStmt
protected Stmt makeConditionalInitPart(Exp pStartCondition,
Stmt pConditionalInitPart)
public void addToLoopBodyPart(Stmt pStmt)
LoopStmt
addToLoopBodyPart in interface LoopStmtpStmt - statement to be added to the boop body.public void addToLoopStepPart(Stmt pStmt)
LoopStmt
addToLoopStepPart in interface LoopStmtpStmt - statement to be added to the loop-step part.public void addToLoopEndPart(Stmt pStmt)
LoopStmt
addToLoopEndPart in interface LoopStmtpStmt - statement to be added to the loop-end part.public void setLoopStartCondition(Exp pCondition)
LoopStmt
setLoopStartCondition in interface LoopStmtpCondition - expression to be set.public void setLoopEndCondition(Exp pCondition)
LoopStmt
setLoopEndCondition in interface LoopStmtpCondition - expression to be set.
public void replaceConditionalInitPart(LabeledStmt pNewStmt)
throws CompileError
CompileErrorpublic void replaceBodyPart(LabeledStmt pNewStmt)
LoopStmt
replaceBodyPart in interface LoopStmtpNewStmt - statement to be set as the new
loop body statement.public boolean isSimpleForLoop()
LoopStmt
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.
isSimpleForLoop in interface LoopStmtpublic boolean isSimpleWhileLoop()
LoopStmt
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.
isSimpleWhileLoop in interface LoopStmtpublic boolean isSimpleRepeatLoop()
LoopStmt
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.
isSimpleRepeatLoop in interface LoopStmtpublic boolean isSimpleUntilLoop()
public boolean isSimpleIndexedLoop()
LoopStmt
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.
isSimpleIndexedLoop in interface LoopStmtpublic boolean isLoopStmt()
isLoopStmt in class StmtImpl
public void combineWithConditionalExp(Stmt pStmt,
HIR pCond)
combineWithConditionalExp in interface StmtcombineWithConditionalExp in class StmtImplpStmt - statement to be executed before pCond.pCond - conditional expression to be combined with pStmt.
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
HIR_Impl
clone in class StmtImpljava.lang.CloneNotSupportedExceptionpublic void accept(HirVisitor pVisitor)
HIR0
accept in interface HIR0accept in class HIR_Impl
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||