use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.
the class ReplacementsParseTest method testGraph.
@SuppressWarnings("try")
private void testGraph(String name) {
StructuredGraph graph = parseEager(name, StructuredGraph.AllowAssumptions.YES);
try (DebugContext.Scope s0 = graph.getDebug().scope(name, graph)) {
for (OpaqueNode node : graph.getNodes().filter(OpaqueNode.class)) {
node.replaceAndDelete(node.getValue());
}
HighTierContext context = getDefaultHighTierContext();
CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new FloatingReadPhase().apply(graph);
canonicalizer.apply(graph, context);
new DeadCodeEliminationPhase().apply(graph);
new GuardLoweringPhase().apply(graph, getDefaultMidTierContext());
new FrameStateAssignmentPhase().apply(graph);
} catch (Throwable e) {
throw graph.getDebug().handle(e);
}
}
use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.
the class MethodSubstitutionTest method testGraph.
@SuppressWarnings("try")
protected StructuredGraph testGraph(final String snippet, String name) {
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope("MethodSubstitutionTest", getResolvedJavaMethod(snippet))) {
StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
HighTierContext context = getDefaultHighTierContext();
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
new InliningPhase(new CanonicalizerPhase()).apply(graph, context);
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
new CanonicalizerPhase().apply(graph, context);
new DeadCodeEliminationPhase().apply(graph);
// Try to ensure any macro nodes are lowered to expose any resulting invokes
if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
}
if (graph.getNodes().filter(MacroNode.class).isNotEmpty()) {
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
}
assertNotInGraph(graph, MacroNode.class);
if (name != null) {
for (Node node : graph.getNodes()) {
if (node instanceof Invoke) {
Invoke invoke = (Invoke) node;
if (invoke.callTarget() instanceof MethodCallTargetNode) {
MethodCallTargetNode call = (MethodCallTargetNode) invoke.callTarget();
assertTrue(!call.targetMethod().getName().equals(name), "Unexpected invoke of intrinsic %s", call.targetMethod());
}
}
}
} else {
assertNotInGraph(graph, Invoke.class);
}
return graph;
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.
the class PartialEscapeAnalysisTest method testPartialEscapeAnalysis.
@SafeVarargs
protected final void testPartialEscapeAnalysis(String snippet, double expectedProbability, int expectedCount, Class<? extends Node>... invalidNodeClasses) {
prepareGraph(snippet, false);
for (AbstractMergeNode merge : graph.getNodes(AbstractMergeNode.TYPE)) {
merge.setStateAfter(null);
}
new DeadCodeEliminationPhase().apply(graph);
new CanonicalizerPhase().apply(graph, context);
try {
Assert.assertTrue("partial escape analysis should have removed all NewInstanceNode allocations", graph.getNodes().filter(NewInstanceNode.class).isEmpty());
Assert.assertTrue("partial escape analysis should have removed all NewArrayNode allocations", graph.getNodes().filter(NewArrayNode.class).isEmpty());
ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
double probabilitySum = 0;
int materializeCount = 0;
for (CommitAllocationNode materialize : graph.getNodes().filter(CommitAllocationNode.class)) {
probabilitySum += cfg.blockFor(materialize).probability() * materialize.getVirtualObjects().size();
materializeCount += materialize.getVirtualObjects().size();
}
Assert.assertEquals("unexpected number of MaterializeObjectNodes", expectedCount, materializeCount);
Assert.assertEquals("unexpected probability of MaterializeObjectNodes", expectedProbability, probabilitySum, 0.01);
for (Node node : graph.getNodes()) {
for (Class<? extends Node> clazz : invalidNodeClasses) {
Assert.assertFalse("instance of invalid class: " + clazz.getSimpleName(), clazz.isInstance(node) && node.usages().isNotEmpty());
}
}
} catch (AssertionError e) {
TypeSystemTest.outputGraph(graph, snippet + ": " + e.getMessage());
throw e;
}
}
use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase in project graal by oracle.
the class NestedLoopEffectsPhaseComplexityTest method parseBytecodes.
private StructuredGraph parseBytecodes(ResolvedJavaMethod method, HighTierContext context, CanonicalizerPhase canonicalizer) {
OptionValues options = getInitialOptions();
StructuredGraph newGraph = new StructuredGraph.Builder(options, getDebugContext(options, null, method), AllowAssumptions.NO).method(method).build();
context.getGraphBuilderSuite().apply(newGraph, context);
new DeadCodeEliminationPhase(Optional).apply(newGraph);
canonicalizer.apply(newGraph, context);
return newGraph;
}
use of org.graalvm.compiler.phases.common.DeadCodeEliminationPhase 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