1 /*
   2  * Copyright (c) 2013, 2014, 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.phases.common.inlining.info;
  24 
  25 import java.util.Collection;
  26 
  27 import org.graalvm.compiler.graph.Node;
  28 import org.graalvm.compiler.nodes.Invoke;
  29 import org.graalvm.compiler.nodes.StructuredGraph;
  30 import org.graalvm.compiler.phases.common.CanonicalizerPhase;
  31 import org.graalvm.compiler.phases.common.inlining.info.elem.Inlineable;
  32 import org.graalvm.compiler.phases.tiers.HighTierContext;
  33 import org.graalvm.compiler.phases.util.Providers;
  34 
  35 import jdk.vm.ci.meta.ResolvedJavaMethod;
  36 
  37 /**
  38  * Represents an opportunity for inlining at a given invoke, with the given weight and level. The
  39  * weight is the amortized weight of the additional code - so smaller is better. The level is the
  40  * number of nested inlinings that lead to this invoke.
  41  */
  42 public interface InlineInfo {
  43 
  44     /**
  45      * The graph containing the {@link #invoke() invocation} that may be inlined.
  46      */
  47     StructuredGraph graph();
  48 
  49     /**
  50      * The invocation that may be inlined.
  51      */
  52     Invoke invoke();
  53 
  54     /**
  55      * Returns the number of methods that may be inlined by the {@link #invoke() invocation}. This
  56      * may be more than one in the case of a invocation profile showing a number of "hot" concrete
  57      * methods dispatched to by the invocation.
  58      */
  59     int numberOfMethods();
  60 
  61     ResolvedJavaMethod methodAt(int index);
  62 
  63     Inlineable inlineableElementAt(int index);
  64 
  65     double probabilityAt(int index);
  66 
  67     double relevanceAt(int index);
  68 
  69     void setInlinableElement(int index, Inlineable inlineableElement);
  70 
  71     /**
  72      * Performs the inlining described by this object and returns the node that represents the
  73      * return value of the inlined method (or null for void methods and methods that have no
  74      * non-exceptional exit).
  75      *
  76      * @return a collection of nodes that need to be canonicalized after the inlining
  77      */
  78     Collection<Node> inline(Providers providers);
  79 
  80     /**
  81      * Try to make the call static bindable to avoid interface and virtual method calls.
  82      */
  83     void tryToDevirtualizeInvoke(Providers providers);
  84 
  85     boolean shouldInline();
  86 
  87     void populateInlinableElements(HighTierContext context, StructuredGraph caller, CanonicalizerPhase canonicalizer);
  88 
  89     int determineNodeCount();
  90 }