LLVM  3.7.0
InlinerPass.h
Go to the documentation of this file.
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 LLVM_TRANSFORMS_IPO_INLINERPASS_H
18 #define LLVM_TRANSFORMS_IPO_INLINERPASS_H
19 
21 
22 namespace llvm {
23  class CallSite;
24  class DataLayout;
25  class InlineCost;
26  template<class PtrType, unsigned SmallSize>
27  class SmallPtrSet;
28 
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.
31 ///
32 struct Inliner : public CallGraphSCCPass {
33  explicit Inliner(char &ID);
34  explicit Inliner(char &ID, int Threshold, bool InsertLifetime);
35 
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  void getAnalysisUsage(AnalysisUsage &Info) const override;
40 
41  // Main run interface method, this implements the interface required by the
42  // Pass class.
43  bool runOnSCC(CallGraphSCC &SCC) override;
44 
46  // doFinalization - Remove now-dead linkonce functions at the end of
47  // processing to avoid breaking the SCC traversal.
48  bool doFinalization(CallGraph &CG) override;
49 
50  /// This method returns the value specified by the -inline-threshold value,
51  /// specified on the command line. This is typically not directly needed.
52  ///
53  unsigned getInlineThreshold() const { return InlineThreshold; }
54 
55  /// Calculate the inline threshold for given Caller. This threshold is lower
56  /// if the caller is marked with OptimizeForSize and -inline-threshold is not
57  /// given on the comand line. It is higher if the callee is marked with the
58  /// inlinehint attribute.
59  ///
60  unsigned getInlineThreshold(CallSite CS) const;
61 
62  /// getInlineCost - This method must be implemented by the subclass to
63  /// determine the cost of inlining the specified call site. If the cost
64  /// returned is greater than the current inline threshold, the call site is
65  /// not inlined.
66  ///
67  virtual InlineCost getInlineCost(CallSite CS) = 0;
68 
69  /// removeDeadFunctions - Remove dead functions.
70  ///
71  /// This also includes a hack in the form of the 'AlwaysInlineOnly' flag
72  /// which restricts it to deleting functions with an 'AlwaysInline'
73  /// attribute. This is useful for the InlineAlways pass that only wants to
74  /// deal with that subset of the functions.
75  bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly = false);
76 
77 private:
78  // InlineThreshold - Cache the value here for easy access.
79  unsigned InlineThreshold;
80 
81  // InsertLifetime - Insert @llvm.lifetime intrinsics.
82  bool InsertLifetime;
83 
84  /// shouldInline - Return true if the inliner should attempt to
85  /// inline at the given CallSite.
86  bool shouldInline(CallSite CS);
87 };
88 
89 } // End llvm namespace
90 
91 #endif
unsigned getInlineThreshold() const
This method returns the value specified by the -inline-threshold value, specified on the command line...
Definition: InlinerPass.h:53
bool removeDeadFunctions(CallGraph &CG, bool AlwaysInlineOnly=false)
removeDeadFunctions - Remove dead functions.
Definition: Inliner.cpp:630
bool doFinalization(CallGraph &CG) override
Remove now-dead linkonce functions at the end of processing to avoid breaking the SCC traversal...
Definition: Inliner.cpp:625
Represents the cost of inlining a function.
Definition: InlineCost.h:51
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:116
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...
Definition: Inliner.cpp:78
Inliner - This class contains all of the helper code which is used to perform the inlining operations...
Definition: InlinerPass.h:32
Represent the analysis usage information of a pass.
bool runOnSCC(CallGraphSCC &SCC) override
runOnSCC - This method should be implemented by the subclass to perform whatever action is necessary ...
Definition: Inliner.cpp:431
virtual InlineCost getInlineCost(CallSite CS)=0
getInlineCost - This method must be implemented by the subclass to determine the cost of inlining the...
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:75
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
Inliner(char &ID)
Definition: Inliner.cpp:67