From 61edc107bbc0c92213184121db1c4bdf029bfdaf Mon Sep 17 00:00:00 2001 From: Easwaran Raman Date: Thu, 11 Aug 2016 18:24:08 +0000 Subject: [PATCH] Add a new method to create SimpleInliner instance and make pre-inliner use this. This adds a createFunctionInliningPass pass that takes an InlineParams object and use this to create the pre-inliner pass. This prevents the regular inliner's threshold flag from influencing the preinliner. Differential revision: https://reviews.llvm.org/D23377 llvm-svn: 278377 --- llvm/include/llvm/Transforms/IPO.h | 2 ++ llvm/lib/Transforms/IPO/InlineSimple.cpp | 4 ++++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO.h b/llvm/include/llvm/Transforms/IPO.h index f673188..3fe7115 100644 --- a/llvm/include/llvm/Transforms/IPO.h +++ b/llvm/include/llvm/Transforms/IPO.h @@ -20,6 +20,7 @@ namespace llvm { +struct InlineParams; class StringRef; class ModuleSummaryIndex; class ModulePass; @@ -103,6 +104,7 @@ Pass *createFunctionImportPass(const ModuleSummaryIndex *Index = nullptr); Pass *createFunctionInliningPass(); Pass *createFunctionInliningPass(int Threshold); Pass *createFunctionInliningPass(unsigned OptLevel, unsigned SizeOptLevel); +Pass *createFunctionInliningPass(InlineParams &Params); //===----------------------------------------------------------------------===// /// createAlwaysInlinerPass - Return a new pass object that inlines only diff --git a/llvm/lib/Transforms/IPO/InlineSimple.cpp b/llvm/lib/Transforms/IPO/InlineSimple.cpp index d135ccff..ef04658 100644 --- a/llvm/lib/Transforms/IPO/InlineSimple.cpp +++ b/llvm/lib/Transforms/IPO/InlineSimple.cpp @@ -95,6 +95,10 @@ Pass *llvm::createFunctionInliningPass(unsigned OptLevel, return new SimpleInliner(llvm::getInlineParams(OptLevel, SizeOptLevel)); } +Pass *llvm::createFunctionInliningPass(InlineParams &Params) { + return new SimpleInliner(Params); +} + bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) { TTIWP = &getAnalysis(); return Inliner::runOnSCC(SCC); diff --git a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp index 2bf8870..71e479a 100644 --- a/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -19,6 +19,7 @@ #include "llvm/Analysis/CFLAndersAliasAnalysis.h" #include "llvm/Analysis/CFLSteensAliasAnalysis.h" #include "llvm/Analysis/GlobalsModRef.h" +#include "llvm/Analysis/InlineCost.h" #include "llvm/Analysis/Passes.h" #include "llvm/Analysis/ScopedNoAliasAA.h" #include "llvm/Analysis/TargetLibraryInfo.h" @@ -252,8 +253,17 @@ void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) { // Perform the preinline and cleanup passes for O1 and above. // And avoid doing them if optimizing for size. if (OptLevel > 0 && SizeLevel == 0 && !DisablePreInliner) { - // Create preinline pass. - MPM.add(createFunctionInliningPass(PreInlineThreshold)); + // Create preinline pass. We construct an InlineParams object and specify + // the threshold here to avoid the command line options of the regular + // inliner to influence pre-inlining. The only fields of InlineParams we + // care about are DefaultThreshold and HintThreshold. + InlineParams IP; + IP.DefaultThreshold = PreInlineThreshold; + // FIXME: The hint threshold has the same value used by the regular inliner. + // This should probably be lowered after performance testing. + IP.HintThreshold = 325; + + MPM.add(createFunctionInliningPass(IP)); MPM.add(createSROAPass()); MPM.add(createEarlyCSEPass()); // Catch trivial redundancies MPM.add(createCFGSimplificationPass()); // Merge & remove BBs -- 2.7.4