1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 java.util.List; 26 27 import org.junit.Test; 28 29 import org.graalvm.compiler.graph.Node; 30 import org.graalvm.compiler.graph.NodeMap; 31 import org.graalvm.compiler.nodes.FrameState; 32 import org.graalvm.compiler.nodes.LoopExitNode; 33 import org.graalvm.compiler.nodes.StructuredGraph; 34 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 35 import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult; 36 import org.graalvm.compiler.nodes.calc.AddNode; 37 import org.graalvm.compiler.nodes.calc.BinaryArithmeticNode; 38 import org.graalvm.compiler.nodes.cfg.Block; 39 import org.graalvm.compiler.nodes.util.GraphUtil; 40 import org.graalvm.compiler.phases.schedule.SchedulePhase; 41 import org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy; 42 43 public class SchedulingTest extends GraphScheduleTest { 44 45 public static int testValueProxyInputsSnippet(int s) { 46 int i = 0; 47 while (true) { 48 i++; 49 int v = i - s * 2; 50 if (i == s) { 51 return v; 52 } 53 } 54 } 55 56 @Test 57 public void testValueProxyInputs() { 58 StructuredGraph graph = parseEager("testValueProxyInputsSnippet", AllowAssumptions.YES); 59 for (FrameState fs : graph.getNodes().filter(FrameState.class).snapshot()) { 60 fs.replaceAtUsages(null); 61 GraphUtil.killWithUnusedFloatingInputs(fs); 62 } 63 SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.LATEST); 64 schedulePhase.apply(graph); 65 ScheduleResult schedule = graph.getLastSchedule(); 66 NodeMap<Block> nodeToBlock = schedule.getCFG().getNodeToBlock(); 67 assertTrue(graph.getNodes().filter(LoopExitNode.class).count() == 1); 68 LoopExitNode loopExit = graph.getNodes().filter(LoopExitNode.class).first(); 69 List<Node> list = schedule.nodesFor(nodeToBlock.get(loopExit)); 70 for (BinaryArithmeticNode<?> node : graph.getNodes().filter(BinaryArithmeticNode.class)) { 71 if (!(node instanceof AddNode)) { 72 assertTrue(node.toString(), nodeToBlock.get(node) == nodeToBlock.get(loopExit)); 73 assertTrue(list.indexOf(node) + " < " + list.indexOf(loopExit) + ", " + node + ", " + loopExit, list.indexOf(node) < list.indexOf(loopExit)); 74 } 75 } 76 } 77 }