Add InlineCost class for represent the estimated cost of inlining a

function.
 - This explicitly models the costs for functions which should
   "always" or "never" be inlined. This fixes bugs where such costs
   were not previously respected.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58450 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2008-10-30 19:26:59 +00:00
parent fa7935fcb3
commit c5e1ec47c7
8 changed files with 97 additions and 18 deletions

View File

@@ -15,6 +15,7 @@
#define LLVM_TRANSFORMS_UTILS_INLINECOST_H
#include "llvm/ADT/SmallPtrSet.h"
#include <cassert>
#include <map>
#include <vector>
@@ -24,6 +25,41 @@ namespace llvm {
class Function;
class CallSite;
/// InlineCost - Represent the cost of inlining a function. This
/// supports special values for functions which should "always" or
/// "never" be inlined. Otherwise, the cost represents a unitless
/// amount; smaller values increase the likelyhood of the function
/// being inlined.
class InlineCost {
enum Kind {
Value,
Always,
Never
};
int Cost : 30;
unsigned Type : 2;
InlineCost(int C, int T) : Cost(C), Type(T) {
assert(Cost == C && "Cost exceeds InlineCost precision");
}
public:
static InlineCost get(int Cost) { return InlineCost(Cost, Value); }
static InlineCost getAlways() { return InlineCost(0, Always); }
static InlineCost getNever() { return InlineCost(0, Never); }
bool isVariable() const { return Type == Value; }
bool isAlways() const { return Type == Always; }
bool isNever() const { return Type == Never; }
/// getValue() - Return a "variable" inline cost's amount. It is
/// an error to call this on an "always" or "never" InlineCost.
int getValue() const {
assert(Type == Value && "Invalid access of InlineCost");
return Cost;
}
};
/// InlineCostAnalyzer - Cost analyzer used by inliner.
class InlineCostAnalyzer {
struct ArgInfo {
@@ -83,8 +119,8 @@ namespace llvm {
/// getInlineCost - The heuristic used to determine if we should inline the
/// function call or not.
///
int getInlineCost(CallSite CS,
SmallPtrSet<const Function *, 16> &NeverInline);
InlineCost getInlineCost(CallSite CS,
SmallPtrSet<const Function *, 16> &NeverInline);
/// getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a
/// higher threshold to determine if the function call should be inlined.