use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class ArraysSubstitutionsTest method testCanonicalLength.
@Test
public void testCanonicalLength() {
StructuredGraph graph = parseEager("testCanonicalLengthSnippet", 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() == 0);
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class IntegerExactFoldTest method testFoldingAfterLowering.
@Test
public void testFoldingAfterLowering() {
StructuredGraph graph = prepareGraph();
Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
assertNotNull("original node must be in the graph", originalNode);
graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
PhaseContext context = new PhaseContext(getProviders());
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
IntegerExactArithmeticSplitNode loweredNode = graph.getNodes().filter(IntegerExactArithmeticSplitNode.class).first();
assertNotNull("the lowered node must be in the graph", loweredNode);
loweredNode.getX().setStamp(StampFactory.forInteger(bits, lowerBoundA, upperBoundA));
loweredNode.getY().setStamp(StampFactory.forInteger(bits, lowerBoundB, upperBoundB));
new CanonicalizerPhase().apply(graph, context);
ValueNode node = findNode(graph);
boolean overflowExpected = node instanceof IntegerExactArithmeticSplitNode;
IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
operation.verifyOverflow(lowerBoundA, upperBoundA, lowerBoundB, upperBoundB, bits, overflowExpected, resultStamp);
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class PoorMansEATest method test.
@SuppressWarnings("try")
private void test(final String snippet) {
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope("PoorMansEATest", new DebugDumpScope(snippet))) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO);
HighTierContext highTierContext = getDefaultHighTierContext();
new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext);
PhaseContext context = new PhaseContext(getProviders());
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
// remove framestates in order to trigger the simplification.
cleanup: for (FrameState fs : graph.getNodes(FrameState.TYPE).snapshot()) {
for (Node input : fs.inputs()) {
if (input instanceof NewInstanceNode) {
fs.replaceAtUsages(null);
fs.safeDelete();
continue cleanup;
}
}
}
new CanonicalizerPhase().apply(graph, context);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class UnusedArray method test.
public void test(String method) {
StructuredGraph graph = parseEager(method, StructuredGraph.AllowAssumptions.YES);
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
NodeIterable<NewArrayNode> newArrayNodes = graph.getNodes().filter(NewArrayNode.class);
assertThat(newArrayNodes, isEmpty());
}
use of org.graalvm.compiler.phases.tiers.PhaseContext in project graal by oracle.
the class CompiledMethodTest method test1.
/**
* Usages of the constant {@code " "} are replaced with the constant {@code "-"} and it is
* verified that executing the compiled code produces a result that the preserves the node
* replacement unless deoptimization occurs (e.g., due to -Xcomp causing profiles to be
* missing).
*/
@Test
public void test1() {
final ResolvedJavaMethod javaMethod = getResolvedJavaMethod("testMethod");
final StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.NO);
new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
new DeadCodeEliminationPhase().apply(graph);
for (ConstantNode node : ConstantNode.getConstantNodes(graph)) {
if (node.getStackKind() == JavaKind.Object && " ".equals(getSnippetReflection().asObject(String.class, node.asJavaConstant()))) {
node.replace(graph, ConstantNode.forConstant(getSnippetReflection().forObject("-"), getMetaAccess(), graph));
}
}
InstalledCode compiledMethod = getCode(javaMethod, graph);
try {
Object result = compiledMethod.executeVarargs("1", "2", "3");
if (!"1-2-3".equals(result)) {
// Deoptimization probably occurred
Assert.assertEquals("interpreter", result);
}
} catch (InvalidInstalledCodeException t) {
Assert.fail("method invalidated");
}
}
Aggregations