001/* 002 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.compiler.test; 024 025import com.oracle.graal.debug.*; 026 027import org.junit.*; 028 029import com.oracle.graal.nodes.*; 030import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; 031import com.oracle.graal.nodes.spi.*; 032import com.oracle.graal.phases.common.*; 033import com.oracle.graal.phases.schedule.*; 034import com.oracle.graal.phases.tiers.*; 035 036/** 037 * Collection of tests for 038 * {@link com.oracle.graal.phases.common.DominatorConditionalEliminationPhase} including those that 039 * triggered bugs in this phase. 040 */ 041public class ConditionalEliminationTestBase extends GraalCompilerTest { 042 043 protected void testConditionalElimination(String snippet, String referenceSnippet) { 044 testConditionalElimination(snippet, referenceSnippet, false); 045 } 046 047 protected void testConditionalElimination(String snippet, String referenceSnippet, boolean applyConditionalEliminationOnReference) { 048 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); 049 Debug.dump(graph, "Graph"); 050 PhaseContext context = new PhaseContext(getProviders()); 051 CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase(); 052 canonicalizer1.disableSimplification(); 053 canonicalizer1.apply(graph, context); 054 new ConvertDeoptimizeToGuardPhase().apply(graph, context); 055 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); 056 new DominatorConditionalEliminationPhase(true).apply(graph, context); 057 canonicalizer.apply(graph, context); 058 canonicalizer.apply(graph, context); 059 StructuredGraph referenceGraph = parseEager(referenceSnippet, AllowAssumptions.YES); 060 if (applyConditionalEliminationOnReference) { 061 new DominatorConditionalEliminationPhase(true).apply(referenceGraph, context); 062 canonicalizer.apply(referenceGraph, context); 063 canonicalizer.apply(referenceGraph, context); 064 } else { 065 canonicalizer.apply(referenceGraph, context); 066 } 067 assertEquals(referenceGraph, graph); 068 } 069 070 public void testProxies(String snippet, int expectedProxiesCreated) { 071 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES); 072 PhaseContext context = new PhaseContext(getProviders()); 073 CanonicalizerPhase canonicalizer1 = new CanonicalizerPhase(); 074 canonicalizer1.disableSimplification(); 075 canonicalizer1.apply(graph, context); 076 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); 077 new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context); 078 canonicalizer.apply(graph, context); 079 080 int baseProxyCount = graph.getNodes().filter(ProxyNode.class).count(); 081 new DominatorConditionalEliminationPhase(true).apply(graph, context); 082 canonicalizer.apply(graph, context); 083 new SchedulePhase().apply(graph, context); 084 int actualProxiesCreated = graph.getNodes().filter(ProxyNode.class).count() - baseProxyCount; 085 Assert.assertEquals(expectedProxiesCreated, actualProxiesCreated); 086 } 087}