Search in sources :

Example 46 with StructuredGraph

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

the class VerifyVirtualizableTest method testVirtualizableEffects.

@SuppressWarnings("try")
private static void testVirtualizableEffects(Class<?> c) {
    RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
    Providers providers = rt.getHostBackend().getProviders();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
    Plugins plugins = new Plugins(new InvocationPlugins());
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
    graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
    HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
    OptionValues options = getInitialOptions();
    DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
    for (Method m : c.getDeclaredMethods()) {
        if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
            ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
            StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
            graphBuilderSuite.apply(graph, context);
            try (DebugCloseable s = debug.disableIntercept()) {
                new VerifyVirtualizableUsage().apply(graph, context);
            }
        }
    }
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) OptionValues(org.graalvm.compiler.options.OptionValues) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Providers(org.graalvm.compiler.phases.util.Providers) VerifyVirtualizableUsage(org.graalvm.compiler.phases.verify.VerifyVirtualizableUsage) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 47 with StructuredGraph

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

the class AllocatorTest method testAllocation.

@SuppressWarnings("try")
protected void testAllocation(String snippet, final int expectedRegisters, final int expectedRegRegMoves, final int expectedSpillMoves) {
    final StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    try (DebugContext.Scope s = debug.scope("AllocatorTest", graph, graph.method(), getCodeCache())) {
        final RegisterStats stats = new RegisterStats(getLIRGenerationResult(graph).getLIR());
        try (DebugContext.Scope s2 = debug.scope("Assertions", stats.lir)) {
            Assert.assertEquals("register count", expectedRegisters, stats.registers.size());
            Assert.assertEquals("reg-reg moves", expectedRegRegMoves, stats.regRegMoves);
            Assert.assertEquals("spill moves", expectedSpillMoves, stats.spillMoves);
        } catch (Throwable e) {
            throw debug.handle(e);
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 48 with StructuredGraph

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

the class StraighteningTest method test.

private void test(final String snippet) {
    // No debug scope to reduce console noise for @Test(expected = ...) tests
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
    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) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 49 with StructuredGraph

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

the class TrivialInliningExplosionTest method parseForCompile.

@Override
protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
    final StructuredGraph graph = super.parseForCompile(method, compilationId, options);
    this.afterParseSize = graph.getNodeCount();
    return graph;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph)

Example 50 with StructuredGraph

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

the class TypeSystemTest method test.

private void test(String snippet, String referenceSnippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
    DebugContext debug = graph.getDebug();
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    /*
         * When using FlowSensitiveReductionPhase instead of ConditionalEliminationPhase,
         * tail-duplication gets activated thus resulting in a graph with more nodes than the
         * reference graph.
         */
    new ConditionalEliminationPhase(false).apply(graph, new PhaseContext(getProviders()));
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    // a second canonicalizer is needed to process nested MaterializeNodes
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO);
    new ConditionalEliminationPhase(false).apply(referenceGraph, new PhaseContext(getProviders()));
    new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
    new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
    assertEquals(referenceGraph, graph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext)

Aggregations

StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)360 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)97 Test (org.junit.Test)96 DebugContext (org.graalvm.compiler.debug.DebugContext)88 ValueNode (org.graalvm.compiler.nodes.ValueNode)70 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)62 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)62 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)57 Node (org.graalvm.compiler.graph.Node)39 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)37 OptionValues (org.graalvm.compiler.options.OptionValues)34 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)28 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)26 FixedNode (org.graalvm.compiler.nodes.FixedNode)26 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)25 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)24 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)24 LogicNode (org.graalvm.compiler.nodes.LogicNode)21 CompilationResult (org.graalvm.compiler.code.CompilationResult)19 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)19