Search in sources :

Example 6 with ParameterNode

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

the class DefaultHotSpotLoweringProvider method lowerOSRStartNode.

private void lowerOSRStartNode(OSRStartNode osrStart) {
    StructuredGraph graph = osrStart.graph();
    if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
        StartNode newStart = graph.add(new StartNode());
        ParameterNode buffer = graph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(StampFactory.forKind(runtime.getTarget().wordJavaKind))));
        ForeignCallNode migrationEnd = graph.add(new ForeignCallNode(foreignCalls, OSR_MIGRATION_END, buffer));
        migrationEnd.setStateAfter(osrStart.stateAfter());
        newStart.setNext(migrationEnd);
        FixedNode next = osrStart.next();
        osrStart.setNext(null);
        migrationEnd.setNext(next);
        graph.setStart(newStart);
        final int wordSize = target.wordSize;
        // @formatter:off
        // taken from c2 locals_addr = osr_buf + (max_locals-1)*wordSize)
        // @formatter:on
        int localsOffset = (graph.method().getMaxLocals() - 1) * wordSize;
        for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.TYPE)) {
            int size = osrLocal.getStackKind().getSlotCount();
            int offset = localsOffset - (osrLocal.index() + size - 1) * wordSize;
            AddressNode address = createOffsetAddress(graph, buffer, offset);
            ReadNode load = graph.add(new ReadNode(address, any(), osrLocal.stamp(NodeView.DEFAULT), BarrierType.NONE));
            osrLocal.replaceAndDelete(load);
            graph.addBeforeFixed(migrationEnd, load);
        }
        // @formatter:off
        // taken from c2 monitors_addr = osr_buf + (max_locals+mcnt*2-1)*wordSize);
        // @formatter:on
        final int lockCount = osrStart.stateAfter().locksSize();
        final int locksOffset = (graph.method().getMaxLocals() + lockCount * 2 - 1) * wordSize;
        // buffer
        for (OSRMonitorEnterNode osrMonitorEnter : graph.getNodes(OSRMonitorEnterNode.TYPE)) {
            MonitorIdNode monitorID = osrMonitorEnter.getMonitorId();
            OSRLockNode lock = (OSRLockNode) osrMonitorEnter.object();
            final int index = lock.index();
            final int offsetDisplacedHeader = locksOffset - ((index * 2) + 1) * wordSize;
            final int offsetLockObject = locksOffset - index * 2 * wordSize;
            // load the displaced mark from the osr buffer
            AddressNode addressDisplacedHeader = createOffsetAddress(graph, buffer, offsetDisplacedHeader);
            ReadNode loadDisplacedHeader = graph.add(new ReadNode(addressDisplacedHeader, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
            graph.addBeforeFixed(migrationEnd, loadDisplacedHeader);
            // we need to initialize the stack slot for the lock
            BeginLockScopeNode beginLockScope = graph.add(new BeginLockScopeNode(lock.getStackKind(), monitorID.getLockDepth()));
            graph.addBeforeFixed(migrationEnd, beginLockScope);
            // write the displaced mark to the correct stack slot
            AddressNode addressDisplacedMark = createOffsetAddress(graph, beginLockScope, runtime.getVMConfig().basicLockDisplacedHeaderOffset);
            WriteNode writeStackSlot = graph.add(new WriteNode(addressDisplacedMark, DISPLACED_MARK_WORD_LOCATION, loadDisplacedHeader, BarrierType.NONE));
            graph.addBeforeFixed(migrationEnd, writeStackSlot);
            // load the lock object from the osr buffer
            AddressNode addressLockObject = createOffsetAddress(graph, buffer, offsetLockObject);
            ReadNode loadObject = graph.add(new ReadNode(addressLockObject, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
            lock.replaceAndDelete(loadObject);
            graph.addBeforeFixed(migrationEnd, loadObject);
        }
        osrStart.replaceAtUsagesAndDelete(newStart);
    }
}
Also used : MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) OSRStartNode(org.graalvm.compiler.nodes.extended.OSRStartNode) StartNode(org.graalvm.compiler.nodes.StartNode) OSRLocalNode(org.graalvm.compiler.nodes.extended.OSRLocalNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) OSRLockNode(org.graalvm.compiler.nodes.extended.OSRLockNode) OSRMonitorEnterNode(org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) BeginLockScopeNode(org.graalvm.compiler.hotspot.nodes.BeginLockScopeNode) GetObjectAddressNode(org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode) ComputeObjectAddressNode(org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode)

Example 7 with ParameterNode

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

the class SnippetTemplate method toString.

@Override
public String toString() {
    StringBuilder buf = new StringBuilder(snippet.toString()).append('(');
    String sep = "";
    for (int i = 0; i < parameters.length; i++) {
        String name = "[" + i + "]";
        Object value = parameters[i];
        buf.append(sep);
        sep = ", ";
        if (value == null) {
            buf.append("<null> ").append(name);
        } else if (value.equals(UNUSED_PARAMETER)) {
            buf.append("<unused> ").append(name);
        } else if (value.equals(CONSTANT_PARAMETER)) {
            buf.append("<constant> ").append(name);
        } else if (value instanceof ParameterNode) {
            ParameterNode param = (ParameterNode) value;
            buf.append(param.getStackKind().getJavaName()).append(' ').append(name);
        } else {
            ParameterNode[] params = (ParameterNode[]) value;
            String kind = params.length == 0 ? "?" : params[0].getStackKind().getJavaName();
            buf.append(kind).append('[').append(params.length).append("] ").append(name);
        }
    }
    return buf.append(')').toString();
}
Also used : LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint)

