1193323Sed//===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file defines a simple policy-based bottom-up inliner. This file 11193323Sed// implements all of the boring mechanics of the bottom-up inlining, while the 12193323Sed// subclass determines WHAT to inline, which is the much more interesting 13193323Sed// component. 14193323Sed// 15193323Sed//===----------------------------------------------------------------------===// 16193323Sed 17198090Srdivacky#ifndef LLVM_TRANSFORMS_IPO_INLINERPASS_H 18198090Srdivacky#define LLVM_TRANSFORMS_IPO_INLINERPASS_H 19193323Sed 20249423Sdim#include "llvm/Analysis/CallGraphSCCPass.h" 21193323Sed 22193323Sednamespace llvm { 23193323Sed class CallSite; 24243830Sdim class DataLayout; 25198090Srdivacky class InlineCost; 26198090Srdivacky template<class PtrType, unsigned SmallSize> 27198090Srdivacky class SmallPtrSet; 28193323Sed 29193323Sed/// Inliner - This class contains all of the helper code which is used to 30193323Sed/// perform the inlining operations that do not depend on the policy. 31193323Sed/// 32193323Sedstruct Inliner : public CallGraphSCCPass { 33212904Sdim explicit Inliner(char &ID); 34234353Sdim explicit Inliner(char &ID, int Threshold, bool InsertLifetime); 35193323Sed 36193323Sed /// getAnalysisUsage - For this class, we declare that we require and preserve 37193323Sed /// the call graph. If the derived class implements this method, it should 38193323Sed /// always explicitly call the implementation here. 39193323Sed virtual void getAnalysisUsage(AnalysisUsage &Info) const; 40193323Sed 41193323Sed // Main run interface method, this implements the interface required by the 42193323Sed // Pass class. 43207618Srdivacky virtual bool runOnSCC(CallGraphSCC &SCC); 44193323Sed 45249423Sdim using llvm::Pass::doFinalization; 46193323Sed // doFinalization - Remove now-dead linkonce functions at the end of 47193323Sed // processing to avoid breaking the SCC traversal. 48193323Sed virtual bool doFinalization(CallGraph &CG); 49193323Sed 50193323Sed /// This method returns the value specified by the -inline-threshold value, 51193323Sed /// specified on the command line. This is typically not directly needed. 52193323Sed /// 53193323Sed unsigned getInlineThreshold() const { return InlineThreshold; } 54193323Sed 55202878Srdivacky /// Calculate the inline threshold for given Caller. This threshold is lower 56203954Srdivacky /// if the caller is marked with OptimizeForSize and -inline-threshold is not 57203954Srdivacky /// given on the comand line. It is higher if the callee is marked with the 58203954Srdivacky /// inlinehint attribute. 59202878Srdivacky /// 60203954Srdivacky unsigned getInlineThreshold(CallSite CS) const; 61202878Srdivacky 62193323Sed /// getInlineCost - This method must be implemented by the subclass to 63193323Sed /// determine the cost of inlining the specified call site. If the cost 64193323Sed /// returned is greater than the current inline threshold, the call site is 65193323Sed /// not inlined. 66193323Sed /// 67193323Sed virtual InlineCost getInlineCost(CallSite CS) = 0; 68193323Sed 69234353Sdim /// removeDeadFunctions - Remove dead functions. 70193323Sed /// 71234353Sdim /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag 72234353Sdim /// which restricts it to deleting functions with an 'AlwaysInline' 73234353Sdim /// attribute. This is useful for the InlineAlways pass that only wants to 74234353Sdim /// deal with that subset of the functions. 75234353Sdim bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false); 76193323Sed 77193323Sedprivate: 78193323Sed // InlineThreshold - Cache the value here for easy access. 79193323Sed unsigned InlineThreshold; 80193323Sed 81234353Sdim // InsertLifetime - Insert @llvm.lifetime intrinsics. 82234353Sdim bool InsertLifetime; 83234353Sdim 84193323Sed /// shouldInline - Return true if the inliner should attempt to 85193323Sed /// inline at the given CallSite. 86193323Sed bool shouldInline(CallSite CS); 87193323Sed}; 88193323Sed 89193323Sed} // End llvm namespace 90193323Sed 91193323Sed#endif 92