Search in sources :

Example 16 with ParameterNode

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

the class BytecodeParser method createStateAfterStartOfReplacementGraph.

/**
 * Creates the frame state after the start node of a graph for an {@link IntrinsicContext
 * intrinsic} that is the parse root (either for root compiling or for post-parse inlining).
 */
private FrameState createStateAfterStartOfReplacementGraph() {
    assert parent == null;
    assert frameState.getMethod().equals(intrinsicContext.getIntrinsicMethod());
    assert bci() == 0;
    assert frameState.stackSize() == 0;
    FrameState stateAfterStart;
    if (intrinsicContext.isPostParseInlined()) {
        stateAfterStart = graph.add(new FrameState(BytecodeFrame.BEFORE_BCI));
    } else {
        ResolvedJavaMethod original = intrinsicContext.getOriginalMethod();
        ValueNode[] locals;
        if (original.getMaxLocals() == frameState.localsSize() || original.isNative()) {
            locals = new ValueNode[original.getMaxLocals()];
            for (int i = 0; i < locals.length; i++) {
                ValueNode node = frameState.locals[i];
                if (node == FrameState.TWO_SLOT_MARKER) {
                    node = null;
                }
                locals[i] = node;
            }
        } else {
            locals = new ValueNode[original.getMaxLocals()];
            int parameterCount = original.getSignature().getParameterCount(!original.isStatic());
            for (int i = 0; i < parameterCount; i++) {
                ValueNode param = frameState.locals[i];
                if (param == FrameState.TWO_SLOT_MARKER) {
                    param = null;
                }
                locals[i] = param;
                assert param == null || param instanceof ParameterNode || param.isConstant();
            }
        }
        ValueNode[] stack = {};
        int stackSize = 0;
        ValueNode[] locks = {};
        List<MonitorIdNode> monitorIds = Collections.emptyList();
        stateAfterStart = graph.add(new FrameState(null, new ResolvedJavaMethodBytecode(original), 0, locals, stack, stackSize, locks, monitorIds, false, false));
    }
    return stateAfterStart;
}
Also used : MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameState(org.graalvm.compiler.nodes.FrameState) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)

Example 17 with ParameterNode

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

the class SnippetStub method getGraph.

@Override
@SuppressWarnings("try")
protected StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId) {
    Plugins defaultPlugins = providers.getGraphBuilderPlugins();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    SnippetReflectionProvider snippetReflection = providers.getSnippetReflection();
    Plugins plugins = new Plugins(defaultPlugins);
    plugins.prependParameterPlugin(new ConstantBindingParameterPlugin(makeConstArgs(), metaAccess, snippetReflection));
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
    // Stubs cannot have optimistic assumptions since they have
    // to be valid for the entire run of the VM.
    final StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
    try (DebugContext.Scope outer = debug.scope("SnippetStub", graph)) {
        graph.disableUnsafeAccessTracking();
        IntrinsicContext initialIntrinsicContext = new IntrinsicContext(method, method, getReplacementsBytecodeProvider(), INLINE_AFTER_PARSING);
        GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialIntrinsicContext);
        instance.apply(graph);
        for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
            int index = param.index();
            if (method.getParameterAnnotation(NonNullParameter.class, index) != null) {
                param.setStamp(param.stamp(NodeView.DEFAULT).join(StampFactory.objectNonNull()));
            }
        }
        new RemoveValueProxyPhase().apply(graph);
        graph.setGuardsStage(GuardsStage.FLOATING_GUARDS);
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
        PhaseContext context = new PhaseContext(providers);
        canonicalizer.apply(graph, context);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return graph;
}
Also used : RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) NonNullParameter(org.graalvm.compiler.api.replacements.Snippet.NonNullParameter) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 18 with ParameterNode

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

the class IntegerExactFoldTest method testFolding.

@Test
public void testFolding() {
    StructuredGraph graph = prepareGraph();
    IntegerStamp a = StampFactory.forInteger(bits, lowerBoundA, upperBoundA);
    IntegerStamp b = StampFactory.forInteger(bits, lowerBoundB, upperBoundB);
    List<ParameterNode> params = graph.getNodes(ParameterNode.TYPE).snapshot();
    params.get(0).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(0), a)), x -> x instanceof IntegerExactArithmeticNode);
    params.get(1).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(1), b)), x -> x instanceof IntegerExactArithmeticNode);
    Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
    assertNotNull("original node must be in the graph", originalNode);
    new CanonicalizerPhase().apply(graph, getDefaultHighTierContext());
    ValueNode node = findNode(graph);
    boolean overflowExpected = node instanceof IntegerExactArithmeticNode;
    IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
    operation.verifyOverflow(lowerBoundA, upperBoundA, lowerBoundB, upperBoundB, bits, overflowExpected, resultStamp);
}
Also used : GuardsStage(org.graalvm.compiler.nodes.StructuredGraph.GuardsStage) LoweringTool(org.graalvm.compiler.nodes.spi.LoweringTool) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) ArrayList(java.util.ArrayList) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) Parameterized(org.junit.runners.Parameterized) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) NodeView(org.graalvm.compiler.nodes.NodeView) Test(org.junit.Test) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Node(org.graalvm.compiler.graph.Node) Assert(org.junit.Assert) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) PiNode(org.graalvm.compiler.nodes.PiNode) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Example 19 with ParameterNode

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

the class SystemArrayCopyTest method parse.

@Override
protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
    StructuredGraph graph = super.parse(builder, graphBuilderSuite);
    if (argsToBind != null) {
        ResolvedJavaMethod m = graph.method();
        Object receiver = isStatic(m.getModifiers()) ? null : this;
        Object[] args = argsWithReceiver(receiver, argsToBind);
        JavaType[] parameterTypes = m.toParameterTypes();
        assert parameterTypes.length == args.length;
        for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
            int index = param.index();
            if (args[index] != null) {
                JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[index].getJavaKind(), args[index]);
                ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
                param.replaceAtUsages(replacement);
            }
        }
    }
    return graph;
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 20 with ParameterNode

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

the class InstalledCodeExecuteHelperTest method parse.

@Override
protected StructuredGraph parse(Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
    StructuredGraph graph = super.parse(builder, graphBuilderSuite);
    if (argsToBind != null) {
        ResolvedJavaMethod m = graph.method();
        Object receiver = isStatic(m.getModifiers()) ? null : this;
        Object[] args = argsWithReceiver(receiver, argsToBind);
        JavaType[] parameterTypes = m.toParameterTypes();
        assert parameterTypes.length == args.length;
        for (int i = 0; i < argsToBind.length; i++) {
            ParameterNode param = graph.getParameter(i);
            JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[i].getJavaKind(), argsToBind[i]);
            ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
            param.replaceAtUsages(replacement);
        }
    }
    return graph;
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

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