39 import org.graalvm.compiler.nodes.StructuredGraph; |
39 import org.graalvm.compiler.nodes.StructuredGraph; |
40 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; |
40 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; |
41 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult; |
41 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult; |
42 import org.graalvm.compiler.nodes.cfg.Block; |
42 import org.graalvm.compiler.nodes.cfg.Block; |
43 import org.graalvm.compiler.nodes.java.InstanceOfNode; |
43 import org.graalvm.compiler.nodes.java.InstanceOfNode; |
44 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
|
45 import org.graalvm.compiler.phases.common.ConditionalEliminationPhase; |
44 import org.graalvm.compiler.phases.common.ConditionalEliminationPhase; |
46 import org.graalvm.compiler.phases.schedule.SchedulePhase; |
45 import org.graalvm.compiler.phases.schedule.SchedulePhase; |
47 import org.junit.Assert; |
46 import org.junit.Assert; |
48 import org.junit.Ignore; |
47 import org.junit.Ignore; |
49 import org.junit.Test; |
48 import org.junit.Test; |
186 * When using FlowSensitiveReductionPhase instead of ConditionalEliminationPhase, |
185 * When using FlowSensitiveReductionPhase instead of ConditionalEliminationPhase, |
187 * tail-duplication gets activated thus resulting in a graph with more nodes than the |
186 * tail-duplication gets activated thus resulting in a graph with more nodes than the |
188 * reference graph. |
187 * reference graph. |
189 */ |
188 */ |
190 new ConditionalEliminationPhase(false).apply(graph, getProviders()); |
189 new ConditionalEliminationPhase(false).apply(graph, getProviders()); |
191 new CanonicalizerPhase().apply(graph, getProviders()); |
190 createCanonicalizerPhase().apply(graph, getProviders()); |
192 // a second canonicalizer is needed to process nested MaterializeNodes |
191 // a second canonicalizer is needed to process nested MaterializeNodes |
193 new CanonicalizerPhase().apply(graph, getProviders()); |
192 createCanonicalizerPhase().apply(graph, getProviders()); |
194 StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO); |
193 StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.NO); |
195 new ConditionalEliminationPhase(false).apply(referenceGraph, getProviders()); |
194 new ConditionalEliminationPhase(false).apply(referenceGraph, getProviders()); |
196 new CanonicalizerPhase().apply(referenceGraph, getProviders()); |
195 this.createCanonicalizerPhase().apply(referenceGraph, getProviders()); |
197 new CanonicalizerPhase().apply(referenceGraph, getProviders()); |
196 this.createCanonicalizerPhase().apply(referenceGraph, getProviders()); |
198 assertEquals(referenceGraph, graph); |
197 assertEquals(referenceGraph, graph); |
199 } |
198 } |
200 |
199 |
201 @Override |
200 @Override |
202 protected void assertEquals(StructuredGraph expected, StructuredGraph graph) { |
201 protected void assertEquals(StructuredGraph expected, StructuredGraph graph) { |
242 } |
241 } |
243 } |
242 } |
244 |
243 |
245 private <T extends Node> void testHelper(String snippet, Class<T> clazz) { |
244 private <T extends Node> void testHelper(String snippet, Class<T> clazz) { |
246 StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO); |
245 StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO); |
247 new CanonicalizerPhase().apply(graph, getProviders()); |
246 createCanonicalizerPhase().apply(graph, getProviders()); |
248 new CanonicalizerPhase().apply(graph, getProviders()); |
247 createCanonicalizerPhase().apply(graph, getProviders()); |
249 DebugContext debug = graph.getDebug(); |
248 DebugContext debug = graph.getDebug(); |
250 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph " + snippet); |
249 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph " + snippet); |
251 Assert.assertFalse("shouldn't have nodes of type " + clazz, graph.getNodes().filter(clazz).iterator().hasNext()); |
250 Assert.assertFalse("shouldn't have nodes of type " + clazz, graph.getNodes().filter(clazz).iterator().hasNext()); |
252 } |
251 } |
253 } |
252 } |