Home | History | Annotate | Download | only in IPO
      1 //===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file defines a simple policy-based bottom-up inliner.  This file
     11 // implements all of the boring mechanics of the bottom-up inlining, while the
     12 // subclass determines WHAT to inline, which is the much more interesting
     13 // component.
     14 //
     15 //===----------------------------------------------------------------------===//
     16 
     17 #ifndef LLVM_TRANSFORMS_IPO_INLINERPASS_H
     18 #define LLVM_TRANSFORMS_IPO_INLINERPASS_H
     19 
     20 #include "llvm/CallGraphSCCPass.h"
     21 
     22 namespace llvm {
     23   class CallSite;
     24   class TargetData;
     25   class InlineCost;
     26   template<class PtrType, unsigned SmallSize>
     27   class SmallPtrSet;
     28 
     29 /// Inliner - This class contains all of the helper code which is used to
     30 /// perform the inlining operations that do not depend on the policy.
     31 ///
     32 struct Inliner : public CallGraphSCCPass {
     33   explicit Inliner(char &ID);
     34   explicit Inliner(char &ID, int Threshold, bool InsertLifetime);
     35 
     36   /// getAnalysisUsage - For this class, we declare that we require and preserve
     37   /// the call graph.  If the derived class implements this method, it should
     38   /// always explicitly call the implementation here.
     39   virtual void getAnalysisUsage(AnalysisUsage &Info) const;
     40 
     41   // Main run interface method, this implements the interface required by the
     42   // Pass class.
     43   virtual bool runOnSCC(CallGraphSCC &SCC);
     44 
     45   // doFinalization - Remove now-dead linkonce functions at the end of
     46   // processing to avoid breaking the SCC traversal.
     47   virtual bool doFinalization(CallGraph &CG);
     48 
     49   /// This method returns the value specified by the -inline-threshold value,
     50   /// specified on the command line.  This is typically not directly needed.
     51   ///
     52   unsigned getInlineThreshold() const { return InlineThreshold; }
     53 
     54   /// Calculate the inline threshold for given Caller. This threshold is lower
     55   /// if the caller is marked with OptimizeForSize and -inline-threshold is not
     56   /// given on the comand line. It is higher if the callee is marked with the
     57   /// inlinehint attribute.
     58   ///
     59   unsigned getInlineThreshold(CallSite CS) const;
     60 
     61   /// getInlineCost - This method must be implemented by the subclass to
     62   /// determine the cost of inlining the specified call site.  If the cost
     63   /// returned is greater than the current inline threshold, the call site is
     64   /// not inlined.
     65   ///
     66   virtual InlineCost getInlineCost(CallSite CS) = 0;
     67 
     68   /// removeDeadFunctions - Remove dead functions.
     69   ///
     70   /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag
     71   /// which restricts it to deleting functions with an 'AlwaysInline'
     72   /// attribute. This is useful for the InlineAlways pass that only wants to
     73   /// deal with that subset of the functions.
     74   bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false);
     75 
     76 private:
     77   // InlineThreshold - Cache the value here for easy access.
     78   unsigned InlineThreshold;
     79 
     80   // InsertLifetime - Insert @llvm.lifetime intrinsics.
     81   bool InsertLifetime;
     82 
     83   /// shouldInline - Return true if the inliner should attempt to
     84   /// inline at the given CallSite.
     85   bool shouldInline(CallSite CS);
     86 };
     87 
     88 } // End llvm namespace
     89 
     90 #endif
     91