LLVM API Documentation
00001 //===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines a simple policy-based bottom-up inliner. This file 00011 // implements all of the boring mechanics of the bottom-up inlining, while the 00012 // subclass determines WHAT to inline, which is the much more interesting 00013 // component. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #ifndef INLINER_H 00018 #define INLINER_H 00019 00020 #include "llvm/CallGraphSCCPass.h" 00021 #include "llvm/Transforms/Utils/InlineCost.h" 00022 00023 00024 namespace llvm { 00025 class CallSite; 00026 class TargetData; 00027 00028 /// Inliner - This class contains all of the helper code which is used to 00029 /// perform the inlining operations that do not depend on the policy. 00030 /// 00031 struct Inliner : public CallGraphSCCPass { 00032 explicit Inliner(void *ID); 00033 explicit Inliner(void *ID, int Threshold); 00034 00035 /// getAnalysisUsage - For this class, we declare that we require and preserve 00036 /// the call graph. If the derived class implements this method, it should 00037 /// always explicitly call the implementation here. 00038 virtual void getAnalysisUsage(AnalysisUsage &Info) const; 00039 00040 // Main run interface method, this implements the interface required by the 00041 // Pass class. 00042 virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCC); 00043 00044 // doFinalization - Remove now-dead linkonce functions at the end of 00045 // processing to avoid breaking the SCC traversal. 00046 virtual bool doFinalization(CallGraph &CG); 00047 00048 // InlineCallIfPossible 00049 bool InlineCallIfPossible(CallSite CS, CallGraph &CG, 00050 const SmallPtrSet<Function*, 8> &SCCFunctions, 00051 const TargetData *TD); 00052 00053 /// This method returns the value specified by the -inline-threshold value, 00054 /// specified on the command line. This is typically not directly needed. 00055 /// 00056 unsigned getInlineThreshold() const { return InlineThreshold; } 00057 00058 /// getInlineCost - This method must be implemented by the subclass to 00059 /// determine the cost of inlining the specified call site. If the cost 00060 /// returned is greater than the current inline threshold, the call site is 00061 /// not inlined. 00062 /// 00063 virtual InlineCost getInlineCost(CallSite CS) = 0; 00064 00065 // getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a 00066 // higher threshold to determine if the function call should be inlined. 00067 /// 00068 virtual float getInlineFudgeFactor(CallSite CS) = 0; 00069 00070 /// resetCachedCostInfo - erase any cached cost data from the derived class. 00071 /// If the derived class has no such data this can be empty. 00072 /// 00073 virtual void resetCachedCostInfo(Function* Caller) = 0; 00074 00075 /// removeDeadFunctions - Remove dead functions that are not included in 00076 /// DNR (Do Not Remove) list. 00077 bool removeDeadFunctions(CallGraph &CG, 00078 SmallPtrSet<const Function *, 16> *DNR = NULL); 00079 private: 00080 // InlineThreshold - Cache the value here for easy access. 00081 unsigned InlineThreshold; 00082 00083 /// shouldInline - Return true if the inliner should attempt to 00084 /// inline at the given CallSite. 00085 bool shouldInline(CallSite CS); 00086 }; 00087 00088 } // End llvm namespace 00089 00090 #endif