001/*
002 * Copyright (c) 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 java.util.*;
026
027import org.junit.*;
028
029import com.oracle.graal.graph.*;
030import com.oracle.graal.nodes.*;
031import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions;
032import com.oracle.graal.nodes.calc.*;
033import com.oracle.graal.nodes.cfg.*;
034import com.oracle.graal.nodes.util.*;
035import com.oracle.graal.phases.schedule.*;
036import com.oracle.graal.phases.schedule.SchedulePhase.SchedulingStrategy;
037
038public class SchedulingTest extends GraphScheduleTest {
039
040    public static int testValueProxyInputsSnippet(int s) {
041        int i = 0;
042        while (true) {
043            i++;
044            int v = i - s * 2;
045            if (i == s) {
046                return v;
047            }
048        }
049    }
050
051    @Test
052    public void testValueProxyInputs() {
053        StructuredGraph graph = parseEager("testValueProxyInputsSnippet", AllowAssumptions.YES);
054        for (FrameState fs : graph.getNodes().filter(FrameState.class).snapshot()) {
055            fs.replaceAtUsages(null);
056            GraphUtil.killWithUnusedFloatingInputs(fs);
057        }
058        SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.LATEST);
059        schedule.apply(graph);
060        NodeMap<Block> nodeToBlock = schedule.getCFG().getNodeToBlock();
061        assertTrue(graph.getNodes().filter(LoopExitNode.class).count() == 1);
062        LoopExitNode loopExit = graph.getNodes().filter(LoopExitNode.class).first();
063        List<Node> list = schedule.nodesFor(nodeToBlock.get(loopExit));
064        for (BinaryArithmeticNode<?> node : graph.getNodes().filter(BinaryArithmeticNode.class)) {
065            if (!(node instanceof AddNode)) {
066                assertTrue(node.toString(), nodeToBlock.get(node) == nodeToBlock.get(loopExit));
067                assertTrue(list.indexOf(node) + " < " + list.indexOf(loopExit) + ", " + node + ", " + loopExit, list.indexOf(node) < list.indexOf(loopExit));
068            }
069        }
070    }
071}