Example 8 with ParameterNode

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

the class SnippetTemplate method bind.

/**
 * Gets the instantiation-time bindings to this template's parameters.
 *
 * @return the map that will be used to bind arguments to parameters when inlining this template
 */
private EconomicMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider metaAccess, Arguments args) {
    EconomicMap<Node, Node> replacements = EconomicMap.create(Equivalence.IDENTITY);
    assert args.info.getParameterCount() == parameters.length : "number of args (" + args.info.getParameterCount() + ") != number of parameters (" + parameters.length + ")";
    for (int i = 0; i < parameters.length; i++) {
        Object parameter = parameters[i];
        assert parameter != null : this + " has no parameter named " + args.info.getParameterName(i);
        Object argument = args.values[i];
        if (parameter instanceof ParameterNode) {
            if (argument instanceof ValueNode) {
                replacements.put((ParameterNode) parameter, (ValueNode) argument);
            } else {
                JavaKind kind = ((ParameterNode) parameter).getStackKind();
                assert argument != null || kind == JavaKind.Object : this + " cannot accept null for non-object parameter named " + args.info.getParameterName(i);
                JavaConstant constant = forBoxed(argument, kind);
                replacements.put((ParameterNode) parameter, ConstantNode.forConstant(constant, metaAccess, replaceeGraph));
            }
        } else if (parameter instanceof ParameterNode[]) {
            ParameterNode[] params = (ParameterNode[]) parameter;
            Varargs varargs = (Varargs) argument;
            int length = params.length;
            List<?> list = null;
            Object array = null;
            if (varargs.value instanceof List) {
                list = (List<?>) varargs.value;
                assert list.size() == length : length + " != " + list.size();
            } else {
                array = varargs.value;
                assert array != null && array.getClass().isArray();
                assert Array.getLength(array) == length : length + " != " + Array.getLength(array);
            }
            for (int j = 0; j < length; j++) {
                ParameterNode param = params[j];
                assert param != null;
                Object value = list != null ? list.get(j) : Array.get(array, j);
                if (value instanceof ValueNode) {
                    replacements.put(param, (ValueNode) value);
                } else {
                    JavaConstant constant = forBoxed(value, param.getStackKind());
                    ConstantNode element = ConstantNode.forConstant(constant, metaAccess, replaceeGraph);
                    replacements.put(param, element);
                }
            }
        } else {
            assert parameter.equals(CONSTANT_PARAMETER) || parameter.equals(UNUSED_PARAMETER) : "unexpected entry for parameter: " + args.info.getParameterName(i) + " -> " + parameter;
        }
    }
    return replacements;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) 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) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ArrayList(java.util.ArrayList) List(java.util.List) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 9 with ParameterNode

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

the class SnippetTemplate method updateStamps.

private void updateStamps(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates) {
    for (ValueNode node : placeholderStampedNodes) {
        ValueNode dup = (ValueNode) duplicates.get(node);
        Stamp replaceeStamp = replacee.stamp(NodeView.DEFAULT);
        if (node instanceof Placeholder) {
            Placeholder placeholderDup = (Placeholder) dup;
            placeholderDup.makeReplacement(replaceeStamp);
        } else {
            dup.setStamp(replaceeStamp);
        }
    }
    for (ParameterNode paramNode : snippet.getNodes(ParameterNode.TYPE)) {
        for (Node usage : paramNode.usages()) {
            Node usageDup = duplicates.get(usage);
            propagateStamp(usageDup);
        }
    }
}
Also used : Placeholder(org.graalvm.compiler.nodes.PiNode.Placeholder) Stamp(org.graalvm.compiler.core.common.type.Stamp) PlaceholderStamp(org.graalvm.compiler.nodes.PiNode.PlaceholderStamp) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) 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) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 10 with ParameterNode

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

the class EAMergingTest method testSimpleMerge.

@Test
public void testSimpleMerge() {
    testEscapeAnalysis("simpleMergeSnippet", null, false);
    assertDeepEquals(1, returnNodes.size());
    assertTrue(returnNodes.get(0).result() instanceof ValuePhiNode);
    PhiNode phi = (PhiNode) returnNodes.get(0).result();
    assertTrue(phi.valueAt(0) instanceof ParameterNode);
    assertTrue(phi.valueAt(1) instanceof ParameterNode);
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) Test(org.junit.Test)

Aggregations

ParameterNode (org.graalvm.compiler.nodes.ParameterNode)46 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)19 ValueNode (org.graalvm.compiler.nodes.ValueNode)19 Node (org.graalvm.compiler.graph.Node)13 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)13 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)13 Test (org.junit.Test)10 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 DebugContext (org.graalvm.compiler.debug.DebugContext)7 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)7 FrameState (org.graalvm.compiler.nodes.FrameState)7 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)7 FixedNode (org.graalvm.compiler.nodes.FixedNode)6 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)6 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)5 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)5 PhiNode (org.graalvm.compiler.nodes.PhiNode)5 ArrayList (java.util.ArrayList)4 JavaConstant (jdk.vm.ci.meta.JavaConstant)4