Search in sources :

Example 6 with ReturnNode

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

the class SnippetTemplate method instantiate.

/**
 * Replaces a given floating node with this specialized snippet.
 *
 * This snippet must be pure data-flow
 *
 * @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
 */
@SuppressWarnings("try")
public void instantiate(MetaAccessProvider metaAccess, FloatingNode replacee, UsageReplacer replacer, Arguments args) {
    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();
        assert entryPointNode.next() == (memoryAnchor == null ? returnNode : memoryAnchor) : entryPointNode.next();
        StructuredGraph replaceeGraph = replacee.graph();
        EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args);
        MemoryAnchorNode anchorDuplicate = null;
        if (memoryAnchor != null) {
            anchorDuplicate = replaceeGraph.add(new MemoryAnchorNode());
            replacements.put(memoryAnchor, anchorDuplicate);
        }
        List<Node> floatingNodes = new ArrayList<>(nodes.size() - 2);
        for (Node n : nodes) {
            if (n != entryPointNode && n != returnNode) {
                floatingNodes.add(n);
            }
        }
        UnmodifiableEconomicMap<Node, Node> duplicates = inlineSnippet(replacee, debug, replaceeGraph, replacements);
        rewireFrameStates(replacee, duplicates);
        updateStamps(replacee, duplicates);
        rewireMemoryGraph(replacee, duplicates);
        assert anchorDuplicate == null || anchorDuplicate.isDeleted();
        // Replace all usages of the replacee with the value returned by the snippet
        ValueNode returnValue = (ValueNode) duplicates.get(returnNode.result());
        replacer.replace(replacee, returnValue);
        debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this);
    }
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) 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) ArrayList(java.util.ArrayList) ValueNode(org.graalvm.compiler.nodes.ValueNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 7 with ReturnNode

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

the class SimpleCFGTest method testImplies.

@Test
public void testImplies() {
    OptionValues options = getInitialOptions();
    DebugContext debug = DebugContext.create(options, new GraalDebugHandlersFactory(getSnippetReflection()));
    StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
    EndNode trueEnd = graph.add(new EndNode());
    EndNode falseEnd = graph.add(new EndNode());
    AbstractBeginNode trueBegin = graph.add(new BeginNode());
    trueBegin.setNext(trueEnd);
    AbstractBeginNode falseBegin = graph.add(new BeginNode());
    falseBegin.setNext(falseEnd);
    IfNode ifNode = graph.add(new IfNode(null, trueBegin, falseBegin, 0.5));
    graph.start().setNext(ifNode);
    AbstractMergeNode merge = graph.add(new MergeNode());
    merge.addForwardEnd(trueEnd);
    merge.addForwardEnd(falseEnd);
    ReturnNode returnNode = graph.add(new ReturnNode(null));
    merge.setNext(returnNode);
    dumpGraph(graph);
    ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, true, true);
    Block[] blocks = cfg.getBlocks();
    // check number of blocks
    assertDeepEquals(4, blocks.length);
    // check block - node assignment
    assertDeepEquals(blocks[0], cfg.blockFor(graph.start()));
    assertDeepEquals(blocks[0], cfg.blockFor(ifNode));
    assertDeepEquals(blocks[1], cfg.blockFor(trueBegin));
    assertDeepEquals(blocks[1], cfg.blockFor(trueEnd));
    assertDeepEquals(blocks[2], cfg.blockFor(falseBegin));
    assertDeepEquals(blocks[2], cfg.blockFor(falseEnd));
    assertDeepEquals(blocks[3], cfg.blockFor(merge));
    assertDeepEquals(blocks[3], cfg.blockFor(returnNode));
    // check dominators
    assertDominator(blocks[0], null);
    assertDominator(blocks[1], blocks[0]);
    assertDominator(blocks[2], blocks[0]);
    assertDominator(blocks[3], blocks[0]);
    // check dominated
    assertDominatedSize(blocks[0], 3);
    assertDominatedSize(blocks[1], 0);
    assertDominatedSize(blocks[2], 0);
    assertDominatedSize(blocks[3], 0);
    // check postdominators
    assertPostdominator(blocks[0], blocks[3]);
    assertPostdominator(blocks[1], blocks[3]);
    assertPostdominator(blocks[2], blocks[3]);
    assertPostdominator(blocks[3], null);
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) DebugContext(org.graalvm.compiler.debug.DebugContext) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) GraalDebugHandlersFactory(org.graalvm.compiler.printer.GraalDebugHandlersFactory) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) EndNode(org.graalvm.compiler.nodes.EndNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) Block(org.graalvm.compiler.nodes.cfg.Block) Test(org.junit.Test)

Example 8 with ReturnNode

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

the class EATestBase method testEscapeAnalysis.

