Search in sources :

Example 1 with PhaseContext

use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.

the class ConditionAnchoringTest method test.

public void test(String name, int ids) {
    StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
    NodeIterable<RawLoadNode> unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    assertThat(unsafeNodes, hasCount(1));
    // lower unsafe load
    PhaseContext context = new PhaseContext(getProviders());
    LoweringPhase lowering = new LoweringPhase(new CanonicalizerPhase(), StandardLoweringStage.HIGH_TIER);
    lowering.apply(graph, context);
    unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    NodeIterable<ConditionAnchorNode> conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    NodeIterable<ReadNode> reads = graph.getNodes().filter(ReadNode.class);
    assertThat(unsafeNodes, isEmpty());
    assertThat(conditionAnchors, hasCount(1));
    // 2 * ids id reads, 1 'field' access
    assertThat(reads, hasCount(2 * ids + 1));
    // float reads and canonicalize to give a chance to conditions to GVN
    FloatingReadPhase floatingReadPhase = new FloatingReadPhase();
    floatingReadPhase.apply(graph);
    CanonicalizerPhase canonicalizerPhase = new CanonicalizerPhase();
    canonicalizerPhase.apply(graph, context);
    NodeIterable<FloatingReadNode> floatingReads = graph.getNodes().filter(FloatingReadNode.class);
    // 1 id read, 1 'field' access
    assertThat(floatingReads, hasCount(ids + 1));
    new ConditionalEliminationPhase(false).apply(graph, context);
    floatingReads = graph.getNodes().filter(FloatingReadNode.class).filter(n -> ((FloatingReadNode) n).getLocationIdentity() instanceof ObjectLocationIdentity);
    conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    assertThat(floatingReads, hasCount(1));
    assertThat(conditionAnchors, isEmpty());
    FloatingReadNode readNode = floatingReads.first();
    assertThat(readNode.getGuard(), instanceOf(BeginNode.class));
    assertThat(readNode.getGuard().asNode().predecessor(), instanceOf(IfNode.class));
}
Also used : RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) Unsafe(sun.misc.Unsafe) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) TruffleGraphBuilderPlugins(org.graalvm.compiler.truffle.compiler.substitutions.TruffleGraphBuilderPlugins) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) NodeIterableIsEmpty.isEmpty(org.graalvm.compiler.graph.test.matchers.NodeIterableIsEmpty.isEmpty) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assert.assertThat(org.junit.Assert.assertThat) InlineInfo.createStandardInlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo) JavaKind(jdk.vm.ci.meta.JavaKind) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) IfNode(org.graalvm.compiler.nodes.IfNode) Test(org.junit.Test) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) NodeIterableCount.hasCount(org.graalvm.compiler.graph.test.matchers.NodeIterableCount.hasCount) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) StandardLoweringStage(org.graalvm.compiler.nodes.spi.LoweringTool.StandardLoweringStage) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) IfNode(org.graalvm.compiler.nodes.IfNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) BeginNode(org.graalvm.compiler.nodes.BeginNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode)

Example 2 with PhaseContext

use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.

the class PartialEvaluator method createGraph.

