19933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner//===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===// 29933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 39933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// The LLVM Compiler Infrastructure 49933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 79933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 89933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner//===----------------------------------------------------------------------===// 99933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 109933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// This file defines a simple policy-based bottom-up inliner. This file 119933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// implements all of the boring mechanics of the bottom-up inlining, while the 129933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// subclass determines WHAT to inline, which is the much more interesting 139933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// component. 149933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner// 159933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner//===----------------------------------------------------------------------===// 169933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 1712f0babca4459c253675700e1d707652d5b6ba17Chris Lattner#ifndef LLVM_TRANSFORMS_IPO_INLINERPASS_H 1812f0babca4459c253675700e1d707652d5b6ba17Chris Lattner#define LLVM_TRANSFORMS_IPO_INLINERPASS_H 199933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 203251e81d793a293b78f4914be6093b405c24fc2aChandler Carruth#include "llvm/Analysis/CallGraphSCCPass.h" 219933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 229933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattnernamespace llvm { 23de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainarclass AssumptionCacheTracker; 24de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainarclass CallSite; 25de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainarclass DataLayout; 26de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainarclass InlineCost; 27de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainarclass ProfileSummaryInfo; 28de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainartemplate <class PtrType, unsigned SmallSize> class SmallPtrSet; 299933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 309933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner/// Inliner - This class contains all of the helper code which is used to 311a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar/// perform the inlining operations that do not depend on the policy. 329933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner/// 339933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattnerstruct Inliner : public CallGraphSCCPass { 3490c579de5a383cee278acc3f7e7b9d0a656e6a35Owen Anderson explicit Inliner(char &ID); 35de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar explicit Inliner(char &ID, bool InsertLifetime); 369933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 379933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// getAnalysisUsage - For this class, we declare that we require and preserve 389933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// the call graph. If the derived class implements this method, it should 399933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// always explicitly call the implementation here. 4036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void getAnalysisUsage(AnalysisUsage &Info) const override; 419933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 429933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // Main run interface method, this implements the interface required by the 439933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // Pass class. 4436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool runOnSCC(CallGraphSCC &SCC) override; 459933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 46ee721156701ec3afb198d4cfede00095b228eeacMatt Beaumont-Gay using llvm::Pass::doFinalization; 479933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // doFinalization - Remove now-dead linkonce functions at the end of 489933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // processing to avoid breaking the SCC traversal. 4936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool doFinalization(CallGraph &CG) override; 509933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 519933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// getInlineCost - This method must be implemented by the subclass to 529933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// determine the cost of inlining the specified call site. If the cost 539933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// returned is greater than the current inline threshold, the call site is 549933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// not inlined. 559933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// 56c5e1ec47c719806fcc882470595960512edc7441Daniel Dunbar virtual InlineCost getInlineCost(CallSite CS) = 0; 579933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 58f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// removeDeadFunctions - Remove dead functions. 59f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// 60f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag 61f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// which restricts it to deleting functions with an 'AlwaysInline' 62f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// attribute. This is useful for the InlineAlways pass that only wants to 63f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// deal with that subset of the functions. 64f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false); 65f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth 66de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// This function performs the main work of the pass. The default 67de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// of Inlinter::runOnSCC() calls skipSCC() before calling this method, but 68de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// derived classes which cannot be skipped can override that method and 69de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// call this function unconditionally. 70de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar bool inlineCalls(CallGraphSCC &SCC); 711a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar 72de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainarprivate: 73fa086f1f00a8b75ab2e2208bd7a028e62f9854dbChad Rosier // InsertLifetime - Insert @llvm.lifetime intrinsics. 74fa086f1f00a8b75ab2e2208bd7a028e62f9854dbChad Rosier bool InsertLifetime; 75fa086f1f00a8b75ab2e2208bd7a028e62f9854dbChad Rosier 761a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar /// shouldInline - Return true if the inliner should attempt to 771a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar /// inline at the given CallSite. 781a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar bool shouldInline(CallSite CS); 79de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// Return true if inlining of CS can block the caller from being 80de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// inlined which is proved to be more beneficial. \p IC is the 81de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// estimated inline cost associated with callsite \p CS. 82de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// \p TotalAltCost will be set to the estimated cost of inlining the caller 83de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar /// if \p CS is suppressed for inlining. 84de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar bool shouldBeDeferred(Function *Caller, CallSite CS, InlineCost IC, 85de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar int &TotalAltCost); 86de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar 87de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainarprotected: 88de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar AssumptionCacheTracker *ACT; 89de2d8694e25a814696358e95141f4b1aa4d8847ePirama Arumuga Nainar ProfileSummaryInfo *PSI; 909933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner}; 919933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 929933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner} // End llvm namespace 939933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 949933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner#endif 95