10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.core.test; 24 25 import org.graalvm.compiler.debug.DebugContext; 26 import org.graalvm.compiler.nodes.ProxyNode; 27 import org.graalvm.compiler.nodes.StructuredGraph; 28 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 29 import org.graalvm.compiler.nodes.spi.LoweringTool; 30 import org.graalvm.compiler.phases.common.CanonicalizerPhase; 31 import org.graalvm.compiler.phases.common.ConditionalEliminationPhase; 32 import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase; 33 import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase; 34 import org.graalvm.compiler.phases.common.LoweringPhase; 35 import org.graalvm.compiler.phases.schedule.SchedulePhase; 36 import org.graalvm.compiler.phases.tiers.PhaseContext; 37 import org.junit.Assert; 38 39 /** 40 * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase} 41 * including those that triggered bugs in this phase. 42 */ 43 public class ConditionalEliminationTestBase extends GraalCompilerTest { 44 protected static int sink0; 45 protected static int sink1; 46 protected static int sink2; 47 48 protected void testConditionalElimination(String snippet, String referenceSnippet) { 49 testConditionalElimination(snippet, referenceSnippet, false, false); 50 } 51 52 @SuppressWarnings("try") 53 protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) { 54 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); 55 DebugContext debug = graph.getDebug(); 56 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); 57 PhaseContext context = new PhaseContext(getProviders()); 58 CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase(); 59 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); 60 try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest", graph)) { 61 prepareGraph(graph, canonicalizer1, context, applyLowering); 62 new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context); 63 canonicalizer.apply(graph, context); 64 canonicalizer.apply(graph, context); 65 new ConvertDeoptimizeToGuardPhase().apply(graph, context); 66 } catch (Throwable t) { | 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.core.test; 24 25 import org.graalvm.compiler.debug.DebugContext; 26 import org.graalvm.compiler.nodes.ProxyNode; 27 import org.graalvm.compiler.nodes.StructuredGraph; 28 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 29 import org.graalvm.compiler.nodes.spi.LoweringTool; 30 import org.graalvm.compiler.phases.OptimisticOptimizations; 31 import org.graalvm.compiler.phases.OptimisticOptimizations.Optimization; 32 import org.graalvm.compiler.phases.common.CanonicalizerPhase; 33 import org.graalvm.compiler.phases.common.ConditionalEliminationPhase; 34 import org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase; 35 import org.graalvm.compiler.phases.common.IterativeConditionalEliminationPhase; 36 import org.graalvm.compiler.phases.common.LoweringPhase; 37 import org.graalvm.compiler.phases.schedule.SchedulePhase; 38 import org.graalvm.compiler.phases.tiers.HighTierContext; 39 import org.graalvm.compiler.phases.tiers.PhaseContext; 40 import org.junit.Assert; 41 42 /** 43 * Collection of tests for {@link org.graalvm.compiler.phases.common.ConditionalEliminationPhase} 44 * including those that triggered bugs in this phase. 45 */ 46 public class ConditionalEliminationTestBase extends GraalCompilerTest { 47 protected static int sink0; 48 protected static int sink1; 49 protected static int sink2; 50 51 /** 52 * These tests assume all code paths in called routines are reachable so disable removal of dead 53 * code based on method profiles. 54 */ 55 @Override 56 protected HighTierContext getDefaultHighTierContext() { 57 return new HighTierContext(getProviders(), getDefaultGraphBuilderSuite(), OptimisticOptimizations.ALL.remove(Optimization.RemoveNeverExecutedCode)); 58 } 59 60 protected void testConditionalElimination(String snippet, String referenceSnippet) { 61 testConditionalElimination(snippet, referenceSnippet, false, false); 62 } 63 64 @SuppressWarnings("try") 65 protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference, boolean applyLowering) { 66 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); 67 DebugContext debug = graph.getDebug(); 68 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); 69 PhaseContext context = new PhaseContext(getProviders()); 70 CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase(); 71 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); 72 try (DebugContext.Scope scope = debug.scope("ConditionalEliminationTest", graph)) { 73 prepareGraph(graph, canonicalizer1, context, applyLowering); 74 new IterativeConditionalEliminationPhase(canonicalizer, true).apply(graph, context); 75 canonicalizer.apply(graph, context); 76 canonicalizer.apply(graph, context); 77 new ConvertDeoptimizeToGuardPhase().apply(graph, context); 78 } catch (Throwable t) { |