From 49f6565267c12c9da02a34f220d1190ae1c8aedb Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 12 Mar 2014 16:12:36 +0000 Subject: 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 --- llvm/lib/Transforms/IPO/InlineSimple.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'llvm/lib/Transforms') 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(); return Inliner::runOnSCC(SCC); -- cgit v1.2.3