Search in sources :

Example 1 with Mark

use of org.graalvm.compiler.graph.Graph.Mark in project graal by oracle.

the class LoweringPhase method checkPostLowering.

/**
 * Checks that second lowering of a given graph did not introduce any new nodes.
 *
 * @param graph a graph that was just {@linkplain #lower lowered}
 * @throws AssertionError if the check fails
 */
private boolean checkPostLowering(StructuredGraph graph, PhaseContext context) {
    Mark expectedMark = graph.getMark();
    lower(graph, context, LoweringMode.VERIFY_LOWERING);
    Mark mark = graph.getMark();
    assert mark.equals(expectedMark) : graph + ": a second round in the current lowering phase introduced these new nodes: " + graph.getNewNodes(expectedMark).snapshot();
    return true;
}
Also used : Mark(org.graalvm.compiler.graph.Graph.Mark)

Example 2 with Mark

use of org.graalvm.compiler.graph.Graph.Mark in project graal by oracle.

the class SnippetTemplate method inlineSnippet.

private UnmodifiableEconomicMap<Node, Node> inlineSnippet(Node replacee, DebugContext debug, StructuredGraph replaceeGraph, EconomicMap<Node, Node> replacements) {
    Mark mark = replaceeGraph.getMark();
    try (InliningLog.UpdateScope scope = replaceeGraph.getInliningLog().openUpdateScope((oldNode, newNode) -> {
        InliningLog log = replaceeGraph.getInliningLog();
        if (oldNode == null) {
            log.trackNewCallsite(newNode);
        }
    })) {
        UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements);
        if (scope != null) {
            replaceeGraph.getInliningLog().addLog(duplicates, snippet.getInliningLog());
        }
        NodeSourcePosition position = replacee.getNodeSourcePosition();
        InliningUtil.updateSourcePosition(replaceeGraph, duplicates, mark, position, true);
        debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After inlining snippet %s", snippet.method());
        return duplicates;
    }
}
Also used : InliningLog(org.graalvm.compiler.nodes.InliningLog) 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) Mark(org.graalvm.compiler.graph.Graph.Mark) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Example 3 with Mark

use of org.graalvm.compiler.graph.Graph.Mark in project graal by oracle.

the class SnippetTemplate method explodeLoops.

public static void explodeLoops(final StructuredGraph snippetCopy, PhaseContext phaseContext) {
    // Do any required loop explosion
    boolean exploded = false;
    do {
        exploded = false;
        ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first();
        if (explodeLoop != null) {
            // Earlier canonicalization may have removed the loop
            // altogether
            LoopBeginNode loopBegin = explodeLoop.findLoopBegin();
            if (loopBegin != null) {
                LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin);
                Mark mark = snippetCopy.getMark();
                LoopTransformations.fullUnroll(loop, phaseContext, new CanonicalizerPhase());
                new CanonicalizerPhase().applyIncremental(snippetCopy, phaseContext, mark);
                loop.deleteUnusedNodes();
            }
            GraphUtil.removeFixedWithUnusedInputs(explodeLoop);
            exploded = true;
        }
    } while (exploded);
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) LoopsData(org.graalvm.compiler.loop.LoopsData) LoopEx(org.graalvm.compiler.loop.LoopEx) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) Mark(org.graalvm.compiler.graph.Graph.Mark) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 4 with Mark

use of org.graalvm.compiler.graph.Graph.Mark in project graal by oracle.

the class BytecodeParser method guardIntrinsic.

/**
 * Weaves a test of the receiver type to ensure the dispatch will select {@code targetMethod}
 * and not another method that overrides it. This should only be called if there is an intrinsic
 * (i.e., an {@link InvocationPlugin}) for {@code targetMethod} and the invocation is indirect.
 *
 * The control flow woven around the intrinsic is as follows:
 *
 * <pre>
 *  if (LoadMethod(LoadHub(receiver)) == targetMethod) {
 *       <intrinsic for targetMethod>
 *  } else {
 *       <virtual call to targetMethod>
 *  }
 * </pre>
 *
 * The {@code else} branch is woven by {@link #afterInvocationPluginExecution}.
 *
 * @return {@code null} if the intrinsic cannot be used otherwise an object to be used by
 *         {@link #afterInvocationPluginExecution} to weave code for the non-intrinsic branch
 */
