use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.
the class CompareCanonicalizerTest3 method assertCanonicallyEqual.
protected void assertCanonicallyEqual(String snippet, String reference) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
CoreProviders context = getProviders();
CanonicalizerPhase canonicalizer = this.createCanonicalizerPhase();
canonicalizer.apply(graph, context);
new GuardLoweringPhase().apply(graph, new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo()));
new FrameStateAssignmentPhase().apply(graph);
canonicalizer.apply(graph, context);
StructuredGraph referenceGraph = parseEager(reference, AllowAssumptions.YES);
canonicalizer.apply(referenceGraph, context);
new GuardLoweringPhase().apply(referenceGraph, new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo()));
new FrameStateAssignmentPhase().apply(referenceGraph);
canonicalizer.apply(referenceGraph, context);
canonicalizer.apply(referenceGraph, context);
assertEquals(referenceGraph, graph, true, true);
}
use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.
the class ConditionalEliminationTest14 method test1.
@Test
public void test1() {
StructuredGraph graph = parseEager("test1Snippet", AllowAssumptions.YES);
CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
CoreProviders context = getProviders();
/* Convert the LoadIndexNode to ReadNode with floating guards. */
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
/* Convert the ReadNode to FloatingReadNode. */
new FloatingReadPhase().apply(graph);
/* Apply the phase that we want to test. */
new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context);
Assert.assertEquals("All guards must be floating", 0, graph.getNodes(FixedGuardNode.TYPE).count());
Assert.assertEquals("All array accesses must have been lowered", 0, graph.getNodes().filter(LoadIndexedNode.class).count());
Assert.assertEquals("All reads must be floating", 0, graph.getNodes().filter(ReadNode.class).count());
Assert.assertEquals("Must have floating reads (3 array accesses, 1 array length)", 4, graph.getNodes().filter(FloatingReadNode.class).count());
NodeIterable<GuardNode> boundsChecks = graph.getNodes(GuardNode.TYPE).filter(n -> ((GuardNode) n).getReason() == DeoptimizationReason.BoundsCheckException);
Assert.assertEquals("Must have only 1 bounds check remaining", 1, boundsChecks.count());
LogicNode condition = boundsChecks.first().getCondition();
Assert.assertTrue("Bounds check must check for array length 8", condition instanceof IntegerBelowNode && ((IntegerBelowNode) condition).getY().valueEquals(ConstantNode.forInt(8)));
}
use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.
the class ConditionalEliminationTest2 method testRedundantCompares.
@Test
public void testRedundantCompares() {
StructuredGraph graph = parseEager("testRedundantComparesSnippet", AllowAssumptions.YES);
CanonicalizerPhase canonicalizer = createCanonicalizerPhase();
CoreProviders context = getProviders();
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
canonicalizer.apply(graph, context);
new FloatingReadPhase().apply(graph);
new ConditionalEliminationPhase(true).apply(graph, context);
canonicalizer.apply(graph, context);
assertDeepEquals(1, graph.getNodes().filter(GuardNode.class).count());
}
use of org.graalvm.compiler.nodes.spi.CoreProviders in project graal by oracle.
the class LoopFullUnrollTest method test.
@SuppressWarnings("try")
private void test(String snippet, int loopCount) {
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope(getClass().getSimpleName(), new DebugDumpScope(snippet))) {
final StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, debug);
CoreProviders context = getProviders();
new LoopFullUnrollPhase(createCanonicalizerPhase(), new DefaultLoopPolicies()).apply(graph, context);
assertTrue(graph.getNodes().filter(LoopBeginNode.class).count() == loopCount);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.nodes.spi.CoreProviders 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) {
CoreProviders context = getProviders();
createCanonicalizerPhase().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);
encoder.verifyEncoding(originalGraph, encodedGraph);
}
}
Aggregations