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.AbstractBeginNode; 30 import org.graalvm.compiler.nodes.AbstractMergeNode; 31 import org.graalvm.compiler.nodes.BeginNode; 32 import org.graalvm.compiler.nodes.EndNode; 33 import org.graalvm.compiler.nodes.IfNode; 34 import org.graalvm.compiler.nodes.MergeNode; 35 import org.graalvm.compiler.nodes.ReturnNode; 36 import org.graalvm.compiler.nodes.StructuredGraph; 37 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 38 import org.graalvm.compiler.nodes.cfg.Block; 39 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph; 40 41 public class SimpleCFGTest extends GraalCompilerTest { 42 43 private static void dumpGraph(final StructuredGraph graph) { 44 Debug.dump(Debug.BASIC_LEVEL, graph, "Graph"); 45 } 46 47 @Test 48 public void testImplies() { 49 StructuredGraph graph = new StructuredGraph.Builder(getInitialOptions(), AllowAssumptions.YES).build(); 50 51 EndNode trueEnd = graph.add(new EndNode()); 52 EndNode falseEnd = graph.add(new EndNode()); 53 54 AbstractBeginNode trueBegin = graph.add(new BeginNode()); 55 trueBegin.setNext(trueEnd); 56 AbstractBeginNode falseBegin = graph.add(new BeginNode()); 57 falseBegin.setNext(falseEnd); 58 59 IfNode ifNode = graph.add(new IfNode(null, trueBegin, falseBegin, 0.5)); 60 graph.start().setNext(ifNode); 61 62 AbstractMergeNode merge = graph.add(new MergeNode()); 63 merge.addForwardEnd(trueEnd); 64 merge.addForwardEnd(falseEnd); 65 ReturnNode returnNode = graph.add(new ReturnNode(null)); 66 merge.setNext(returnNode); 67 68 dumpGraph(graph); 69 | 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.AbstractBeginNode; 27 import org.graalvm.compiler.nodes.AbstractMergeNode; 28 import org.graalvm.compiler.nodes.BeginNode; 29 import org.graalvm.compiler.nodes.EndNode; 30 import org.graalvm.compiler.nodes.IfNode; 31 import org.graalvm.compiler.nodes.MergeNode; 32 import org.graalvm.compiler.nodes.ReturnNode; 33 import org.graalvm.compiler.nodes.StructuredGraph; 34 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 35 import org.graalvm.compiler.nodes.cfg.Block; 36 import org.graalvm.compiler.nodes.cfg.ControlFlowGraph; 37 import org.graalvm.compiler.options.OptionValues; 38 import org.graalvm.compiler.printer.GraalDebugHandlersFactory; 39 import org.junit.Assert; 40 import org.junit.Test; 41 42 public class SimpleCFGTest extends GraalCompilerTest { 43 44 private static void dumpGraph(final StructuredGraph graph) { 45 DebugContext debug = graph.getDebug(); 46 debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph"); 47 } 48 49 @Test 50 public void testImplies() { 51 OptionValues options = getInitialOptions(); 52 DebugContext debug = DebugContext.create(options, new GraalDebugHandlersFactory(getSnippetReflection())); 53 StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build(); 54 55 EndNode trueEnd = graph.add(new EndNode()); 56 EndNode falseEnd = graph.add(new EndNode()); 57 58 AbstractBeginNode trueBegin = graph.add(new BeginNode()); 59 trueBegin.setNext(trueEnd); 60 AbstractBeginNode falseBegin = graph.add(new BeginNode()); 61 falseBegin.setNext(falseEnd); 62 63 IfNode ifNode = graph.add(new IfNode(null, trueBegin, falseBegin, 0.5)); 64 graph.start().setNext(ifNode); 65 66 AbstractMergeNode merge = graph.add(new MergeNode()); 67 merge.addForwardEnd(trueEnd); 68 merge.addForwardEnd(falseEnd); 69 ReturnNode returnNode = graph.add(new ReturnNode(null)); 70 merge.setNext(returnNode); 71 72 dumpGraph(graph); 73 |