public class CountedLoopInfo extends Object
CountedLoopInfo.getLimit(), CountedLoopInfo.getBody(),
CountedLoopInfo.getLimitCheckedIV() and CountedLoopInfo.getBodyIV():
A regular head counted loop like
for (int i = 0; i < end; i++) {
// body
}
has a limit (end) that is compared against the InductionVariable (iv) returned by
getLimitCheckedIV. The iv for the loop above is the basic induction variable i.
For inverted loops like
int i = 0;
do {
// body
i++;
} while(i < end)
The iv compared against limit is not i, but the next iteration's body iv i+1.
Thus, for inverted loops CountedLoopInfo.getBodyIV() returns a different result than
CountedLoopInfo.getLimitCheckedIV(). CountedLoopInfo.getBodyIV() returns i, while CountedLoopInfo.getLimitCheckedIV()
returns i + 1.
Furthermore, the contract between CountedLoopInfo.getLimitCheckedIV() and CountedLoopInfo.getBodyIV() defines
that both IVs iterate on the same signed-ness range, i.e., if one is purely in an unsigned range
the other one has to be as well (same applies for signed integers). This means that optimizations
can safely use IntegerHelper based on the signed-ness of the CountedLoopInfo.getLimitCheckedIV()
to compute min/max and iteration ranges for the loops involved.| Modifier and Type | Field and Description |
|---|---|
protected AbstractBeginNode |
body |
protected ValueNode |
end |
protected IfNode |
ifNode |
protected boolean |
isLimitIncluded
true iff the limit is included in the limit test, e.g., the limit test is
i <= n rather than i < n. |
protected InductionVariable |
limitCheckedIV |
protected LoopEx |
loop |
protected boolean |
unsigned |
| Modifier | Constructor and Description |
|---|---|
protected |
CountedLoopInfo(LoopEx loop,
InductionVariable limitCheckedIV,
IfNode ifNode,
ValueNode end,
boolean isLimitIncluded,
AbstractBeginNode body,
boolean unsigned) |
protected final LoopEx loop
protected InductionVariable limitCheckedIV
protected ValueNode end
protected boolean isLimitIncluded
true iff the limit is included in the limit test, e.g., the limit test is
i <= n rather than i < n.protected AbstractBeginNode body
protected IfNode ifNode
protected final boolean unsigned
protected CountedLoopInfo(LoopEx loop, InductionVariable limitCheckedIV, IfNode ifNode, ValueNode end, boolean isLimitIncluded, AbstractBeginNode body, boolean unsigned)
public InductionVariable getLimitCheckedIV()
InductionVariable compared (CompareNode) to
CountedLoopInfo.getLimit(). If this loop is
CountedLoopInfo.isInverted() returns to next iteration iv based on
CountedLoopInfo.getBodyIV().public InductionVariable getBodyIV()
InductionVariable used in the body of this CountedLoopInfo. If
CountedLoopInfo.isInverted() returns false this returns the same as
CountedLoopInfo.getLimitCheckedIV().public ValueNode getLimit()
ValueNode that is compared (CompareNode) to the
InductionVariable return by CountedLoopInfo.getLimitCheckedIV()public ValueNode getTripCountLimit()
CountedLoopInfo.maxTripCountNode(). If CountedLoopInfo.isInverted() is
false this returns the same as CountedLoopInfo.getLimit(). Otherwise,
depending on the shape of the inverted loops this may return a value that is |stride| off the
real limit to account for inverted loops with none-inverted limit checks.
Consider the following inverted loop
int i = 0;
do {
i++;
} while (i < 100);
This loop performs 100 iterations. However, the following loop
int i = 0;
do {
} while (i++ < 100);
performs 101 iterations.
While the "limit" of both is 100, the "real" mathematical limit of the second one is 101.
Thus, in order to perform correct calculation of CountedLoopInfo.maxTripCountNode()
we distinguish between those two concepts.public ValueNode maxTripCountNode()
CountedLoopInfo.isExactTripCount() returns true.
THIS VALUE SHOULD BE TREATED AS UNSIGNED.public boolean isUnsignedCheck()
public ValueNode maxTripCountNode(boolean assumeLoopEntered)
protected ValueNode maxTripCountNode(boolean assumeLoopEntered, IntegerHelper integerHelper)
count
check.
This count is exact if CountedLoopInfo.isExactTripCount() returns true.
THIS VALUE SHOULD BE TREATED AS UNSIGNED.assumeLoopEntered - if true the check that the loop is entered at all will be omitted.public boolean loopMightBeEntered()
false if we can tell statically that
the loop cannot be entered; returns true if the loop might possibly be entered,
including in the case where we cannot be sure statically.public boolean isConstantMaxTripCount()
public UnsignedLong constantMaxTripCount()
public IntegerHelper getCounterIntegerHelper()
public IntegerHelper getCounterIntegerHelper(int bits)
public boolean isExactTripCount()
public ValueNode exactTripCountNode()
public boolean isConstantExactTripCount()
public UnsignedLong constantExactTripCount()
public IfNode getLimitTest()
IfNode that checks CountedLoopInfo.getLimitCheckedIV() against
CountedLoopInfo.getLimit().public ValueNode getBodyIVStart()
InductionVariable.initNode() of the loop's CountedLoopInfo.getBodyIV(), i.e.,
the start node of the IV used inside the loop body (which can be different than the
IV checked in CountedLoopInfo.getLimitCheckedIV()}.public boolean isLimitIncluded()
public AbstractBeginNode getBody()
public AbstractBeginNode getCountedExit()
public InductionVariable.Direction getDirection()
public GuardingNode getOverFlowGuard()
public boolean counterNeverOverflows()
public GuardingNode createOverFlowGuard()
public IntegerStamp getStamp()
public boolean isInverted()