summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/InlineSimple.cpp
diff options
context:
space:
mode:
authorEli Bendersky <eliben@google.com>2014-03-12 16:12:36 +0000
committerEli Bendersky <eliben@google.com>2014-03-12 16:12:36 +0000
commitce306f9f99e3211dec0ff567073fd5bc86b6c99e (patch)
tree5b373efcb4add039519b1b00e3bb728e7bb74e47 /lib/Transforms/IPO/InlineSimple.cpp
parent3d37204ca6514d5d1e2c43fbf85dfeba08c83175 (diff)
downloadllvm-ce306f9f99e3211dec0ff567073fd5bc86b6c99e.tar.gz
llvm-ce306f9f99e3211dec0ff567073fd5bc86b6c99e.tar.bz2
llvm-ce306f9f99e3211dec0ff567073fd5bc86b6c99e.tar.xz
Move duplicated code into a helper function (exposed through overload).
There's a bit of duplicated "magic" code in opt.cpp and Clang's CodeGen that computes the inliner threshold from opt level and size opt level. This patch moves the code to a function that lives alongside the inliner itself, providing a convenient overload to the inliner creation. A separate patch can be committed to Clang to use this once it's committed to LLVM. Standalone tools that use the inlining pass can also avoid duplicating this code and fearing it will go out of sync. Note: this patch also restructures the conditinal logic of the computation to be cleaner. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203669 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/InlineSimple.cpp')
-rw-r--r--lib/Transforms/IPO/InlineSimple.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp
index eecd9b1030..e5f46d7a78 100644
--- a/lib/Transforms/IPO/InlineSimple.cpp
+++ b/lib/Transforms/IPO/InlineSimple.cpp
@@ -56,6 +56,17 @@ public:
void getAnalysisUsage(AnalysisUsage &AU) const override;
};
+static int computeThresholdFromOptLevels(unsigned OptLevel,
+ unsigned SizeOptLevel) {
+ if (OptLevel > 2)
+ return 275;
+ if (SizeOptLevel == 1)
+ return 75;
+ if (SizeOptLevel == 2)
+ return 25;
+ return 225;
+}
+
} // end anonymous namespace
char SimpleInliner::ID = 0;
@@ -72,6 +83,12 @@ Pass *llvm::createFunctionInliningPass(int Threshold) {
return new SimpleInliner(Threshold);
}
+Pass *llvm::createFunctionInliningPass(unsigned OptLevel,
+ unsigned SizeOptLevel) {
+ return new SimpleInliner(
+ computeThresholdFromOptLevels(OptLevel, SizeOptLevel));
+}
+
bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) {
ICA = &getAnalysis<InlineCostAnalysis>();
return Inliner::runOnSCC(SCC);