Search in sources :

Example 6 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class ProfileCompiledMethodsPhase method run.

@Override
protected void run(StructuredGraph graph) {
    SchedulePhase schedule = new SchedulePhase(graph.getOptions());
    schedule.apply(graph, false);
    ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
    for (Loop<Block> loop : cfg.getLoops()) {
        double loopProbability = cfg.blockFor(loop.getHeader().getBeginNode()).probability();
        if (loopProbability > (1D / Integer.MAX_VALUE)) {
            addSectionCounters(loop.getHeader().getBeginNode(), loop.getBlocks(), loop.getChildren(), graph.getLastSchedule(), cfg);
        }
    }
    // don't put the counter increase directly after the start (problems with OSR)
    FixedWithNextNode current = graph.start();
    while (current.next() instanceof FixedWithNextNode) {
        current = (FixedWithNextNode) current.next();
    }
    addSectionCounters(current, Arrays.asList(cfg.getBlocks()), cfg.getLoops(), graph.getLastSchedule(), cfg);
    if (WITH_INVOKES) {
        for (Node node : graph.getNodes()) {
            if (node instanceof Invoke) {
                Invoke invoke = (Invoke) node;
                DynamicCounterNode.addCounterBefore(GROUP_NAME_INVOKES, invoke.callTarget().targetName(), 1, true, invoke.asNode());
            }
        }
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ReinterpretNode(org.graalvm.compiler.nodes.calc.ReinterpretNode) RemNode(org.graalvm.compiler.nodes.calc.RemNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) IntegerDivRemNode(org.graalvm.compiler.nodes.calc.IntegerDivRemNode) BinaryNode(org.graalvm.compiler.nodes.calc.BinaryNode) SwitchNode(org.graalvm.compiler.nodes.extended.SwitchNode) NotNode(org.graalvm.compiler.nodes.calc.NotNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AccessMonitorNode(org.graalvm.compiler.nodes.java.AccessMonitorNode) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) SafepointNode(org.graalvm.compiler.nodes.SafepointNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) Node(org.graalvm.compiler.graph.Node) ConvertNode(org.graalvm.compiler.nodes.calc.ConvertNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) DynamicCounterNode(org.graalvm.compiler.nodes.debug.DynamicCounterNode) FloatDivNode(org.graalvm.compiler.nodes.calc.FloatDivNode) Block(org.graalvm.compiler.nodes.cfg.Block) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 7 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class MultiTypeGuardInlineInfo method createDispatchOnTypeBeforeInvoke.

private boolean createDispatchOnTypeBeforeInvoke(StructuredGraph graph, AbstractBeginNode[] successors, boolean invokeIsOnlySuccessor, StampProvider stampProvider, ConstantReflectionProvider constantReflection) {
    assert ptypes.size() >= 1;
    ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
    LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, nonNullReceiver));
    graph.getDebug().log("Type switch with %d types", concretes.size());
    ResolvedJavaType[] keys = new ResolvedJavaType[ptypes.size()];
    double[] keyProbabilities = new double[ptypes.size() + 1];
    int[] keySuccessors = new int[ptypes.size() + 1];
    double totalProbability = notRecordedTypeProbability;
    for (int i = 0; i < ptypes.size(); i++) {
        keys[i] = ptypes.get(i).getType();
        keyProbabilities[i] = ptypes.get(i).getProbability();
        totalProbability += keyProbabilities[i];
        keySuccessors[i] = invokeIsOnlySuccessor ? 0 : typesToConcretes.get(i);
        assert keySuccessors[i] < successors.length - 1 : "last successor is the unknownTypeSux";
    }
    keyProbabilities[keyProbabilities.length - 1] = notRecordedTypeProbability;
    keySuccessors[keySuccessors.length - 1] = successors.length - 1;
    // Normalize the probabilities.
    for (int i = 0; i < keyProbabilities.length; i++) {
        keyProbabilities[i] /= totalProbability;
    }
    TypeSwitchNode typeSwitch = graph.add(new TypeSwitchNode(hub, successors, keys, keyProbabilities, keySuccessors, constantReflection));
    FixedWithNextNode pred = (FixedWithNextNode) invoke.asNode().predecessor();
    pred.setNext(typeSwitch);
    return false;
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 8 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class GraphUtil method markFixedNodes.

private static void markFixedNodes(FixedNode node, EconomicSet<Node> markedNodes, EconomicMap<AbstractMergeNode, List<AbstractEndNode>> unmarkedMerges) {
    NodeStack workStack = new NodeStack();
    workStack.push(node);
    while (!workStack.isEmpty()) {
        Node fixedNode = workStack.pop();
        markedNodes.add(fixedNode);
        if (fixedNode instanceof AbstractMergeNode) {
            unmarkedMerges.removeKey((AbstractMergeNode) fixedNode);
        }
        while (fixedNode instanceof FixedWithNextNode) {
            fixedNode = ((FixedWithNextNode) fixedNode).next();
            if (fixedNode != null) {
                markedNodes.add(fixedNode);
            }
        }
        if (fixedNode instanceof ControlSplitNode) {
            for (Node successor : fixedNode.successors()) {
                workStack.push(successor);
            }
        } else if (fixedNode instanceof AbstractEndNode) {
            AbstractEndNode end = (AbstractEndNode) fixedNode;
            AbstractMergeNode merge = end.merge();
            if (merge != null) {
                assert !markedNodes.contains(merge) || (merge instanceof LoopBeginNode && end instanceof LoopEndNode) : merge;
                if (merge instanceof LoopBeginNode) {
                    if (end == ((LoopBeginNode) merge).forwardEnd()) {
                        workStack.push(merge);
                        continue;
                    }
                    if (markedNodes.contains(merge)) {
                        continue;
                    }
                }
                List<AbstractEndNode> endsSeen = unmarkedMerges.get(merge);
                if (endsSeen == null) {
                    endsSeen = new ArrayList<>(merge.forwardEndCount());
                    unmarkedMerges.put(merge, endsSeen);
                }
                endsSeen.add(end);
                if (!(end instanceof LoopEndNode) && endsSeen.size() == merge.forwardEndCount()) {
                    assert merge.forwardEnds().filter(n -> !markedNodes.contains(n)).isEmpty();
                    // all this merge's forward ends are marked: it needs to be killed
                    workStack.push(merge);
                }
            }
        }
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) ArrayList(java.util.ArrayList) NodeStack(org.graalvm.compiler.graph.NodeStack) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) List(java.util.List) ArrayList(java.util.ArrayList) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode)

