1 //===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_TRANSFORMS_IPO_INLINERPASS_H
18 #define LLVM_TRANSFORMS_IPO_INLINERPASS_H
20 #include "llvm/CallGraphSCCPass.h"
26 template<class PtrType, unsigned SmallSize>
29 /// Inliner - This class contains all of the helper code which is used to
30 /// perform the inlining operations that do not depend on the policy.
32 struct Inliner : public CallGraphSCCPass {
33 explicit Inliner(void *ID);
34 explicit Inliner(void *ID, int Threshold);
36 /// getAnalysisUsage - For this class, we declare that we require and preserve
37 /// the call graph. If the derived class implements this method, it should
38 /// always explicitly call the implementation here.
39 virtual void getAnalysisUsage(AnalysisUsage &Info) const;
41 // Main run interface method, this implements the interface required by the
43 virtual bool runOnSCC(std::vector<CallGraphNode *> &SCC);
45 // doFinalization - Remove now-dead linkonce functions at the end of
46 // processing to avoid breaking the SCC traversal.
47 virtual bool doFinalization(CallGraph &CG);
49 /// This method returns the value specified by the -inline-threshold value,
50 /// specified on the command line. This is typically not directly needed.
52 unsigned getInlineThreshold() const { return InlineThreshold; }
54 /// getInlineCost - This method must be implemented by the subclass to
55 /// determine the cost of inlining the specified call site. If the cost
56 /// returned is greater than the current inline threshold, the call site is
59 virtual InlineCost getInlineCost(CallSite CS) = 0;
61 // getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a
62 // higher threshold to determine if the function call should be inlined.
64 virtual float getInlineFudgeFactor(CallSite CS) = 0;
66 /// resetCachedCostInfo - erase any cached cost data from the derived class.
67 /// If the derived class has no such data this can be empty.
69 virtual void resetCachedCostInfo(Function* Caller) = 0;
71 /// removeDeadFunctions - Remove dead functions that are not included in
72 /// DNR (Do Not Remove) list.
73 bool removeDeadFunctions(CallGraph &CG,
74 SmallPtrSet<const Function *, 16> *DNR = NULL);
76 // InlineThreshold - Cache the value here for easy access.
77 unsigned InlineThreshold;
79 /// shouldInline - Return true if the inliner should attempt to
80 /// inline at the given CallSite.
81 bool shouldInline(CallSite CS);
84 } // End llvm namespace