protected IntrinsicGuard guardIntrinsic(ValueNode[] args, ResolvedJavaMethod targetMethod, InvocationPluginReceiver pluginReceiver) {
    ValueNode intrinsicReceiver = args[0];
    ResolvedJavaType receiverType = StampTool.typeOrNull(intrinsicReceiver);
    if (receiverType == null) {
        // The verifier guarantees it to be at least type declaring targetMethod
        receiverType = targetMethod.getDeclaringClass();
    }
    ResolvedJavaMethod resolvedMethod = receiverType.resolveMethod(targetMethod, method.getDeclaringClass());
    if (resolvedMethod == null || resolvedMethod.equals(targetMethod)) {
        assert resolvedMethod == null || targetMethod.getDeclaringClass().isAssignableFrom(resolvedMethod.getDeclaringClass());
        Mark mark = graph.getMark();
        FixedWithNextNode currentLastInstr = lastInstr;
        ValueNode nonNullReceiver = pluginReceiver.get();
        Stamp methodStamp = stampProvider.createMethodStamp();
        LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, nonNullReceiver));
        LoadMethodNode actual = append(new LoadMethodNode(methodStamp, targetMethod, receiverType, method.getDeclaringClass(), hub));
        ConstantNode expected = graph.unique(ConstantNode.forConstant(methodStamp, targetMethod.getEncoding(), getMetaAccess()));
        LogicNode compare = graph.addOrUniqueWithInputs(CompareNode.createCompareNode(constantReflection, metaAccess, options, null, CanonicalCondition.EQ, actual, expected, NodeView.DEFAULT));
        JavaTypeProfile profile = null;
        if (profilingInfo != null && this.optimisticOpts.useTypeCheckHints(getOptions())) {
            profile = profilingInfo.getTypeProfile(bci());
            if (profile != null) {
                JavaTypeProfile newProfile = adjustProfileForInvocationPlugin(profile, targetMethod);
                if (newProfile != profile) {
                    if (newProfile.getTypes().length == 0) {
                        // All profiled types select the intrinsic so
                        // emit a fixed guard instead of an if-then-else.
                        lastInstr = append(new FixedGuardNode(compare, TypeCheckedInliningViolated, InvalidateReprofile, false));
                        return new IntrinsicGuard(currentLastInstr, intrinsicReceiver, mark, null, null);
                    }
                } else {
                    // No profiled types select the intrinsic so emit a virtual call
                    return null;
                }
                profile = newProfile;
            }
        }
        AbstractBeginNode intrinsicBranch = graph.add(new BeginNode());
        AbstractBeginNode nonIntrinsicBranch = graph.add(new BeginNode());
        append(new IfNode(compare, intrinsicBranch, nonIntrinsicBranch, FAST_PATH_PROBABILITY));
        lastInstr = intrinsicBranch;
        return new IntrinsicGuard(currentLastInstr, intrinsicReceiver, mark, nonIntrinsicBranch, profile);
    } else {
        // Receiver selects an overriding method so emit a virtual call
        return null;
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Mark(org.graalvm.compiler.graph.Graph.Mark) IfNode(org.graalvm.compiler.nodes.IfNode) LoadMethodNode(org.graalvm.compiler.nodes.extended.LoadMethodNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) JavaTypeProfile(jdk.vm.ci.meta.JavaTypeProfile) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 5 with Mark

use of org.graalvm.compiler.graph.Graph.Mark in project graal by oracle.

the class LoopTransformations method fullUnroll.

public static void fullUnroll(LoopEx loop, PhaseContext context, CanonicalizerPhase canonicalizer) {
    // assert loop.isCounted(); //TODO (gd) strengthen : counted with known trip count
    LoopBeginNode loopBegin = loop.loopBegin();
    StructuredGraph graph = loopBegin.graph();
    int initialNodeCount = graph.getNodeCount();
    while (!loopBegin.isDeleted()) {
        Mark mark = graph.getMark();
        peel(loop);
        canonicalizer.applyIncremental(graph, context, mark);
        loop.invalidateFragments();
        if (graph.getNodeCount() > initialNodeCount + MaximumDesiredSize.getValue(graph.getOptions()) * 2) {
            throw new RetryableBailoutException("FullUnroll : Graph seems to grow out of proportion");
        }
    }
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) RetryableBailoutException(org.graalvm.compiler.core.common.RetryableBailoutException) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Mark(org.graalvm.compiler.graph.Graph.Mark)

Aggregations

Mark (org.graalvm.compiler.graph.Graph.Mark)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)4 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)4 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)4 Node (org.graalvm.compiler.graph.Node)3 BeginNode (org.graalvm.compiler.nodes.BeginNode)3 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)3 FixedNode (org.graalvm.compiler.nodes.FixedNode)3 LogicNode (org.graalvm.compiler.nodes.LogicNode)3 PhiNode (org.graalvm.compiler.nodes.PhiNode)3 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)2 InliningLog (org.graalvm.compiler.nodes.InliningLog)2 KillingBeginNode (org.graalvm.compiler.nodes.KillingBeginNode)2 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)2 ExplodeLoopNode (org.graalvm.compiler.replacements.nodes.ExplodeLoopNode)2