Example 9 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class SnippetTemplate method instantiate.

/**
 * Replaces a given fixed node with this specialized snippet.
 *
 * @param metaAccess
 * @param replacee the node that will be replaced
 * @param replacer object that replaces the usages of {@code replacee}
 * @param args the arguments to be bound to the flattened positional parameters of the snippet
 * @param killReplacee is true, the replacee node is deleted
 * @return the map of duplicated nodes (original -&gt; duplicate)
 */
@SuppressWarnings("try")
public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAccess, FixedNode replacee, UsageReplacer replacer, Arguments args, boolean killReplacee) {
    DebugContext debug = replacee.getDebug();
    assert assertSnippetKills(replacee);
    try (DebugCloseable a = args.info.instantiationTimer.start(debug)) {
        args.info.instantiationCounter.increment(debug);
        // Inline the snippet nodes, replacing parameters with the given args in the process
        StartNode entryPointNode = snippet.start();
        FixedNode firstCFGNode = entryPointNode.next();
        StructuredGraph replaceeGraph = replacee.graph();
        EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args);
        replacements.put(entryPointNode, AbstractBeginNode.prevBegin(replacee));
        UnmodifiableEconomicMap<Node, Node> duplicates = inlineSnippet(replacee, debug, replaceeGraph, replacements);
        // Re-wire the control flow graph around the replacee
        FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
        replacee.replaceAtPredecessor(firstCFGNodeDuplicate);
        rewireFrameStates(replacee, duplicates);
        if (replacee instanceof DeoptimizingNode) {
            DeoptimizingNode replaceeDeopt = (DeoptimizingNode) replacee;
            FrameState stateBefore = null;
            FrameState stateDuring = null;
            FrameState stateAfter = null;
            if (replaceeDeopt.canDeoptimize()) {
                if (replaceeDeopt instanceof DeoptimizingNode.DeoptBefore) {
                    stateBefore = ((DeoptimizingNode.DeoptBefore) replaceeDeopt).stateBefore();
                }
                if (replaceeDeopt instanceof DeoptimizingNode.DeoptDuring) {
                    stateDuring = ((DeoptimizingNode.DeoptDuring) replaceeDeopt).stateDuring();
                }
                if (replaceeDeopt instanceof DeoptimizingNode.DeoptAfter) {
                    stateAfter = ((DeoptimizingNode.DeoptAfter) replaceeDeopt).stateAfter();
                }
            }
            for (DeoptimizingNode deoptNode : deoptNodes) {
                DeoptimizingNode deoptDup = (DeoptimizingNode) duplicates.get(deoptNode.asNode());
                if (deoptDup.canDeoptimize()) {
                    if (deoptDup instanceof DeoptimizingNode.DeoptBefore) {
                        ((DeoptimizingNode.DeoptBefore) deoptDup).setStateBefore(stateBefore);
                    }
                    if (deoptDup instanceof DeoptimizingNode.DeoptDuring) {
                        DeoptimizingNode.DeoptDuring deoptDupDuring = (DeoptimizingNode.DeoptDuring) deoptDup;
                        if (stateDuring != null) {
                            deoptDupDuring.setStateDuring(stateDuring);
                        } else if (stateAfter != null) {
                            deoptDupDuring.computeStateDuring(stateAfter);
                        } else if (stateBefore != null) {
                            assert !deoptDupDuring.hasSideEffect() : "can't use stateBefore as stateDuring for state split " + deoptDupDuring;
                            deoptDupDuring.setStateDuring(stateBefore);
                        }
                    }
                    if (deoptDup instanceof DeoptimizingNode.DeoptAfter) {
                        DeoptimizingNode.DeoptAfter deoptDupAfter = (DeoptimizingNode.DeoptAfter) deoptDup;
                        if (stateAfter != null) {
                            deoptDupAfter.setStateAfter(stateAfter);
                        } else {
                            assert !deoptDupAfter.hasSideEffect() : "can't use stateBefore as stateAfter for state split " + deoptDupAfter;
                            deoptDupAfter.setStateAfter(stateBefore);
                        }
                    }
                }
            }
        }
        updateStamps(replacee, duplicates);
        rewireMemoryGraph(replacee, duplicates);
        // Replace all usages of the replacee with the value returned by the snippet
        ValueNode returnValue = null;
        if (returnNode != null && !(replacee instanceof ControlSinkNode)) {
            ReturnNode returnDuplicate = (ReturnNode) duplicates.get(returnNode);
            returnValue = returnDuplicate.result();
            if (returnValue == null && replacee.usages().isNotEmpty() && replacee instanceof MemoryCheckpoint) {
                replacer.replace(replacee, null);
            } else {
                assert returnValue != null || replacee.hasNoUsages();
                replacer.replace(replacee, returnValue);
            }
            if (returnDuplicate.isAlive()) {
                FixedNode next = null;
                if (replacee instanceof FixedWithNextNode) {
                    FixedWithNextNode fwn = (FixedWithNextNode) replacee;
                    next = fwn.next();
                    fwn.setNext(null);
                }
                returnDuplicate.replaceAndDelete(next);
            }
        }
        if (killReplacee) {
            // Remove the replacee from its graph
            GraphUtil.killCFG(replacee);
        }
        debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this);
        return duplicates;
    }
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) DebugContext(org.graalvm.compiler.debug.DebugContext) FixedNode(org.graalvm.compiler.nodes.FixedNode) FrameState(org.graalvm.compiler.nodes.FrameState) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 10 with FixedWithNextNode

