InvokeHintsTest.java revision 12657:6ef01bd40ce2
1130803Smarcel/* 2130803Smarcel * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 3130803Smarcel * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4130803Smarcel * 5130803Smarcel * This code is free software; you can redistribute it and/or modify it 6130803Smarcel * under the terms of the GNU General Public License version 2 only, as 7130803Smarcel * published by the Free Software Foundation. 8130803Smarcel * 9130803Smarcel * This code is distributed in the hope that it will be useful, but WITHOUT 10130803Smarcel * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11130803Smarcel * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12130803Smarcel * version 2 for more details (a copy is included in the LICENSE file that 13130803Smarcel * accompanied this code). 14130803Smarcel * 15130803Smarcel * You should have received a copy of the GNU General Public License version 16130803Smarcel * 2 along with this work; if not, write to the Free Software Foundation, 17130803Smarcel * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18130803Smarcel * 19130803Smarcel * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20130803Smarcel * or visit www.oracle.com if you need additional information or have any 21130803Smarcel * questions. 22130803Smarcel */ 23130803Smarcelpackage org.graalvm.compiler.core.test; 24130803Smarcel 25130803Smarcelimport java.util.HashMap; 26130803Smarcelimport java.util.Map; 27130803Smarcel 28130803Smarcelimport org.junit.Test; 29130803Smarcel 30130803Smarcelimport org.graalvm.compiler.nodes.Invoke; 31130803Smarcelimport org.graalvm.compiler.nodes.StructuredGraph; 32130803Smarcelimport org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; 33130803Smarcelimport org.graalvm.compiler.phases.common.CanonicalizerPhase; 34130803Smarcelimport org.graalvm.compiler.phases.common.DeadCodeEliminationPhase; 35130803Smarcelimport org.graalvm.compiler.phases.common.inlining.InliningPhase; 36130803Smarcelimport org.graalvm.compiler.phases.tiers.HighTierContext; 37130803Smarcel 38130803Smarcelpublic class InvokeHintsTest extends GraalCompilerTest { 39130803Smarcel 40130803Smarcel private static final String REFERENCE_SNIPPET = "referenceSnippet"; 41130803Smarcel 42130803Smarcel public static int const1() { 43130803Smarcel return 1; 44130803Smarcel } 45130803Smarcel 46130803Smarcel public static int const7() { 47130803Smarcel return 7; 48130803Smarcel } 49130803Smarcel 50130803Smarcel @SuppressWarnings("all") 51130803Smarcel public static int referenceSnippet() { 52130803Smarcel return 7; 53130803Smarcel } 54130803Smarcel 55130803Smarcel @Test 56130803Smarcel public void test1() { 57130803Smarcel test("test1Snippet"); 58130803Smarcel } 59130803Smarcel 60130803Smarcel @SuppressWarnings("all") 61130803Smarcel public static int test1Snippet() { 62130803Smarcel return const7(); 63130803Smarcel } 64130803Smarcel 65130803Smarcel @Test 66130803Smarcel public void test2() { 67130803Smarcel test("test2Snippet"); 68130803Smarcel } 69130803Smarcel 70130803Smarcel @SuppressWarnings("all") 71130803Smarcel public static int test2Snippet() { 72130803Smarcel return const1() + const1() + const1() + const1() + const1() + const1() + const1(); 73130803Smarcel } 74130803Smarcel 75130803Smarcel private void test(String snippet) { 76130803Smarcel StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO); 77130803Smarcel Map<Invoke, Double> hints = new HashMap<>(); 78130803Smarcel for (Invoke invoke : graph.getInvokes()) { 79130803Smarcel hints.put(invoke, 1000d); 80130803Smarcel } 81130803Smarcel 82130803Smarcel HighTierContext context = getDefaultHighTierContext(); 83130803Smarcel new InliningPhase(hints, new CanonicalizerPhase()).apply(graph, context); 84130803Smarcel new CanonicalizerPhase().apply(graph, context); 85130803Smarcel new DeadCodeEliminationPhase().apply(graph); 86130803Smarcel StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.NO); 87130803Smarcel assertEquals(referenceGraph, graph); 88130803Smarcel } 89130803Smarcel} 90130803Smarcel