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/Analysis/CallGraphSCCPass.h" 21 22 namespace llvm { 23 class AssumptionCacheTracker; 24 class CallSite; 25 class DataLayout; 26 class InlineCost; 27 class ProfileSummaryInfo; 28 template <class PtrType, unsigned SmallSize> class SmallPtrSet; 29 30 /// Inliner - This class contains all of the helper code which is used to 31 /// perform the inlining operations that do not depend on the policy. 32 /// 33 struct Inliner : public CallGraphSCCPass { 34 explicit Inliner(char &ID); 35 explicit Inliner(char &ID, bool InsertLifetime); 36 37 /// getAnalysisUsage - For this class, we declare that we require and preserve 38 /// the call graph. If the derived class implements this method, it should 39 /// always explicitly call the implementation here. 40 void getAnalysisUsage(AnalysisUsage &Info) const override; 41 42 // Main run interface method, this implements the interface required by the 43 // Pass class. 44 bool runOnSCC(CallGraphSCC &SCC) override; 45 46 using llvm::Pass::doFinalization; 47 // doFinalization - Remove now-dead linkonce functions at the end of 48 // processing to avoid breaking the SCC traversal. 49 bool doFinalization(CallGraph &CG) override; 50 51 /// getInlineCost - This method must be implemented by the subclass to 52 /// determine the cost of inlining the specified call site. If the cost 53 /// returned is greater than the current inline threshold, the call site is 54 /// not inlined. 55 /// 56 virtual InlineCost getInlineCost(CallSite CS) = 0; 57 58 /// removeDeadFunctions - Remove dead functions. 59 /// 60 /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag 61 /// which restricts it to deleting functions with an 'AlwaysInline' 62 /// attribute. This is useful for the InlineAlways pass that only wants to 63 /// deal with that subset of the functions. 64 bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false); 65 66 /// This function performs the main work of the pass. The default 67 /// of Inlinter::runOnSCC() calls skipSCC() before calling this method, but 68 /// derived classes which cannot be skipped can override that method and 69 /// call this function unconditionally. 70 bool inlineCalls(CallGraphSCC &SCC); 71 72 private: 73 // InsertLifetime - Insert @llvm.lifetime intrinsics. 74 bool InsertLifetime; 75 76 /// shouldInline - Return true if the inliner should attempt to 77 /// inline at the given CallSite. 78 bool shouldInline(CallSite CS); 79 /// Return true if inlining of CS can block the caller from being 80 /// inlined which is proved to be more beneficial. \p IC is the 81 /// estimated inline cost associated with callsite \p CS. 82 /// \p TotalAltCost will be set to the estimated cost of inlining the caller 83 /// if \p CS is suppressed for inlining. 84 bool shouldBeDeferred(Function *Caller, CallSite CS, InlineCost IC, 85 int &TotalAltCost); 86 87 protected: 88 AssumptionCacheTracker *ACT; 89 ProfileSummaryInfo *PSI; 90 }; 91 92 } // End llvm namespace 93 94 #endif 95