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 { 239933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner class CallSite; 243574eca1b02600bac4e625297f4ecf745f4c4f32Micah Villmow class DataLayout; 2512f0babca4459c253675700e1d707652d5b6ba17Chris Lattner class InlineCost; 2612f0babca4459c253675700e1d707652d5b6ba17Chris Lattner template<class PtrType, unsigned SmallSize> 2712f0babca4459c253675700e1d707652d5b6ba17Chris Lattner class SmallPtrSet; 289933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 299933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner/// Inliner - This class contains all of the helper code which is used to 301a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar/// perform the inlining operations that do not depend on the policy. 319933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner/// 329933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattnerstruct Inliner : public CallGraphSCCPass { 3390c579de5a383cee278acc3f7e7b9d0a656e6a35Owen Anderson explicit Inliner(char &ID); 34fa086f1f00a8b75ab2e2208bd7a028e62f9854dbChad Rosier explicit Inliner(char &ID, int Threshold, bool InsertLifetime); 359933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 369933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// getAnalysisUsage - For this class, we declare that we require and preserve 379933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// the call graph. If the derived class implements this method, it should 389933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// always explicitly call the implementation here. 3936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void getAnalysisUsage(AnalysisUsage &Info) const override; 409933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 419933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // Main run interface method, this implements the interface required by the 429933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // Pass class. 4336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool runOnSCC(CallGraphSCC &SCC) override; 449933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 45ee721156701ec3afb198d4cfede00095b228eeacMatt Beaumont-Gay using llvm::Pass::doFinalization; 469933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // doFinalization - Remove now-dead linkonce functions at the end of 479933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // processing to avoid breaking the SCC traversal. 4836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool doFinalization(CallGraph &CG) override; 499933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 509933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// This method returns the value specified by the -inline-threshold value, 519933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// specified on the command line. This is typically not directly needed. 529933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// 539933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner unsigned getInlineThreshold() const { return InlineThreshold; } 549933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 55f8526cb711ec96cd2d5aff30da57f65ae8e5b7b8Jakob Stoklund Olesen /// Calculate the inline threshold for given Caller. This threshold is lower 56570a4a5d9ca31f276a67502d1e0533d59d331feaJakob Stoklund Olesen /// if the caller is marked with OptimizeForSize and -inline-threshold is not 57570a4a5d9ca31f276a67502d1e0533d59d331feaJakob Stoklund Olesen /// given on the comand line. It is higher if the callee is marked with the 58570a4a5d9ca31f276a67502d1e0533d59d331feaJakob Stoklund Olesen /// inlinehint attribute. 59f8526cb711ec96cd2d5aff30da57f65ae8e5b7b8Jakob Stoklund Olesen /// 60570a4a5d9ca31f276a67502d1e0533d59d331feaJakob Stoklund Olesen unsigned getInlineThreshold(CallSite CS) const; 61f8526cb711ec96cd2d5aff30da57f65ae8e5b7b8Jakob Stoklund Olesen 629933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// getInlineCost - This method must be implemented by the subclass to 639933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// determine the cost of inlining the specified call site. If the cost 649933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// returned is greater than the current inline threshold, the call site is 659933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// not inlined. 669933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner /// 67c5e1ec47c719806fcc882470595960512edc7441Daniel Dunbar virtual InlineCost getInlineCost(CallSite CS) = 0; 689933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 69f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// removeDeadFunctions - Remove dead functions. 70f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// 71f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag 72f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// which restricts it to deleting functions with an 'AlwaysInline' 73f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// attribute. This is useful for the InlineAlways pass that only wants to 74f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth /// deal with that subset of the functions. 75f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false); 76f91f5af802bd4487c49ee17cd0d3e46c6456263eChandler Carruth 779933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattnerprivate: 789933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner // InlineThreshold - Cache the value here for easy access. 799933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner unsigned InlineThreshold; 801a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar 81fa086f1f00a8b75ab2e2208bd7a028e62f9854dbChad Rosier // InsertLifetime - Insert @llvm.lifetime intrinsics. 82fa086f1f00a8b75ab2e2208bd7a028e62f9854dbChad Rosier bool InsertLifetime; 83fa086f1f00a8b75ab2e2208bd7a028e62f9854dbChad Rosier 841a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar /// shouldInline - Return true if the inliner should attempt to 851a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar /// inline at the given CallSite. 861a99dbfe3b70c83d3f3e4648b5868c04697cd77cDaniel Dunbar bool shouldInline(CallSite CS); 879933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner}; 889933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 899933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner} // End llvm namespace 909933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner 919933e4bd7dc07943f62a9ae17dddb815c4901972Tanya Lattner#endif 92