1 /* |
1 /* |
2 * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
27 import org.graalvm.compiler.debug.DebugContext; |
27 import org.graalvm.compiler.debug.DebugContext; |
28 import org.graalvm.compiler.nodes.GuardNode; |
28 import org.graalvm.compiler.nodes.GuardNode; |
29 import org.graalvm.compiler.nodes.StructuredGraph; |
29 import org.graalvm.compiler.nodes.StructuredGraph; |
30 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; |
30 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; |
31 import org.graalvm.compiler.nodes.java.InstanceOfNode; |
31 import org.graalvm.compiler.nodes.java.InstanceOfNode; |
|
32 import org.graalvm.compiler.nodes.spi.CoreProviders; |
32 import org.graalvm.compiler.nodes.spi.LoweringTool; |
33 import org.graalvm.compiler.nodes.spi.LoweringTool; |
33 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
34 import org.graalvm.compiler.phases.common.CanonicalizerPhase; |
34 import org.graalvm.compiler.phases.common.ConditionalEliminationPhase; |
35 import org.graalvm.compiler.phases.common.ConditionalEliminationPhase; |
35 import org.graalvm.compiler.phases.common.FloatingReadPhase; |
36 import org.graalvm.compiler.phases.common.FloatingReadPhase; |
36 import org.graalvm.compiler.phases.common.LoweringPhase; |
37 import org.graalvm.compiler.phases.common.LoweringPhase; |
37 import org.graalvm.compiler.phases.tiers.PhaseContext; |
|
38 import org.junit.Assert; |
38 import org.junit.Assert; |
39 import org.junit.Test; |
39 import org.junit.Test; |
40 |
40 |
41 /** |
41 /** |
42 * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase} |
42 * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase} |
108 |
108 |
109 @Test |
109 @Test |
110 public void testRedundantCompares() { |
110 public void testRedundantCompares() { |
111 StructuredGraph graph = parseEager("testRedundantComparesSnippet", AllowAssumptions.YES); |
111 StructuredGraph graph = parseEager("testRedundantComparesSnippet", AllowAssumptions.YES); |
112 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
112 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
113 PhaseContext context = new PhaseContext(getProviders()); |
113 CoreProviders context = getProviders(); |
114 |
114 |
115 new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |
115 new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |
116 canonicalizer.apply(graph, context); |
116 canonicalizer.apply(graph, context); |
117 new FloatingReadPhase().apply(graph); |
117 new FloatingReadPhase().apply(graph); |
118 new ConditionalEliminationPhase(true).apply(graph, context); |
118 new ConditionalEliminationPhase(true).apply(graph, context); |
131 @Test |
131 @Test |
132 public void testInstanceOfCheckCastLowered() { |
132 public void testInstanceOfCheckCastLowered() { |
133 StructuredGraph graph = parseEager("testInstanceOfCheckCastSnippet", AllowAssumptions.YES); |
133 StructuredGraph graph = parseEager("testInstanceOfCheckCastSnippet", AllowAssumptions.YES); |
134 |
134 |
135 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
135 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
136 PhaseContext context = new PhaseContext(getProviders()); |
136 CoreProviders context = getProviders(); |
137 |
137 |
138 new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |
138 new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); |
139 canonicalizer.apply(graph, context); |
139 canonicalizer.apply(graph, context); |
140 new ConditionalEliminationPhase(true).apply(graph, context); |
140 new ConditionalEliminationPhase(true).apply(graph, context); |
141 canonicalizer.apply(graph, context); |
141 canonicalizer.apply(graph, context); |
145 |
145 |
146 private void checkInstanceOfCount(String methodName, int count) { |
146 private void checkInstanceOfCount(String methodName, int count) { |
147 StructuredGraph graph = parseEager(methodName, AllowAssumptions.YES); |
147 StructuredGraph graph = parseEager(methodName, AllowAssumptions.YES); |
148 |
148 |
149 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
149 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
150 PhaseContext context = new PhaseContext(getProviders()); |
150 CoreProviders context = getProviders(); |
151 |
151 |
152 canonicalizer.apply(graph, context); |
152 canonicalizer.apply(graph, context); |
153 new ConditionalEliminationPhase(true).apply(graph, context); |
153 new ConditionalEliminationPhase(true).apply(graph, context); |
154 getDebugContext().dump(DebugContext.BASIC_LEVEL, graph, "After ConditionalEliminationPhase"); |
154 getDebugContext().dump(DebugContext.BASIC_LEVEL, graph, "After ConditionalEliminationPhase"); |
155 canonicalizer.apply(graph, context); |
155 canonicalizer.apply(graph, context); |