aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/Transforms
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-10-30 19:26:59 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-10-30 19:26:59 +0000
commitc5e1ec47c719806fcc882470595960512edc7441 (patch)
tree41553d08ff1c9b421dd3f34977eb7403ba0d4bad /include/llvm/Transforms
parentfa7935fcb33436e200fd1e5aa99048ea227d2606 (diff)
downloadexternal_llvm-c5e1ec47c719806fcc882470595960512edc7441.zip
external_llvm-c5e1ec47c719806fcc882470595960512edc7441.tar.gz
external_llvm-c5e1ec47c719806fcc882470595960512edc7441.tar.bz2
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
Diffstat (limited to 'include/llvm/Transforms')
-rw-r--r--include/llvm/Transforms/IPO/InlinerPass.h3
-rw-r--r--include/llvm/Transforms/Utils/InlineCost.h40
2 files changed, 40 insertions, 3 deletions
diff --git a/include/llvm/Transforms/IPO/InlinerPass.h b/include/llvm/Transforms/IPO/InlinerPass.h
index 00950f7..082dd82 100644
--- a/include/llvm/Transforms/IPO/InlinerPass.h
+++ b/include/llvm/Transforms/IPO/InlinerPass.h
@@ -18,6 +18,7 @@
#define INLINER_H
#include "llvm/CallGraphSCCPass.h"
+#include "llvm/Transforms/Utils/InlineCost.h"
namespace llvm {
class CallSite;
@@ -53,7 +54,7 @@ struct Inliner : public CallGraphSCCPass {
/// returned is greater than the current inline threshold, the call site is
/// not inlined.
///
- virtual int getInlineCost(CallSite CS) = 0;
+ virtual InlineCost getInlineCost(CallSite CS) = 0;
// getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a
// higher threshold to determine if the function call should be inlined.
diff --git a/include/llvm/Transforms/Utils/InlineCost.h b/include/llvm/Transforms/Utils/InlineCost.h
index 154ba1a..1698a81 100644
--- a/include/llvm/Transforms/Utils/InlineCost.h
+++ b/include/llvm/Transforms/Utils/InlineCost.h
@@ -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.