/**
 * Runs Escape Analysis on the given snippet and makes sure that no allocations remain in the
 * graph.
 *
 * @param snippet the name of the method whose graph should be processed
 * @param expectedConstantResult if this is non-null, the resulting graph needs to have the
 *            given constant return value
 * @param iterativeEscapeAnalysis true if escape analysis should be run for more than one
 *            iteration
 */
protected void testEscapeAnalysis(String snippet, JavaConstant expectedConstantResult, boolean iterativeEscapeAnalysis) {
    prepareGraph(snippet, iterativeEscapeAnalysis);
    if (expectedConstantResult != null) {
        for (ReturnNode returnNode : returnNodes) {
            Assert.assertTrue(returnNode.result().toString(), returnNode.result().isConstant());
            Assert.assertEquals(expectedConstantResult, returnNode.result().asConstant());
        }
    }
    int newInstanceCount = graph.getNodes().filter(NewInstanceNode.class).count() + graph.getNodes().filter(NewArrayNode.class).count() + graph.getNodes().filter(CommitAllocationNode.class).count();
    Assert.assertEquals(0, newInstanceCount);
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode)

Example 9 with ReturnNode

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

the class LongNodeChainTest method longAddChain.

private void longAddChain(boolean reverse) {
    HighTierContext context = getDefaultHighTierContext();
    OptionValues options = getInitialOptions();
    StructuredGraph graph = new StructuredGraph.Builder(options, DebugContext.create(options, DebugHandlersFactory.LOADER)).build();
    ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
    ValueNode value = null;
    if (reverse) {
        // Make sure the constant's stamp is not used to infer the add node's stamp.
        OpaqueNode opaque = graph.unique(new OpaqueNode(constant));
        constant = opaque;
        AddNode addNode = graph.unique(new AddNode(constant, constant));
        value = addNode;
        for (int i = 1; i < N; ++i) {
            AddNode newAddNode = graph.addWithoutUnique(new AddNode(constant, constant));
            addNode.setY(newAddNode);
            addNode = newAddNode;
        }
        opaque.replaceAndDelete(opaque.getValue());
    } else {
        value = constant;
        for (int i = 0; i < N; ++i) {
            value = graph.unique(new AddNode(constant, value));
        }
    }
    ReturnNode returnNode = graph.add(new ReturnNode(value));
    graph.start().setNext(returnNode);
    for (SchedulingStrategy s : Strategies) {
        new SchedulePhase(s).apply(graph);
    }
    new CanonicalizerPhase().apply(graph, context);
    JavaConstant asConstant = (JavaConstant) returnNode.result().asConstant();
    Assert.assertEquals(N + 1, asConstant.asInt());
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) OptionValues(org.graalvm.compiler.options.OptionValues) JavaConstant(jdk.vm.ci.meta.JavaConstant) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) SchedulingStrategy(org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 10 with ReturnNode

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

the class HashMapGetTest method hashMapTest.

@Test
public void hashMapTest() {
    HashMap<Integer, Integer> map = new HashMap<>();
    ResolvedJavaMethod get = getResolvedJavaMethod(HashMapGetTest.class, "mapGet");
    for (int i = 0; i < 5000; i++) {
        mapGet(map, i);
        map.put(i, i);
        mapGet(map, i);
    }
    test(get, null, map, new Integer(0));
    for (IfNode ifNode : lastCompiledGraph.getNodes(IfNode.TYPE)) {
        LogicNode condition = ifNode.condition();
        if (ifNode.getTrueSuccessorProbability() < 0.4 && condition instanceof ObjectEqualsNode) {
            assertTrue(ifNode.trueSuccessor().next() instanceof ReturnNode, "Expected return.", ifNode.trueSuccessor(), ifNode.trueSuccessor().next());
        }
    }
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) HashMap(java.util.HashMap) ObjectEqualsNode(org.graalvm.compiler.nodes.calc.ObjectEqualsNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) IfNode(org.graalvm.compiler.nodes.IfNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test)

Aggregations

ReturnNode (org.graalvm.compiler.nodes.ReturnNode)40 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)22 ValueNode (org.graalvm.compiler.nodes.ValueNode)12 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)11 DebugContext (org.graalvm.compiler.debug.DebugContext)10 Node (org.graalvm.compiler.graph.Node)10 FixedNode (org.graalvm.compiler.nodes.FixedNode)10 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)8 Test (org.junit.Test)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)7 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)7 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)7 FrameState (org.graalvm.compiler.nodes.FrameState)7 MergeNode (org.graalvm.compiler.nodes.MergeNode)7 StartNode (org.graalvm.compiler.nodes.StartNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 PhiNode (org.graalvm.compiler.nodes.PhiNode)6 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)5 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)4 BeginNode (org.graalvm.compiler.nodes.BeginNode)4