@SuppressWarnings("try")
public StructuredGraph createGraph(DebugContext debug, final CompilableTruffleAST compilable, TruffleInliningPlan inliningPlan, AllowAssumptions allowAssumptions, CompilationIdentifier compilationId, SpeculationLog log, Cancellable cancellable) {
    String name = compilable.toString();
    OptionValues options = TruffleCompilerOptions.getOptions();
    ResolvedJavaMethod rootMethod = rootForCallTarget(compilable);
    // @formatter:off
    final StructuredGraph graph = new StructuredGraph.Builder(options, debug, allowAssumptions).name(name).method(rootMethod).speculationLog(log).compilationId(compilationId).cancellable(cancellable).build();
    try (DebugContext.Scope s = debug.scope("CreateGraph", graph);
        Indent indent = debug.logAndIndent("createGraph %s", graph)) {
        PhaseContext baseContext = new PhaseContext(providers);
        HighTierContext tierContext = new HighTierContext(providers, new PhaseSuite<HighTierContext>(), OptimisticOptimizations.NONE);
        fastPartialEvaluation(compilable, inliningPlan, graph, baseContext, tierContext);
        if (cancellable != null && cancellable.isCancelled()) {
            return null;
        }
        new VerifyFrameDoesNotEscapePhase().apply(graph, false);
        postPartialEvaluation(graph);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return graph;
}
Also used : Indent(org.graalvm.compiler.debug.Indent) VerifyFrameDoesNotEscapePhase(org.graalvm.compiler.truffle.compiler.phases.VerifyFrameDoesNotEscapePhase) OptionValues(org.graalvm.compiler.options.OptionValues) DebugContext(org.graalvm.compiler.debug.DebugContext) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with PhaseContext

use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.

the class RuntimeStrengthenStampsPhase method beforeCompilation.

@Override
@SuppressWarnings("try")
public void beforeCompilation(BeforeCompilationAccess c) {
    CompilationAccessImpl config = (CompilationAccessImpl) c;
    if (Options.PrintRuntimeCompileMethods.getValue()) {
        printCallTree();
    }
    System.out.println(methods.size() + " method(s) included for runtime compilation");
    if (Options.PrintStaticTruffleBoundaries.getValue()) {
        printStaticTruffleBoundaries();
    }
    Integer maxMethods = Options.MaxRuntimeCompileMethods.getValue();
    if (maxMethods != 0 && methods.size() > maxMethods) {
        printDeepestLevelPath();
        throw VMError.shouldNotReachHere("Number of methods for runtime compilation exceeds the allowed limit: " + methods.size() + " > " + maxMethods);
    }
    HostedMetaAccess hMetaAccess = config.getMetaAccess();
    runtimeConfigBuilder.updateLazyState(hMetaAccess);
    /*
         * Start fresh with a new GraphEncoder, since we are going to optimize all graphs now that
         * the static analysis results are available.
         */
    graphEncoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
    StrengthenStampsPhase strengthenStamps = new RuntimeStrengthenStampsPhase(config.getUniverse(), objectReplacer);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext phaseContext = new PhaseContext(hostedProviders);
    for (CallTreeNode node : methods.values()) {
        StructuredGraph graph = node.graph;
        if (graph != null) {
            DebugContext debug = graph.getDebug();
            try (DebugContext.Scope scope = debug.scope("RuntimeOptimize", graph)) {
                removeUnreachableInvokes(node);
                strengthenStamps.apply(graph);
                canonicalizer.apply(graph, phaseContext);
                GraalConfiguration.instance().runAdditionalCompilerPhases(graph, this);
                canonicalizer.apply(graph, phaseContext);
                graphEncoder.prepare(graph);
            } catch (Throwable ex) {
                debug.handle(ex);
            }
        }
    }
    graphEncoder.finishPrepare();
    for (CallTreeNode node : methods.values()) {
        if (node.graph != null) {
            registerDeoptEntries(node);
            long startOffset = graphEncoder.encode(node.graph);
            objectReplacer.createMethod(node.implementationMethod).setEncodedGraphStartOffset(startOffset);
            /* We do not need the graph anymore, let the GC do it's work. */
            node.graph = null;
        }
    }
    GraalSupport.setGraphEncoding(graphEncoder.getEncoding(), graphEncoder.getObjects(), graphEncoder.getNodeClasses());
    objectReplacer.updateDataDuringAnalysis((AnalysisMetaAccess) hMetaAccess.getWrapped());
}
Also used : CompilationAccessImpl(com.oracle.svm.hosted.FeatureImpl.CompilationAccessImpl) GraphEncoder(org.graalvm.compiler.nodes.GraphEncoder) DebugContext(org.graalvm.compiler.debug.DebugContext) HostedMetaAccess(com.oracle.svm.hosted.meta.HostedMetaAccess) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) StrengthenStampsPhase(com.oracle.svm.hosted.phases.StrengthenStampsPhase)

Example 4 with PhaseContext

use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.

the class ScalarTypeSystemTest method test.

private void test(final String snippet, final String referenceSnippet) {
    // No debug scope to reduce console noise for @Test(expected = ...) tests
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    graph.getDebug().dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    PhaseContext context = new PhaseContext(getProviders());
    new CanonicalizerPhase().apply(graph, context);
    StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
    assertEquals(referenceGraph, graph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 5 with PhaseContext

use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.

the class StampCanonicalizerTest method testZeroReturn.

private void testZeroReturn(String methodName) {
    StructuredGraph graph = parseEager(methodName, AllowAssumptions.YES);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    new DeadCodeEliminationPhase().apply(graph);
    assertConstantReturn(graph, 0);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase)

Aggregations

PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)60 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)59 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)56 DebugContext (org.graalvm.compiler.debug.DebugContext)24 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)19 Test (org.junit.Test)18 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)8 ConditionalEliminationPhase (org.graalvm.compiler.phases.common.ConditionalEliminationPhase)7 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)7 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)6 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)6 FrameState (org.graalvm.compiler.nodes.FrameState)6 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)6 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)5 Node (org.graalvm.compiler.graph.Node)5 OptionValues (org.graalvm.compiler.options.OptionValues)5 GuardLoweringPhase (org.graalvm.compiler.phases.common.GuardLoweringPhase)5 IterativeConditionalEliminationPhase (org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase)4 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)4 PartialEscapePhase (org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase)4