001/*
002 * Copyright (c) 2013, 2014, 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.phases.common.inlining.info;
024
025import java.util.*;
026
027import jdk.internal.jvmci.meta.*;
028
029import com.oracle.graal.graph.*;
030import com.oracle.graal.nodes.*;
031import com.oracle.graal.phases.common.*;
032import com.oracle.graal.phases.common.inlining.info.elem.*;
033import com.oracle.graal.phases.tiers.*;
034import com.oracle.graal.phases.util.*;
035
036/**
037 * Represents an opportunity for inlining at a given invoke, with the given weight and level. The
038 * weight is the amortized weight of the additional code - so smaller is better. The level is the
039 * number of nested inlinings that lead to this invoke.
040 */
041public interface InlineInfo {
042
043    /**
044     * The graph containing the {@link #invoke() invocation} that may be inlined.
045     */
046    StructuredGraph graph();
047
048    /**
049     * The invocation that may be inlined.
050     */
051    Invoke invoke();
052
053    /**
054     * Returns the number of methods that may be inlined by the {@link #invoke() invocation}. This
055     * may be more than one in the case of a invocation profile showing a number of "hot" concrete
056     * methods dispatched to by the invocation.
057     */
058    int numberOfMethods();
059
060    ResolvedJavaMethod methodAt(int index);
061
062    Inlineable inlineableElementAt(int index);
063
064    double probabilityAt(int index);
065
066    double relevanceAt(int index);
067
068    void setInlinableElement(int index, Inlineable inlineableElement);
069
070    /**
071     * Performs the inlining described by this object and returns the node that represents the
072     * return value of the inlined method (or null for void methods and methods that have no
073     * non-exceptional exit).
074     *
075     * @return a collection of nodes that need to be canonicalized after the inlining
076     */
077    Collection<Node> inline(Providers providers);
078
079    /**
080     * Try to make the call static bindable to avoid interface and virtual method calls.
081     */
082    void tryToDevirtualizeInvoke(Providers providers);
083
084    boolean shouldInline();
085
086    void populateInlinableElements(HighTierContext context, StructuredGraph caller, CanonicalizerPhase canonicalizer);
087
088    int determineNodeCount();
089}