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.Assert; 26 import org.junit.Test; 27 28 import org.graalvm.compiler.debug.Debug; 29 import org.graalvm.compiler.nodes.StructuredGraph; 30 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 31 import org.graalvm.compiler.nodes.ValuePhiNode; 32 33 /** 34 * In the following tests, the correct removal of redundant phis during graph building is tested. 35 */ 36 public class PhiCreationTests extends GraalCompilerTest { 37 38 /** 39 * Dummy method to avoid javac dead code elimination. 40 */ 41 private static void test() { 42 } 43 44 @Test 45 public void test1() { 46 StructuredGraph graph = parseEager("test1Snippet", AllowAssumptions.YES); 47 Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext()); 48 } 49 50 public static int test1Snippet(int a) { 51 if (a > 1) { 53 } 54 return a; 55 } 56 57 @Test 58 public void test2() { 59 StructuredGraph graph = parseEager("test2Snippet", AllowAssumptions.YES); 60 Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext()); 61 } 62 63 public static int test2Snippet(int a) { 64 while (a > 1) { 65 test(); 66 } 67 return a; 68 } 69 70 @Test 71 public void test3() { 72 StructuredGraph graph = parseEager("test3Snippet", AllowAssumptions.YES); 73 Debug.dump(Debug.BASIC_LEVEL, graph, "Graph"); 74 Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext()); 75 } 76 77 public static int test3Snippet(int a) { 78 while (a > 1) { 79 while (a > 1) { 80 test(); 81 } 82 } 83 return a; 84 } 85 86 @Test 87 public void test4() { 88 StructuredGraph graph = parseEager("test4Snippet", AllowAssumptions.YES); 89 Debug.dump(Debug.BASIC_LEVEL, graph, "Graph"); 90 Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext()); 91 } 92 93 public static int test4Snippet(int a) { 94 int b = 5; 95 while (a > 1) { 96 while (a > 1) { 97 while (a > 1) { 98 try { 99 test(); 100 } catch (Throwable t) { 101 102 } 103 } 104 } 105 while (a > 1) { 106 while (a > 1) { 107 try { 108 test(); 109 } catch (Throwable t) { | 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.StructuredGraph; 27 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 28 import org.graalvm.compiler.nodes.ValuePhiNode; 29 import org.junit.Assert; 30 import org.junit.Test; 31 32 /** 33 * In the following tests, the correct removal of redundant phis during graph building is tested. 34 */ 35 public class PhiCreationTests extends GraalCompilerTest { 36 37 /** 38 * Dummy method to avoid javac dead code elimination. 39 */ 40 private static void test() { 41 } 42 43 @Test 44 public void test1() { 45 StructuredGraph graph = parseEager("test1Snippet", AllowAssumptions.YES); 46 Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext()); 47 } 48 49 public static int test1Snippet(int a) { 50 if (a > 1) { 52 } 53 return a; 54 } 55 56 @Test 57 public void test2() { 58 StructuredGraph graph = parseEager("test2Snippet", AllowAssumptions.YES); 59 Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext()); 60 } 61 62 public static int test2Snippet(int a) { 63 while (a > 1) { 64 test(); 65 } 66 return a; 67 } 68 69 @Test 70 public void test3() { 71 StructuredGraph graph = parseEager("test3Snippet", AllowAssumptions.YES); 72 DebugContext debug = graph.getDebug(); 73 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); 74 Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext()); 75 } 76 77 public static int test3Snippet(int a) { 78 while (a > 1) { 79 while (a > 1) { 80 test(); 81 } 82 } 83 return a; 84 } 85 86 @Test 87 public void test4() { 88 StructuredGraph graph = parseEager("test4Snippet", AllowAssumptions.YES); 89 DebugContext debug = graph.getDebug(); 90 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); 91 Assert.assertFalse(graph.getNodes().filter(ValuePhiNode.class).iterator().hasNext()); 92 } 93 94 public static int test4Snippet(int a) { 95 int b = 5; 96 while (a > 1) { 97 while (a > 1) { 98 while (a > 1) { 99 try { 100 test(); 101 } catch (Throwable t) { 102 103 } 104 } 105 } 106 while (a > 1) { 107 while (a > 1) { 108 try { 109 test(); 110 } catch (Throwable t) { |