summaryrefslogtreecommitdiffstats
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
commit49f6565267c12c9da02a34f220d1190ae1c8aedb (patch)
tree4c4c29e187c24a7a11fd4e8426d78d412fbe44bb
parent501eadb42919f8312a55d78455a44b39e16762ed (diff)
downloadbcm5719-llvm-49f6565267c12c9da02a34f220d1190ae1c8aedb.tar.gz
bcm5719-llvm-49f6565267c12c9da02a34f220d1190ae1c8aedb.zip
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. llvm-svn: 203669
-rw-r--r--llvm/include/llvm/Transforms/IPO.h12
-rw-r--r--llvm/lib/Transforms/IPO/InlineSimple.cpp17
-rw-r--r--llvm/tools/opt/opt.cpp9
3 files changed, 26 insertions, 12 deletions
diff --git a/llvm/include/llvm/Transforms/IPO.h b/llvm/include/llvm/Transforms/IPO.h
index b4f65b25d5f..ae9d5c1d09b 100644
--- a/llvm/include/llvm/Transforms/IPO.h
+++ b/llvm/include/llvm/Transforms/IPO.h
@@ -34,7 +34,7 @@ ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false);
//===----------------------------------------------------------------------===//
//
-// These functions strips symbols from functions and modules.
+// These functions strips symbols from functions and modules.
// Only debugging information is not stripped.
//
ModulePass *createStripNonDebugSymbolsPass();
@@ -78,20 +78,24 @@ ModulePass *createGlobalDCEPass();
/// the specified global values. Otherwise, it deletes as much of the module as
/// possible, except for the global values specified.
///
-ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
+ModulePass *createGVExtractionPass(std::vector<GlobalValue*>& GVs, bool
deleteFn = false);
//===----------------------------------------------------------------------===//
/// createFunctionInliningPass - Return a new pass object that uses a heuristic
/// to inline direct function calls to small functions.
///
+/// The Threshold can be passed directly, or asked to be computed from the
+/// given optimization and size optimization arguments.
+///
/// The -inline-threshold command line option takes precedence over the
/// threshold given here.
Pass *createFunctionInliningPass();
Pass *createFunctionInliningPass(int Threshold);
+Pass *createFunctionInliningPass(unsigned OptLevel, unsigned SizeOptLevel);
//===----------------------------------------------------------------------===//
-/// createAlwaysInlinerPass - Return a new pass object that inlines only
+/// createAlwaysInlinerPass - Return a new pass object that inlines only
/// functions that are marked as "always_inline".
Pass *createAlwaysInlinerPass();
Pass *createAlwaysInlinerPass(bool InsertLifetime);
@@ -192,7 +196,7 @@ ModulePass *createMergeFunctionsPass();
/// createPartialInliningPass - This pass inlines parts of functions.
///
ModulePass *createPartialInliningPass();
-
+
//===----------------------------------------------------------------------===//
// createMetaRenamerPass - Rename everything with metasyntatic names.
//
diff --git a/llvm/lib/Transforms/IPO/InlineSimple.cpp b/llvm/lib/Transforms/IPO/InlineSimple.cpp
index eecd9b10308..e5f46d7a783 100644
--- a/llvm/lib/Transforms/IPO/InlineSimple.cpp
+++ b/llvm/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);
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index 14a40a4af76..4dd9544fc32 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -210,14 +210,7 @@ static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
if (DisableInline) {
// No inlining pass
} else if (OptLevel > 1) {
- unsigned Threshold = 225;
- if (SizeLevel == 1) // -Os
- Threshold = 75;
- else if (SizeLevel == 2) // -Oz
- Threshold = 25;
- if (OptLevel > 2)
- Threshold = 275;
- Builder.Inliner = createFunctionInliningPass(Threshold);
+ Builder.Inliner = createFunctionInliningPass(OptLevel, SizeLevel);
} else {
Builder.Inliner = createAlwaysInlinerPass();
}
OpenPOWER on IntegriCloud