LLVM API Documentation

InlinerPass.h
Go to the documentation of this file.
00001 //===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines a simple policy-based bottom-up inliner.  This file
00011 // implements all of the boring mechanics of the bottom-up inlining, while the
00012 // subclass determines WHAT to inline, which is the much more interesting
00013 // component.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_TRANSFORMS_IPO_INLINERPASS_H
00018 #define LLVM_TRANSFORMS_IPO_INLINERPASS_H
00019 
00020 #include "llvm/Analysis/CallGraphSCCPass.h"
00021 
00022 namespace llvm {
00023   class CallSite;
00024   class DataLayout;
00025   class InlineCost;
00026   template<class PtrType, unsigned SmallSize>
00027   class SmallPtrSet;
00028 
00029 /// Inliner - This class contains all of the helper code which is used to
00030 /// perform the inlining operations that do not depend on the policy.
00031 ///
00032 struct Inliner : public CallGraphSCCPass {
00033   explicit Inliner(char &ID);
00034   explicit Inliner(char &ID, int Threshold, bool InsertLifetime);
00035 
00036   /// getAnalysisUsage - For this class, we declare that we require and preserve
00037   /// the call graph.  If the derived class implements this method, it should
00038   /// always explicitly call the implementation here.
00039   void getAnalysisUsage(AnalysisUsage &Info) const override;
00040 
00041   // Main run interface method, this implements the interface required by the
00042   // Pass class.
00043   bool runOnSCC(CallGraphSCC &SCC) override;
00044 
00045   using llvm::Pass::doFinalization;
00046   // doFinalization - Remove now-dead linkonce functions at the end of
00047   // processing to avoid breaking the SCC traversal.
00048   bool doFinalization(CallGraph &CG) override;
00049 
00050   /// This method returns the value specified by the -inline-threshold value,
00051   /// specified on the command line.  This is typically not directly needed.
00052   ///
00053   unsigned getInlineThreshold() const { return InlineThreshold; }
00054 
00055   /// Calculate the inline threshold for given Caller. This threshold is lower
00056   /// if the caller is marked with OptimizeForSize and -inline-threshold is not
00057   /// given on the comand line. It is higher if the callee is marked with the
00058   /// inlinehint attribute.
00059   ///
00060   unsigned getInlineThreshold(CallSite CS) const;
00061 
00062   /// getInlineCost - This method must be implemented by the subclass to
00063   /// determine the cost of inlining the specified call site.  If the cost
00064   /// returned is greater than the current inline threshold, the call site is
00065   /// not inlined.
00066   ///
00067   virtual InlineCost getInlineCost(CallSite CS) = 0;
00068 
00069   /// removeDeadFunctions - Remove dead functions.
00070   ///
00071   /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag
00072   /// which restricts it to deleting functions with an 'AlwaysInline'
00073   /// attribute. This is useful for the InlineAlways pass that only wants to
00074   /// deal with that subset of the functions.
00075   bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false);
00076 
00077 private:
00078   // InlineThreshold - Cache the value here for easy access.
00079   unsigned InlineThreshold;
00080 
00081   // InsertLifetime - Insert @llvm.lifetime intrinsics.
00082   bool InsertLifetime;
00083 
00084   /// shouldInline - Return true if the inliner should attempt to
00085   /// inline at the given CallSite.
00086   bool shouldInline(CallSite CS);
00087 };
00088 
00089 } // End llvm namespace
00090 
00091 #endif