use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class PEGraphDecoderTest method test.
@Test
@SuppressWarnings("try")
public void test() {
ResolvedJavaMethod testMethod = getResolvedJavaMethod(PEGraphDecoderTest.class, "doTest", Object.class);
StructuredGraph targetGraph = null;
DebugContext debug = getDebugContext();
try (DebugContext.Scope scope = debug.scope("GraphPETest", testMethod)) {
GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withEagerResolving(true).withUnresolvedIsError(true);
registerPlugins(graphBuilderConfig.getPlugins().getInvocationPlugins());
targetGraph = new StructuredGraph.Builder(getInitialOptions(), debug, AllowAssumptions.YES).method(testMethod).build();
CachingPEGraphDecoder decoder = new CachingPEGraphDecoder(getTarget().arch, targetGraph, getProviders(), graphBuilderConfig, OptimisticOptimizations.NONE, AllowAssumptions.YES, null, null, new InlineInvokePlugin[] { new InlineAll() }, null, null, null, null);
decoder.decode(testMethod, false);
debug.dump(DebugContext.BASIC_LEVEL, targetGraph, "Target Graph");
targetGraph.verify();
PhaseContext context = new PhaseContext(getProviders());
new CanonicalizerPhase().apply(targetGraph, context);
targetGraph.verify();
} catch (Throwable ex) {
if (targetGraph != null) {
debug.dump(DebugContext.BASIC_LEVEL, targetGraph, ex.toString());
}
debug.handle(ex);
}
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class HotSpotInvokeDynamicPluginTest method test.
private void test(String name, int expectedResolves, int expectedStubCalls) {
StructuredGraph graph = parseEager(name, AllowAssumptions.NO, new OptionValues(getInitialOptions(), GraalOptions.GeneratePIC, true));
MidTierContext midTierContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
Assert.assertEquals(expectedResolves, graph.getNodes().filter(ResolveDynamicConstantNode.class).count());
Assert.assertEquals(0, graph.getNodes().filter(ResolveDynamicStubCall.class).count());
PhaseContext context = new PhaseContext(getProviders());
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new GuardLoweringPhase().apply(graph, midTierContext);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
new FrameStateAssignmentPhase().apply(graph);
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.LOW_TIER).apply(graph, context);
Assert.assertEquals(0, graph.getNodes().filter(ResolveDynamicConstantNode.class).count());
Assert.assertEquals(expectedStubCalls, graph.getNodes().filter(ResolveDynamicStubCall.class).count());
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class ArraysSubstitutionsTest method testCanonicalEqual.
@Test
public void testCanonicalEqual() {
StructuredGraph graph = parseEager("testCanonicalEqualSnippet", AllowAssumptions.NO);
HighTierContext context = new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL);
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
Assert.assertTrue(graph.getNodes(ReturnNode.TYPE).first().result().asJavaConstant().asLong() == 1);
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class GraphEncoderTest method testStringMethods.
public void testStringMethods(boolean canonicalize) {
/* Encode and decode all methods of java.lang.String. */
List<StructuredGraph> originalGraphs = new ArrayList<>();
for (Method method : String.class.getDeclaredMethods()) {
ResolvedJavaMethod javaMethod = getMetaAccess().lookupJavaMethod(method);
if (javaMethod.hasBytecodes()) {
StructuredGraph originalGraph = parseEager(javaMethod, AllowAssumptions.YES);
if (canonicalize) {
PhaseContext context = new PhaseContext(getProviders());
new CanonicalizerPhase().apply(originalGraph, context);
}
originalGraphs.add(originalGraph);
}
}
GraphEncoder encoder = new GraphEncoder(getTarget().arch);
for (StructuredGraph originalGraph : originalGraphs) {
encoder.prepare(originalGraph);
}
encoder.finishPrepare();
Map<StructuredGraph, Integer> startOffsets = new HashMap<>();
for (StructuredGraph originalGraph : originalGraphs) {
startOffsets.put(originalGraph, encoder.encode(originalGraph));
}
for (StructuredGraph originalGraph : originalGraphs) {
EncodedGraph encodedGraph = new EncodedGraph(encoder.getEncoding(), startOffsets.get(originalGraph), encoder.getObjects(), encoder.getNodeClasses(), originalGraph);
GraphEncoder.verifyEncoding(originalGraph, encodedGraph, getTarget().arch);
}
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class CompareCanonicalizerTest method testCanonicalComparison.
@Test
public void testCanonicalComparison() {
StructuredGraph referenceGraph = parseEager("referenceCanonicalComparison", AllowAssumptions.NO);
for (int i = 1; i < 4; i++) {
StructuredGraph graph = parseEager("canonicalCompare" + i, AllowAssumptions.NO);
assertEquals(referenceGraph, graph);
}
new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
for (int i = 1; i < 4; i++) {
StructuredGraph graph = getCanonicalizedGraph("canonicalCompare" + i);
assertEquals(referenceGraph, graph);
}
}
Aggregations