src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PushThroughIfTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PushThroughIfTest.java

Print this page




   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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.junit.Test;
  26 
  27 import org.graalvm.compiler.debug.Debug;
  28 import org.graalvm.compiler.nodes.FrameState;
  29 import org.graalvm.compiler.nodes.StructuredGraph;
  30 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  31 import org.graalvm.compiler.nodes.util.GraphUtil;
  32 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  33 import org.graalvm.compiler.phases.tiers.PhaseContext;

  34 
  35 public class PushThroughIfTest extends GraalCompilerTest {
  36 
  37     public int field1;
  38     public int field2;
  39 
  40     public int testSnippet(boolean b) {
  41         int i;
  42         if (b) {
  43             i = field1;
  44         } else {
  45             i = field1;
  46         }
  47         return i + field2;
  48     }
  49 
  50     @SuppressWarnings("unused")
  51     public int referenceSnippet(boolean b) {
  52         return field1 + field2;
  53     }
  54 
  55     @Test
  56     public void test1() {
  57         test("testSnippet", "referenceSnippet");
  58     }
  59 
  60     private void test(String snippet, String reference) {
  61         StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
  62         Debug.dump(Debug.BASIC_LEVEL, graph, "Graph");

  63         for (FrameState fs : graph.getNodes(FrameState.TYPE).snapshot()) {
  64             fs.replaceAtUsages(null);
  65             GraphUtil.killWithUnusedFloatingInputs(fs);
  66         }
  67         new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
  68         new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
  69 
  70         StructuredGraph referenceGraph = parseEager(reference, AllowAssumptions.YES);
  71         for (FrameState fs : referenceGraph.getNodes(FrameState.TYPE).snapshot()) {
  72             fs.replaceAtUsages(null);
  73             GraphUtil.killWithUnusedFloatingInputs(fs);
  74         }
  75         new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
  76         assertEquals(referenceGraph, graph);
  77     }
  78 }


   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  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.FrameState;
  27 import org.graalvm.compiler.nodes.StructuredGraph;
  28 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  29 import org.graalvm.compiler.nodes.util.GraphUtil;
  30 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  31 import org.graalvm.compiler.phases.tiers.PhaseContext;
  32 import org.junit.Test;
  33 
  34 public class PushThroughIfTest extends GraalCompilerTest {
  35 
  36     public int field1;
  37     public int field2;
  38 
  39     public int testSnippet(boolean b) {
  40         int i;
  41         if (b) {
  42             i = field1;
  43         } else {
  44             i = field1;
  45         }
  46         return i + field2;
  47     }
  48 
  49     @SuppressWarnings("unused")
  50     public int referenceSnippet(boolean b) {
  51         return field1 + field2;
  52     }
  53 
  54     @Test
  55     public void test1() {
  56         test("testSnippet", "referenceSnippet");
  57     }
  58 
  59     private void test(String snippet, String reference) {
  60         StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
  61         DebugContext debug = graph.getDebug();
  62         debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
  63         for (FrameState fs : graph.getNodes(FrameState.TYPE).snapshot()) {
  64             fs.replaceAtUsages(null);
  65             GraphUtil.killWithUnusedFloatingInputs(fs);
  66         }
  67         new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
  68         new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
  69 
  70         StructuredGraph referenceGraph = parseEager(reference, AllowAssumptions.YES);
  71         for (FrameState fs : referenceGraph.getNodes(FrameState.TYPE).snapshot()) {
  72             fs.replaceAtUsages(null);
  73             GraphUtil.killWithUnusedFloatingInputs(fs);
  74         }
  75         new CanonicalizerPhase().apply(referenceGraph, new PhaseContext(getProviders()));
  76         assertEquals(referenceGraph, graph);
  77     }
  78 }
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/PushThroughIfTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File