public final class Block extends AbstractBlockBase<Block>
AbstractBlockBase.BlockIdComparator| Modifier and Type | Field and Description |
|---|---|
protected AbstractBeginNode |
beginNode |
static Block[] |
EMPTY_ARRAY |
protected FixedNode |
endNode |
protected ProfileData.ProfileSource |
frequencySource |
protected Block |
postdominator |
protected double |
relativeFrequency |
BLOCK_ID_COMPARATOR, domDepth, EMPTY_PROBABILITY_ARRAY, id, predecessors, SINGLETON_PROBABILITY_ARRAY, successorProbabilities, successors| Constructor and Description |
|---|
Block(AbstractBeginNode node) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canKill(org.graalvm.word.LocationIdentity location) |
boolean |
canKillBetweenThisAndDominator(org.graalvm.word.LocationIdentity location) |
void |
delete() |
AbstractBeginNode |
getBeginNode() |
Block |
getDominator(int distance) |
Block |
getEarliestPostDominated() |
FixedNode |
getEndNode() |
Block |
getFirstPredecessor() |
Block |
getFirstSuccessor() |
ProfileData.ProfileSource |
getFrequencySource() |
LocationSet |
getKillLocations() |
Loop<Block> |
getLoop() |
int |
getLoopDepth() |
Iterable<FixedNode> |
getNodes() |
Block |
getPostdominator() |
double |
getRelativeFrequency()
Get the relative Frequency of a basic block.
|
boolean |
isExceptionEntry() |
boolean |
isInSameOrOuterLoopOf(Block block)
Checks whether
this block is in the same loop or an outer loop of the block given as
parameter. |
boolean |
isLoopEnd() |
boolean |
isLoopHeader() |
void |
markAsLoopEnd() |
long |
numBackedges()
If this block is a loop header, returns the number of the loop's
backedges.
|
void |
setFrequencySource(ProfileData.ProfileSource frequencySource) |
void |
setLoop(Loop<Block> loop) |
protected void |
setPostDominator(Block postdominator) |
void |
setRelativeFrequency(double relativeFrequency) |
String |
toString() |
String |
toString(Verbosity verbosity) |
getDominatedSibling, getDominator, getDominatorDepth, getDominatorNumber, getDominatorSkipLoops, getFirstDominated, getId, getLinearScanNumber, getMaxChildDominatorNumber, getPredecessorCount, getPredecessors, getSuccessorCount, getSuccessorProbabilities, getSuccessors, hashCode, isAligned, setAlign, setDominatedSibling, setDominator, setDominatorNumber, setFirstDominated, setId, setLinearScanNumber, setMaxChildDomNumber, setPredecessors, setSuccessorProbabilities, setSuccessors, setSuccessorspublic static final Block[] EMPTY_ARRAY
protected final AbstractBeginNode beginNode
protected FixedNode endNode
protected double relativeFrequency
protected ProfileData.ProfileSource frequencySource
protected Block postdominator
public Block(AbstractBeginNode node)
public AbstractBeginNode getBeginNode()
public FixedNode getEndNode()
public Loop<Block> getLoop()
getLoop in class AbstractBlockBase<Block>public int getLoopDepth()
getLoopDepth in class AbstractBlockBase<Block>public boolean isLoopHeader()
isLoopHeader in class AbstractBlockBase<Block>public long numBackedges()
AbstractBlockBaseAbstractBlockBase.getLoop(). Returns -1 if this is not a loop header.numBackedges in class AbstractBlockBase<Block>public boolean isLoopEnd()
isLoopEnd in class AbstractBlockBase<Block>public void markAsLoopEnd()
public boolean isExceptionEntry()
isExceptionEntry in class AbstractBlockBase<Block>public Block getFirstPredecessor()
public Block getFirstSuccessor()
public Block getEarliestPostDominated()
public Block getPostdominator()
getPostdominator in class AbstractBlockBase<Block>public String toString()
toString in class AbstractBlockBase<Block>public double getRelativeFrequency()
if (a) {
thenAction()
} else {
elseAction()
}
and a true successor probability of 0.5 this means 50% of the time when executing the code
condition a was false. This only becomes relevant in a large context: e.g., out of 1000 times
the code is executed, 500 times a is false.
The interpreter collects these branch profiles for every java bytecode if instruction. The
Graal compiler uses them to derive its internal representation of execution probabilities
called "block frequencies". Since the Graal compiler only compiles one method at a time and
does not perform inter method optimizations the actual total numbers for invocation and
execution counts are not interesting. Thus, Graal uses the branch probabilities from the
interpreter to derive a metric for profiles within a single compilation unit. These are the
block frequencies. Block frequencies are applied to basic blocks, i.e., every basic block has
one. It is a floating point number that expresses how often a basic block will be executed
with respect to the start of a method. Thus, the metric only makes sense within a single
compilation unit and it marks hot regions of code.
Consider the following method foo:
void foo() {
// method start: frequency = 1
int i=0;
while (true) {
if(i>=10) { // exit
break;
}
consume(i)
i++;
}
return // method end: relative frequency = 1
}
Every method's start basic block is unconditionally executed thus it has a frequency of 1.
Then foo contains a loop that consists of a loop header, a condition, an exit and a loop
body. In this while loop, the header is executed initially once and then how often the back
edges indicate that the loop will be executed. For this Graal uses the frequency of the loop
exit condition (i.e. i >= 10). When the condition has a false successor (enter the
loop body) frequency of roughly 90% we can calculate the loop frequency from that: the loop
frequency is the entry block frequency times the frequency from the exit condition's false
successor which accumulates roughly to 1/0.1 which amounts to roughly 10 loop iterations.
However, since we know the loop is exited at some point the code after the loop has again a
block frequency set to 1 (loop entry frequency).
Graal sets the
profiles during parsing and later computes loop frequencies for LoopBeginNode.
Finally, the frequency for basic Blocks is set during ControlFlowGraph
construction.getRelativeFrequency in class AbstractBlockBase<Block>public void setRelativeFrequency(double relativeFrequency)
public void setFrequencySource(ProfileData.ProfileSource frequencySource)
public ProfileData.ProfileSource getFrequencySource()
public Block getDominator(int distance)
getDominator in class AbstractBlockBase<Block>public boolean canKill(org.graalvm.word.LocationIdentity location)
public LocationSet getKillLocations()
public boolean canKillBetweenThisAndDominator(org.graalvm.word.LocationIdentity location)
public void delete()
delete in class AbstractBlockBase<Block>protected void setPostDominator(Block postdominator)
public boolean isInSameOrOuterLoopOf(Block block)
this block is in the same loop or an outer loop of the block given as
parameter.