|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object scale.common.Root scale.score.Note scale.score.chords.Chord scale.score.chords.SequentialChord scale.score.chords.LoopHeaderChord
public class LoopHeaderChord
This class is used to mark the start of a loop.
$Id: LoopHeaderChord.java,v 1.136 2007-10-29 13:39:26 burrill Exp $
Copyright 2008 by the
Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.
An instance of this class always has two and only two in-coming CFG
edges. One is from a LoopPreHeaderChord
and the other is from a LoopTailChord
. No
code is generated for a LoopHeaderChord instance.
Don't assume that a LoopHeaderChord instance will always start a
basic block. For example, a "do { } while (false);" will not have
a LoopTailChord
after SCC.
There may be one, none, or several LoopExitChord
instances associated with a loop.
Below are two images of the loop structure used by Scale. They
show the CFG before going into SSA
mode.
Both were generated from:
int sumfor(int n) { int sum, i; sum = 0; for (i = 0; i < n; i++) sum += i; return sum; }
Regular Loop | Loop Test at End |
---|---|
LoopPreHeaderChord
,
LoopTailChord
,
LoopExitChord
,
LoopInitChord
Field Summary | |
---|---|
static boolean |
classTrace
True if traces are to be performed. |
Fields inherited from class scale.score.chords.Chord |
---|
lineNumber |
Constructor Summary | |
---|---|
LoopHeaderChord(Scribble scribble,
LoopHeaderChord parent)
|
|
LoopHeaderChord(Scribble scribble,
LoopHeaderChord parent,
Chord next)
|
Method Summary | |
---|---|
void |
addChildLoop(LoopHeaderChord child)
Specify that child is a loop contained in this loop. |
void |
addLoopExit(LoopExitChord loopExit)
Specify a LoopExitChord
instance associated with this loop. |
LoopHeaderChord |
commonAncestor(LoopHeaderChord l2)
Return the common ancestor of this loop and the specified loop. |
Chord |
copy()
Make a copy of this loop header sans any data dependence information. |
int |
countNodesInLoop()
Return the number of nodes in the loop, not including the loop header or the LoopExitChord nodes. |
void |
defPrimaryInductionVariable(InductionVar var)
Define the primary induction variable for this loop. |
DDGraph |
getDDGraph(boolean createSpatialDependencies)
Return the data dependency graph for this CFG. |
DColor |
getDisplayColorHint()
Return a String specifying the color to use for coloring this node in a graphical display. |
LoopHeaderChord |
getFirstChild()
Return the first child loop. |
LoopExitChord |
getFirstExit()
Return the first loop exit. |
InductionVar |
getInductionVar(Expr exp)
Return the InductionVar instance
referenced by this LoadExpr
expression or null . |
InductionVar |
getInductionVar(int index)
Return the indicated induction variable. |
InductionVar |
getInductionVar(VariableDecl vd)
Return the InductionVar instance
associated with this variable or null . |
Expr |
getInductionVarInitExpr()
Return the expression that initializes the primary induction variable or null if it is not known. |
Vector<InductionVar> |
getInductionVars()
Return a vector of this loop's induction variables. |
LoopHeaderChord |
getInnerLoop(int i)
Return the specified inner loop. |
Vector<LoopHeaderChord> |
getInnerLoops()
Return a Vector of all of the loops
(LoopHeaderChord instances) contained in this loop. |
void |
getInnermostLoops(Vector<LoopHeaderChord> loops)
Add all innermost loops in this loop tree to the vector. |
void |
getLoopChordsRecursive(HashSet<Chord> chords)
Return all the CFG nodes in this loop and all of its inner loops. |
LoopExitChord |
getLoopExit(int i)
Return the specified loop exit. |
LoopHeaderChord |
getLoopHeader()
Return the LoopHeaderChord instance associated with
this loop exit. |
InductionVar |
getLoopIndex(LoadExpr le)
Return the InductionVar instance
associated with this LoadExpr
or null . |
VariableDecl |
getLoopIndexVar()
Return the primary loop index variable or null if
none known. |
LoopInitChord |
getLoopInit()
Return the LoopInitChord
instance for this loop. |
int |
getLoopNumber()
Return the integer value associated with a loop. |
LoopTailChord |
getLoopTail()
Return the LoopTailChord
instance for this loop if known. |
IfThenElseChord |
getLoopTest()
Return the loop test Chord for this loop or null if
not known. |
Expr |
getLowerBound()
Return the node representing the loop's lower bound. |
int |
getNestedLevel()
Return the nest level for a loop. |
LoopHeaderChord |
getParent()
Return the parent loop of this loop. |
LoopPreHeaderChord |
getPreHeader()
Return the LoopPreHeaderChord instance for this loop. |
InductionVar |
getPrimaryInductionVar()
Return the best primary induction variable. |
InductionVar |
getPrimaryInductionVar(int index)
Return the indicated primary induction variable. |
int |
getProfEntryCnt()
Return the number of times the loop was entered during execution. |
int |
getProfIterationCnt()
Return the number of times the loop was iterated during execution as determined by profiling. |
Scribble |
getScribble()
Return the Scribble instance for
this loop header. |
long |
getStepValue()
Return the step value of the primary induction variable or 0 if it is not known. |
boolean |
getSubscripts(Table<Declaration,SubscriptExpr> subs)
Create the mapping from the array names to the SubscriptExpr instances in this
loop. |
boolean |
getSubscriptsRecursive(Table<Declaration,SubscriptExpr> subs)
Create a Table mapping from array name
to SubscriptExpr instances
in this loop nest. |
Vector<LoopHeaderChord> |
getTightlyNestedLoops()
Return a vector of the tightly nested loops or null . |
LoopHeaderChord |
getTopLoop()
Returns the top most "real" loop containing this loop. |
Cost |
getTripCount()
|
int |
getUnrollFactor()
Return the requested unroll factor. |
Expr |
getUpperBound()
Return the node representing the loop's upper bound. |
boolean |
hasInnerLoop(LoopHeaderChord child)
Return true if the specified loop is a child of this loop. |
java.lang.String |
inductionVarName()
Return the name of the primary induction variable. |
boolean |
inhibitLoopPermute()
|
AffineExpr |
isAffine(Expr n)
Return the affine expression defined by the specified expression or null if the expression is not affine. |
boolean |
isDDComplete()
Return true if the data dependence information for this loop nest is complete. |
boolean |
isInnerMostLoop()
Return true if this loop is an inner-most loop. |
boolean |
isInvariant(Expr exp)
Return true if the expression is invariant in the loop. |
boolean |
isLoopExit(LoopExitChord le)
Return true if the specified loop exit is for this loop. |
boolean |
isLoopHeader()
Return true if this chord is a LoopHeaderChord. |
boolean |
isLoopIndex(Expr exp)
Return true if the specified expression is a LoadExpr instance that references a
loop induction variable. |
boolean |
isLoopIndex(VariableDecl vd)
Return true if the specified variable is a loop induction variable. |
boolean |
isLoopInfoComplete()
Return true if the loop information for this loop is complete. |
boolean |
isPerfectlyNested()
Return true if this is a perfectly nested loop. |
boolean |
isPrimaryLoopIndex(Expr exp)
Return true if the specified LoadExpr instance references the primary loop induction
variable. |
boolean |
isPrimaryLoopIndex(VariableDecl vd)
Return true if the specified variable is the primary loop induction variable. |
boolean |
isSpecial()
Return true if this is CFG node was added for the convenience of the compiler and does not correspond to actual source code in the user program. |
boolean |
isSubloop(LoopHeaderChord loop)
Return true if this loop is a subloop of
loop or if this == loop . |
boolean |
isTightlyNested()
Return true if this loop is tightly nested. |
boolean |
isTrueLoop()
Return true if this loop is an actual loop in the program. |
void |
labelCFGLoopOrder()
Give unique labels to all CFG nodes. |
void |
linkSubgraph(HashMap<Chord,Chord> nm)
Link a new CFG node that contains old links. |
void |
loopClean()
Eliminate associated loop information. |
boolean |
loopContainsCall()
Return true if an expression in the loop may result in a call to a subroutine. |
int |
nestedLevel()
Return the nesting depth of the inner-most loop relative to this loop. |
void |
newSSAForm()
Remove the induction variable information from this loop and all child loops. |
int |
numChordsInLoop()
Return the number of nodes in this loop including its subloops. |
int |
numInDataEdges()
Return the number of in-coming data edges. |
int |
numInductionVars()
Return the number of induction variables found for the loop. |
int |
numInnerLoops()
Return the number of the loops contained in this loop (i.e., the number of immediate sub-loops). |
int |
numLoopExits()
Return the number of loop exits. |
int |
numPrimaryInductionVars()
Return the number of induction variables with termination tests. |
boolean |
parentsFinished(HashSet<Chord> finished)
Always return true, since we ignore the back edge when performing a topological sort. |
boolean |
parentsVisited()
Always return true, since we ignore the back edge when performing a topological sort. |
boolean |
print(int indent)
Print a display of the information about the loop. |
void |
printSubscripts(Table<Declaration,SubscriptExpr> arraySubscripts)
Print the (sometimes very large) list of subscript expressions in this loop. |
void |
recomputeLoop()
Specify that the loop information is no longer valid. |
void |
recomputeLoops()
Specify that the loop information is no longer valid for this loop and all its sub-loops. |
void |
removeChildLoop(LoopHeaderChord child)
Specify that child is no longer a loop contained in
this loop. |
void |
removeLoopExit(LoopExitChord loopExit)
Specify that LoopExitChord instance is no longer a loop exit for this loop. |
void |
setDDComplete()
Specify that the data dependence information for this loop is complete to initialize for data dependence testing. |
void |
setDDIncomplete()
Specify that the data dependence information for this loop is not complete because data dependence testing failed. |
void |
setLoopInit(LoopInitChord loopInit)
Specify the LoopInitChord instance associated with this loop. |
void |
setLoopTail(LoopTailChord loopTail)
Specify the LoopTailChord instance associated with this loop. |
void |
setLoopTest(IfThenElseChord loopTest)
Specify the loop exit test associated with this loop. |
void |
setParent(LoopHeaderChord parent)
Specify the enclosing loop of this loop. |
void |
setProfEntryCnt(int count)
Specify the number of times the loop was entered during execution. |
void |
setProfIterationCnt(int count)
Specify the number of times the loop was iterated during execution. |
void |
setScribble(Scribble scribble)
Specify the Scribble instance for
this loop header. |
void |
setUnrollFactor(int unrollFactor)
Set the requested unroll factor. |
java.lang.String |
toStringSpecial()
Construct a String that contains the loop header chord of this loop. |
void |
unlinkChord()
Break any un-needed links from this LoopHeaderChord
instance that has been deleted. |
void |
usePragma(PragmaStk.Pragma pragma)
|
void |
validate()
Check this node for validity. |
void |
visit(Predicate p)
Process a node by calling its associated routine. |
Methods inherited from class scale.score.Note |
---|
getChord, getEssentialUse, setAnnotationLevel, setReportLevel, toString |
Methods inherited from class scale.common.Root |
---|
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, hashCode, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, trace, trace, trace |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static boolean classTrace
Constructor Detail |
---|
public LoopHeaderChord(Scribble scribble, LoopHeaderChord parent, Chord next)
parent
- the parent loop of this loop or null
next
- is the successor CFG nodepublic LoopHeaderChord(Scribble scribble, LoopHeaderChord parent)
parent
- the parent loop of this loop or null
Method Detail |
---|
public Chord copy()
copy
in class Chord
public void loopClean()
loopClean
in class Chord
public final LoopHeaderChord getParent()
public final void addChildLoop(LoopHeaderChord child)
child
is a loop contained in this loop.
public final void removeChildLoop(LoopHeaderChord child)
child
is no longer a loop contained in
this loop.
public boolean hasInnerLoop(LoopHeaderChord child)
public final boolean isInnerMostLoop()
public final LoopHeaderChord getFirstChild()
public Vector<LoopHeaderChord> getInnerLoops()
Vector
of all of the loops
(LoopHeaderChord
instances) contained in this loop.
public LoopHeaderChord getInnerLoop(int i)
public final void getInnermostLoops(Vector<LoopHeaderChord> loops)
BeginChord
instance is never added.
public final int numInnerLoops()
public void unlinkChord()
LoopHeaderChord
instance that has been deleted.
unlinkChord
in class Chord
public final boolean parentsVisited()
parentsVisited
in class Chord
public final boolean parentsFinished(HashSet<Chord> finished)
parentsFinished
in class Chord
finished
- is the set to test.public final void setParent(LoopHeaderChord parent)
parent
- new parent loop of this looppublic void addLoopExit(LoopExitChord loopExit)
LoopExitChord
instance associated with this loop.
loopExit
- is the LoopExitChord
instancepublic final void removeLoopExit(LoopExitChord loopExit)
LoopExitChord
instance is no longer a loop exit for this loop.
public final LoopExitChord getFirstExit()
public final LoopExitChord getLoopExit(int i)
public final int numLoopExits()
public boolean isLoopExit(LoopExitChord le)
public LoopPreHeaderChord getPreHeader()
LoopPreHeaderChord
instance for this loop.
public final void usePragma(PragmaStk.Pragma pragma)
public final int getUnrollFactor()
public final void setUnrollFactor(int unrollFactor)
public final boolean inhibitLoopPermute()
public void setLoopTail(LoopTailChord loopTail)
LoopTailChord
instance associated with this loop.
loopTail
- the LoopTailChordpublic LoopTailChord getLoopTail()
LoopTailChord
instance for this loop if known.
public void setLoopInit(LoopInitChord loopInit)
LoopInitChord
instance associated with this loop.
loopInit
- the LoopInitChordpublic LoopInitChord getLoopInit()
LoopInitChord
instance for this loop.
public void setLoopTest(IfThenElseChord loopTest)
loopTest
- the loop test Chordpublic IfThenElseChord getLoopTest()
null
if
not known. There may be multiple loop exit tests. At most one
of these tests will be known.
public LoopHeaderChord getLoopHeader()
LoopHeaderChord
instance associated with
this loop exit.
getLoopHeader
in class Chord
public boolean isSpecial()
isSpecial
in class Chord
public int numInDataEdges()
numInDataEdges
in class Chord
public void visit(Predicate p)
Note
Each class has a visit(Predicate p)
method. For
example, in class ABC
:
public void visit(Predicate p) { p.visitABC(this); }and the class that implements
Predicate
has a method
public void visitABC(Note n) { ABC a = (ABC) n; ... }Thus, the class that implements
Predicate
can call
n.visit(this);where
n
is a Note
sub-class without
determining which specific sub-class n
is.
The visit pattern basically avoids implementing a large
switch
statement or defining different methods
in each class for some purpose.
visit
in class Note
Predicate
public final int getNestedLevel()
public boolean isPerfectlyNested()
isTightlyNested()
public final boolean isTightlyNested()
public final Vector<LoopHeaderChord> getTightlyNestedLoops()
null
.
A tighly nested loop has only one inner loop and that inner loop
is a tightly nested loop.
public final int nestedLevel()
public void defPrimaryInductionVariable(InductionVar var)
public InductionVar getPrimaryInductionVar()
public java.lang.String inductionVarName()
public VariableDecl getLoopIndexVar()
null
if
none known.
public InductionVar getPrimaryInductionVar(int index)
public int numPrimaryInductionVars()
public Expr getInductionVarInitExpr()
null
if it is not known.
public long getStepValue()
0
if it is not known.
public Expr getLowerBound()
public Expr getUpperBound()
public boolean isInvariant(Expr exp)
public boolean isPrimaryLoopIndex(VariableDecl vd)
public boolean loopContainsCall()
public int numInductionVars()
public InductionVar getInductionVar(int index)
public Vector<InductionVar> getInductionVars()
public final LoopHeaderChord getTopLoop()
this
if this
is the top
loop or this
is the BeginChord
.
public final Scribble getScribble()
Scribble
instance for
this loop header.
public final void setScribble(Scribble scribble)
Scribble
instance for
this loop header.
public DDGraph getDDGraph(boolean createSpatialDependencies)
createSpatialDependencies
- is true if spatial edges should
be createdpublic void labelCFGLoopOrder()
LoopExitChord
, its label is greater than the label of any other
node in the loop. Note - if node n2's label is greater than node
n1's label, this does not necessarily mean that n2 is always
executed after n1; they could be in parallel branches of the CFG.
So, one can not compare the labels of two nodes and declare that
one is executed before or after the other. But, the label values
do provide a useful partial ordering.
For a complete ordering of a CFG do
scribble.getLoopTree().labelCFGLoopOrder();
Note - other algorithms may use the label field and destroy this value. An example is the computation of dominators.
Note - this method uses nextVisit()
.
AASR
,
Scribble.linearize(scale.common.Vector)
,
Chord.pushChordWhenReady(Stack, int)
public boolean getSubscripts(Table<Declaration,SubscriptExpr> subs)
SubscriptExpr
instances in this
loop. Only "valid" subscript expressions are added. A valid
subscript expression is one that dependence testing can utilize.
Examples of invalid subscript expressions include
(func(a,b))[i] strct.arr[i]
public boolean getSubscriptsRecursive(Table<Declaration,SubscriptExpr> subs)
Table
mapping from array name
to SubscriptExpr
instances
in this loop nest. Only "valid" subscript expressions are added.
A valid subscript expression is one that dependence testing can
utilize. Examples of invalid subscript expressions include
(func(a,b))[i] strct.arr[i]
public AffineExpr isAffine(Expr n)
null
if the expression is not affine.
n
- is the expression.public void recomputeLoops()
public void recomputeLoop()
public void newSSAForm()
public final void setProfEntryCnt(int count)
public final int getProfEntryCnt()
public final void setProfIterationCnt(int count)
public final int getProfIterationCnt()
public final boolean isLoopHeader()
isLoopHeader
in class Chord
public boolean isDDComplete()
public boolean isLoopInfoComplete()
public void setDDIncomplete()
public void setDDComplete()
public void printSubscripts(Table<Declaration,SubscriptExpr> arraySubscripts)
public boolean isSubloop(LoopHeaderChord loop)
this
loop is a subloop of
loop
or if this == loop
.
public Cost getTripCount()
public java.lang.String toStringSpecial()
toStringSpecial
in class Chord
public boolean isTrueLoop()
public void getLoopChordsRecursive(HashSet<Chord> chords)
public int numChordsInLoop()
public int countNodesInLoop()
LoopExitChord
nodes. The CFG
is spanned to calculate the value.
Chord.nextVisit()
,
numChordsInLoop
public LoopHeaderChord commonAncestor(LoopHeaderChord l2)
BeginChord
node is a loop header.
public boolean print(int indent)
public DColor getDisplayColorHint()
getDisplayColorHint
in interface DisplayNode
getDisplayColorHint
in class Chord
DColor
public InductionVar getLoopIndex(LoadExpr le)
InductionVar
instance
associated with this LoadExpr
or null
.
public boolean isLoopIndex(Expr exp)
LoadExpr
instance that references a
loop induction variable.
public boolean isLoopIndex(VariableDecl vd)
public InductionVar getInductionVar(Expr exp)
InductionVar
instance
referenced by this LoadExpr
expression or null
.
public InductionVar getInductionVar(VariableDecl vd)
InductionVar
instance
associated with this variable or null
.
public boolean isPrimaryLoopIndex(Expr exp)
LoadExpr
instance references the primary loop induction
variable.
public void linkSubgraph(HashMap<Chord,Chord> nm)
linkSubgraph
in class SequentialChord
nm
- is a map from the old nodes to the new nodes.Scribble.linkSubgraph(scale.common.Vector, scale.common.HashMap, scale.common.Vector)
public void validate()
validate
in class Note
public final int getLoopNumber()
getLoopNumber
in class Chord
URJ
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |