Convert several more passes to use getAnalysisIfAvailable<TargetData>()
[oota-llvm.git] / include / llvm / Transforms / IPO / InlinerPass.h
1 //===- InlinerPass.h - Code common to all inliners --------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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
13 // component.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef INLINER_H
18 #define INLINER_H
19
20 #include "llvm/CallGraphSCCPass.h"
21 #include "llvm/Transforms/Utils/InlineCost.h"
22
23
24 namespace llvm {
25   class CallSite;
26   class TargetData;
27
28 /// Inliner - This class contains all of the helper code which is used to
29 /// perform the inlining operations that do not depend on the policy.
30 ///
31 struct Inliner : public CallGraphSCCPass {
32   explicit Inliner(void *ID);
33   explicit Inliner(void *ID, int Threshold);
34
35   /// getAnalysisUsage - For this class, we declare that we require and preserve
36   /// the call graph.  If the derived class implements this method, it should
37   /// always explicitly call the implementation here.
38   virtual void getAnalysisUsage(AnalysisUsage &Info) const;
39
40   // Main run interface method, this implements the interface required by the
41   // Pass class.
42   virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCC);
43
44   // doFinalization - Remove now-dead linkonce functions at the end of
45   // processing to avoid breaking the SCC traversal.
46   virtual bool doFinalization(CallGraph &CG);
47
48   // InlineCallIfPossible
49   bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
50                             const SmallPtrSet<Function*, 8> &SCCFunctions,
51                             const TargetData *TD);
52
53   /// This method returns the value specified by the -inline-threshold value,
54   /// specified on the command line.  This is typically not directly needed.
55   ///
56   unsigned getInlineThreshold() const { return InlineThreshold; }
57
58   /// getInlineCost - This method must be implemented by the subclass to
59   /// determine the cost of inlining the specified call site.  If the cost
60   /// returned is greater than the current inline threshold, the call site is
61   /// not inlined.
62   ///
63   virtual InlineCost getInlineCost(CallSite CS) = 0;
64
65   // getInlineFudgeFactor - Return a > 1.0 factor if the inliner should use a
66   // higher threshold to determine if the function call should be inlined.
67   ///
68   virtual float getInlineFudgeFactor(CallSite CS) = 0;
69
70   /// resetCachedCostInfo - erase any cached cost data from the derived class.
71   /// If the derived class has no such data this can be empty.
72   /// 
73   virtual void resetCachedCostInfo(Function* Caller) = 0;
74
75   /// removeDeadFunctions - Remove dead functions that are not included in
76   /// DNR (Do Not Remove) list.
77   bool removeDeadFunctions(CallGraph &CG, 
78                            SmallPtrSet<const Function *, 16> *DNR = NULL);
79 private:
80   // InlineThreshold - Cache the value here for easy access.
81   unsigned InlineThreshold;
82
83   /// shouldInline - Return true if the inliner should attempt to
84   /// inline at the given CallSite.
85   bool shouldInline(CallSite CS);
86 };
87
88 } // End llvm namespace
89
90 #endif