[llvm] r203669 - Move duplicated code into a helper function (exposed through overload).

Eli Bendersky eliben at google.com
Wed Mar 12 09:50:50 PDT 2014


On Wed, Mar 12, 2014 at 9:41 AM, Eric Christopher <echristo at gmail.com>wrote:

> You seem to have dropped the comments here...
>

Resurrected in r203675

Eli



>
> -eric
>
> On Wed, Mar 12, 2014 at 9:12 AM, Eli Bendersky <eliben at google.com> wrote:
> > Author: eliben
> > Date: Wed Mar 12 11:12:36 2014
> > New Revision: 203669
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=203669&view=rev
> > Log:
> > 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.
> >
> >
> > Modified:
> >     llvm/trunk/include/llvm/Transforms/IPO.h
> >     llvm/trunk/lib/Transforms/IPO/InlineSimple.cpp
> >     llvm/trunk/tools/opt/opt.cpp
> >
> > Modified: llvm/trunk/include/llvm/Transforms/IPO.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO.h?rev=203669&r1=203668&r2=203669&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/include/llvm/Transforms/IPO.h (original)
> > +++ llvm/trunk/include/llvm/Transforms/IPO.h Wed Mar 12 11:12:36 2014
> > @@ -34,7 +34,7 @@ ModulePass *createStripSymbolsPass(bool
> >
> >
>  //===----------------------------------------------------------------------===//
> >  //
> > -// 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.
> >  //
> >
> > Modified: llvm/trunk/lib/Transforms/IPO/InlineSimple.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/InlineSimple.cpp?rev=203669&r1=203668&r2=203669&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Transforms/IPO/InlineSimple.cpp (original)
> > +++ llvm/trunk/lib/Transforms/IPO/InlineSimple.cpp Wed Mar 12 11:12:36
> 2014
> > @@ -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(i
> >    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);
> >
> > Modified: llvm/trunk/tools/opt/opt.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=203669&r1=203668&r2=203669&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/tools/opt/opt.cpp (original)
> > +++ llvm/trunk/tools/opt/opt.cpp Wed Mar 12 11:12:36 2014
> > @@ -210,14 +210,7 @@ static void AddOptimizationPasses(PassMa
> >    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();
> >    }
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140312/cb7916b3/attachment.html>


More information about the llvm-commits mailing list