Search in sources :

Example 26 with LoopBeginNode

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;
}
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 27 with LoopBeginNode

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

Example 28 with LoopBeginNode

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;
}
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 29 with LoopBeginNode

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);
        }
    }
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ArrayList(java.util.ArrayList) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode)

Example 30 with LoopBeginNode

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();
                    }
                }
            }
        }
    }
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ReadCacheEntry(org.graalvm.compiler.virtual.phases.ea.PEReadEliminationBlockState.ReadCacheEntry) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) Pair(org.graalvm.collections.Pair)

Aggregations

LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)61 FixedNode (org.graalvm.compiler.nodes.FixedNode)30 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)26 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)24 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)23 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)22 Node (org.graalvm.compiler.graph.Node)21 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)21 EndNode (org.graalvm.compiler.nodes.EndNode)20 PhiNode (org.graalvm.compiler.nodes.PhiNode)20 ValueNode (org.graalvm.compiler.nodes.ValueNode)20 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)19 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)14 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)13 MergeNode (org.graalvm.compiler.nodes.MergeNode)11 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)10 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)10 ArrayList (java.util.ArrayList)9 IfNode (org.graalvm.compiler.nodes.IfNode)9 LogicNode (org.graalvm.compiler.nodes.LogicNode)9