use of org.graalvm.compiler.nodes.FixedNode in project graal by oracle.
the class ScheduledNodeIterator method processNodes.
public void processNodes(Block block, ScheduleResult schedule) {
lastFixed = block.getBeginNode();
assert lastFixed != null;
reconnect = null;
iterator = schedule.nodesFor(block).listIterator();
while (iterator.hasNext()) {
Node node = iterator.next();
if (!node.isAlive()) {
continue;
}
if (reconnect != null && node instanceof FixedNode) {
reconnect.setNext((FixedNode) node);
reconnect = null;
}
if (node instanceof FixedWithNextNode) {
lastFixed = (FixedWithNextNode) node;
}
processNode(node);
}
if (reconnect != null) {
assert block.getSuccessorCount() == 1;
reconnect.setNext(block.getFirstSuccessor().getBeginNode());
}
}
use of org.graalvm.compiler.nodes.FixedNode 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.FixedNode 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.FixedNode in project graal by oracle.
the class NodeCostUtil method computeGraphCycles.
@SuppressWarnings("try")
public static double computeGraphCycles(StructuredGraph graph, boolean fullSchedule) {
Function<Block, Iterable<? extends Node>> blockToNodes;
ControlFlowGraph cfg;
if (fullSchedule) {
SchedulePhase schedule = new SchedulePhase(SchedulePhase.SchedulingStrategy.LATEST_OUT_OF_LOOPS, true);
schedule.apply(graph);
cfg = graph.getLastSchedule().getCFG();
blockToNodes = b -> graph.getLastSchedule().getBlockToNodesMap().get(b);
} else {
cfg = ControlFlowGraph.compute(graph, true, true, false, false);
BlockMap<List<FixedNode>> nodes = new BlockMap<>(cfg);
for (Block b : cfg.getBlocks()) {
ArrayList<FixedNode> curNodes = new ArrayList<>();
for (FixedNode node : b.getNodes()) {
curNodes.add(node);
}
nodes.put(b, curNodes);
}
blockToNodes = b -> nodes.get(b);
}
double weightedCycles = 0D;
DebugContext debug = graph.getDebug();
try (DebugContext.Scope s = debug.scope("NodeCostSummary")) {
for (Block block : cfg.getBlocks()) {
for (Node n : blockToNodes.apply(block)) {
double probWeighted = n.estimatedNodeCycles().value * block.probability();
assert Double.isFinite(probWeighted);
weightedCycles += probWeighted;
if (debug.isLogEnabled()) {
debug.log("Node %s contributes cycles:%f size:%d to graph %s [block prob:%f]", n, n.estimatedNodeCycles().value * block.probability(), n.estimatedNodeSize().value, graph, block.probability());
}
}
}
}
assert weightedCycles >= 0D;
assert Double.isFinite(weightedCycles);
return weightedCycles;
}
use of org.graalvm.compiler.nodes.FixedNode in project graal by oracle.
the class FixedNodeProbabilityCache method findBegin.
private static FixedNode findBegin(FixedNode node) {
FixedNode current = node;
while (true) {
assert current != null;
Node predecessor = current.predecessor();
if (current instanceof AbstractBeginNode) {
if (predecessor == null) {
break;
} else if (predecessor.successors().count() != 1) {
assert predecessor instanceof ControlSplitNode : "a FixedNode with multiple successors needs to be a ControlSplitNode: " + current + " / " + predecessor;
break;
}
} else if (predecessor == null) {
current = null;
break;
}
current = (FixedNode) predecessor;
}
return current;
}
Aggregations