Search in sources :

Example 31 with FixedNode

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());
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 32 with FixedNode

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;
}
Also used : LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode)

Example 33 with FixedNode

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;
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ArrayList(java.util.ArrayList) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 34 with FixedNode

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;
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) FixedNode(org.graalvm.compiler.nodes.FixedNode) Node(org.graalvm.compiler.graph.Node) ArrayList(java.util.ArrayList) FixedNode(org.graalvm.compiler.nodes.FixedNode) DebugContext(org.graalvm.compiler.debug.DebugContext) BlockMap(org.graalvm.compiler.core.common.cfg.BlockMap) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) Block(org.graalvm.compiler.nodes.cfg.Block) ArrayList(java.util.ArrayList) List(java.util.List)

Example 35 with FixedNode

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;
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

FixedNode (org.graalvm.compiler.nodes.FixedNode)87 Node (org.graalvm.compiler.graph.Node)41 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)41 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)39 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)39 ValueNode (org.graalvm.compiler.nodes.ValueNode)34 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)33 EndNode (org.graalvm.compiler.nodes.EndNode)27 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)25 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)23 PhiNode (org.graalvm.compiler.nodes.PhiNode)22 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)21 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)21 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)20 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)17 MergeNode (org.graalvm.compiler.nodes.MergeNode)17 StartNode (org.graalvm.compiler.nodes.StartNode)17 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)16 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)13 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)13