use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.

the class CompileQueue method insertDeoptTests.

/**
 * Inserts a call to {@link DeoptTester#deoptTest} right after FixedWithNextNode StateSplits.
 *
 * @param method method that is being augmented with deopt test calls
 * @param graph The graph of a deoptimizable method or the corresponding deopt target method.
 */
private static void insertDeoptTests(HostedMethod method, StructuredGraph graph) {
    for (Node node : graph.getNodes()) {
        if (node instanceof FixedWithNextNode && node instanceof StateSplit && !(node instanceof InvokeNode) && !(node instanceof ForeignCallNode) && !(node instanceof DeoptTestNode) && !(method.isSynchronized() && node instanceof StartNode)) {
            FixedWithNextNode fixedWithNext = (FixedWithNextNode) node;
            FixedNode next = fixedWithNext.next();
            DeoptTestNode testNode = graph.add(new DeoptTestNode());
            fixedWithNext.setNext(null);
            testNode.setNext(next);
            fixedWithNext.setNext(testNode);
        }
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) StartNode(org.graalvm.compiler.nodes.StartNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) DeoptTestNode(com.oracle.svm.core.graal.nodes.DeoptTestNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) DeoptEntryNode(com.oracle.svm.core.graal.nodes.DeoptEntryNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) StartNode(org.graalvm.compiler.nodes.StartNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) DeoptTestNode(com.oracle.svm.core.graal.nodes.DeoptTestNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Aggregations

FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)57 FixedNode (org.graalvm.compiler.nodes.FixedNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)29 Node (org.graalvm.compiler.graph.Node)26 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)22 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)21 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)20 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)13 EndNode (org.graalvm.compiler.nodes.EndNode)12 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)12 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)10 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)9 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)9 Invoke (org.graalvm.compiler.nodes.Invoke)9 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)9 PhiNode (org.graalvm.compiler.nodes.PhiNode)9 IfNode (org.graalvm.compiler.nodes.IfNode)8 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)7 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7