use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class ComputeInliningRelevance method getMaxProbabilityLoopExit.
/**
* Returns the most probable loop exit. If multiple successors share the maximum probability,
* one is returned and the others are enqueued in pathBeginNodes.
*/
private Node getMaxProbabilityLoopExit(LoopBeginNode loopBegin, ArrayList<FixedNode> pathBeginNodes) {
Node maxSux = null;
double maxProbability = 0.0;
int pathBeginCount = pathBeginNodes.size();
for (LoopExitNode sux : loopBegin.loopExits()) {
double probability = nodeProbabilities.applyAsDouble(sux);
if (probability > maxProbability) {
maxProbability = probability;
maxSux = sux;
truncate(pathBeginNodes, pathBeginCount);
} else if (probability == maxProbability) {
pathBeginNodes.add(sux);
}
}
return maxSux;
}
use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class ComputeInliningRelevance method compute.
/**
* Initializes or updates the relevance computation. If there are no loops within the graph,
* most computation happens lazily.
*/
public void compute() {
rootScope = null;
if (!graph.hasLoops()) {
// fast path for the frequent case of no loops
rootScope = new Scope(graph.start(), null);
} else {
if (nodeRelevances == null) {
nodeRelevances = EconomicMap.create(Equivalence.IDENTITY, EXPECTED_MIN_INVOKE_COUNT + InliningUtil.getNodeCount(graph) / EXPECTED_INVOKE_RATIO);
}
NodeWorkList workList = graph.createNodeWorkList();
EconomicMap<LoopBeginNode, Scope> loops = EconomicMap.create(Equivalence.IDENTITY, EXPECTED_LOOP_COUNT);
Scope topScope = new Scope(graph.start(), null);
for (LoopBeginNode loopBegin : graph.getNodes(LoopBeginNode.TYPE)) {
createLoopScope(loopBegin, loops, topScope);
}
topScope.process(workList);
for (Scope scope : loops.getValues()) {
scope.process(workList);
}
}
}
use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class ComputeInliningRelevance method computeFastPathMinProbability.
/**
* Computes the minimum probability along the most probable path within the scope. During
* iteration, the method returns immediately once a loop exit is discovered.
*/
private double computeFastPathMinProbability(FixedNode scopeStart) {
ArrayList<FixedNode> pathBeginNodes = new ArrayList<>();
pathBeginNodes.add(scopeStart);
double minPathProbability = nodeProbabilities.applyAsDouble(scopeStart);
boolean isLoopScope = scopeStart instanceof LoopBeginNode;
do {
Node current = pathBeginNodes.remove(pathBeginNodes.size() - 1);
do {
if (isLoopScope && current instanceof LoopExitNode && ((LoopBeginNode) scopeStart).loopExits().contains((LoopExitNode) current)) {
return minPathProbability;
} else if (current instanceof LoopBeginNode && current != scopeStart) {
current = getMaxProbabilityLoopExit((LoopBeginNode) current, pathBeginNodes);
minPathProbability = getMinPathProbability((FixedNode) current, minPathProbability);
} else if (current instanceof ControlSplitNode) {
current = getMaxProbabilitySux((ControlSplitNode) current, pathBeginNodes);
minPathProbability = getMinPathProbability((FixedNode) current, minPathProbability);
} else {
assert current.successors().count() <= 1;
current = current.successors().first();
}
} while (current != null);
} while (!pathBeginNodes.isEmpty());
return minPathProbability;
}
use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class PostOrderNodeIterator method finishLoopEnds.
private void finishLoopEnds(LoopEndNode end) {
assert !visitedEnds.isMarked(end);
assert !nodeStates.containsKey(end);
nodeStates.put(end, state);
visitedEnds.mark(end);
LoopBeginNode begin = end.loopBegin();
boolean endsVisited = true;
for (LoopEndNode le : begin.loopEnds()) {
if (!visitedEnds.isMarked(le)) {
endsVisited = false;
break;
}
}
if (endsVisited) {
ArrayList<T> states = new ArrayList<>(begin.loopEnds().count());
for (LoopEndNode le : begin.orderedLoopEnds()) {
states.add(nodeStates.get(le));
}
T loopBeginState = nodeStates.get(begin);
if (loopBeginState != null) {
loopBeginState.loopEnds(begin, states);
}
}
}
use of org.graalvm.compiler.nodes.LoopBeginNode in project graal by oracle.
the class PEReadEliminationClosure method processInitialLoopState.
@SuppressWarnings("unchecked")
@Override
protected void processInitialLoopState(Loop<Block> loop, PEReadEliminationBlockState initialState) {
super.processInitialLoopState(loop, initialState);
if (!initialState.getReadCache().isEmpty()) {
EconomicMap<ValueNode, Pair<ValueNode, Object>> firstValueSet = null;
for (PhiNode phi : ((LoopBeginNode) loop.getHeader().getBeginNode()).phis()) {
ValueNode firstValue = phi.valueAt(0);
if (firstValue != null && phi.getStackKind().isObject()) {
ValueNode unproxified = GraphUtil.unproxify(firstValue);
if (firstValueSet == null) {
firstValueSet = EconomicMap.create(Equivalence.IDENTITY_WITH_SYSTEM_HASHCODE);
}
Pair<ValueNode, Object> pair = Pair.create(unproxified, firstValueSet.get(unproxified));
firstValueSet.put(unproxified, pair);
}
}
if (firstValueSet != null) {
ReadCacheEntry[] entries = new ReadCacheEntry[initialState.getReadCache().size()];
int z = 0;
for (ReadCacheEntry entry : initialState.getReadCache().getKeys()) {
entries[z++] = entry;
}
for (ReadCacheEntry entry : entries) {
ValueNode object = entry.object;
if (object != null) {
Pair<ValueNode, Object> pair = firstValueSet.get(object);
while (pair != null) {
initialState.addReadCache(pair.getLeft(), entry.identity, entry.index, entry.kind, entry.overflowAccess, initialState.getReadCache().get(entry), this);
pair = (Pair<ValueNode, Object>) pair.getRight();
}
}
}
}
}
}
Aggregations