LLVM  6.0.0svn
CallGraphSCCPass.h
Go to the documentation of this file.
1 //===- CallGraphSCCPass.h - Pass that operates BU on call graph -*- 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 the CallGraphSCCPass class, which is used for passes which
11 // are implemented as bottom-up traversals on the call graph. Because there may
12 // be cycles in the call graph, passes of this type operate on the call-graph in
13 // SCC order: that is, they process function bottom-up, except for recursive
14 // functions, which they process all at once.
15 //
16 // These passes are inherently interprocedural, and are required to keep the
17 // call graph up-to-date if they do anything which could modify it.
18 //
19 //===----------------------------------------------------------------------===//
20 
21 #ifndef LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
22 #define LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
23 
25 #include "llvm/Pass.h"
26 #include "llvm/PassSupport.h"
27 
28 namespace llvm {
29 
30 class CallGraphNode;
31 class CallGraph;
32 class PMStack;
33 class CallGraphSCC;
34 
35 class CallGraphSCCPass : public Pass {
36 public:
37  explicit CallGraphSCCPass(char &pid) : Pass(PT_CallGraphSCC, pid) {}
38 
39  /// createPrinterPass - Get a pass that prints the Module
40  /// corresponding to a CallGraph.
42  const std::string &Banner) const override;
43 
46 
47  /// doInitialization - This method is called before the SCC's of the program
48  /// has been processed, allowing the pass to do initialization as necessary.
49  virtual bool doInitialization(CallGraph &CG) {
50  return false;
51  }
52 
53  /// runOnSCC - This method should be implemented by the subclass to perform
54  /// whatever action is necessary for the specified SCC. Note that
55  /// non-recursive (or only self-recursive) functions will have an SCC size of
56  /// 1, where recursive portions of the call graph will have SCC size > 1.
57  ///
58  /// SCC passes that add or delete functions to the SCC are required to update
59  /// the SCC list, otherwise stale pointers may be dereferenced.
60  ///
61  virtual bool runOnSCC(CallGraphSCC &SCC) = 0;
62 
63  /// doFinalization - This method is called after the SCC's of the program has
64  /// been processed, allowing the pass to do final cleanup as necessary.
65  virtual bool doFinalization(CallGraph &CG) {
66  return false;
67  }
68 
69  /// Assign pass manager to manager this pass
70  void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
71 
72  /// Return what kind of Pass Manager can manage this pass.
75  }
76 
77  /// getAnalysisUsage - For this class, we declare that we require and preserve
78  /// the call graph. If the derived class implements this method, it should
79  /// always explicitly call the implementation here.
80  void getAnalysisUsage(AnalysisUsage &Info) const override;
81 
82 protected:
83  /// Optional passes call this function to check whether the pass should be
84  /// skipped. This is the case when optimization bisect is over the limit.
85  bool skipSCC(CallGraphSCC &SCC) const;
86 };
87 
88 /// CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
89 class CallGraphSCC {
90  const CallGraph &CG; // The call graph for this SCC.
91  void *Context; // The CGPassManager object that is vending this.
92  std::vector<CallGraphNode*> Nodes;
93 
94 public:
95  CallGraphSCC(CallGraph &cg, void *context) : CG(cg), Context(context) {}
96 
98  Nodes.assign(NewNodes.begin(), NewNodes.end());
99  }
100 
101  bool isSingular() const { return Nodes.size() == 1; }
102  unsigned size() const { return Nodes.size(); }
103 
104  /// ReplaceNode - This informs the SCC and the pass manager that the specified
105  /// Old node has been deleted, and New is to be used in its place.
106  void ReplaceNode(CallGraphNode *Old, CallGraphNode *New);
107 
108  typedef std::vector<CallGraphNode *>::const_iterator iterator;
109  iterator begin() const { return Nodes.begin(); }
110  iterator end() const { return Nodes.end(); }
111 
112  const CallGraph &getCallGraph() { return CG; }
113 };
114 
116 
117 /// This pass is required by interprocedural register allocation. It forces
118 /// codegen to follow bottom up order on call graph.
120 public:
121  static char ID;
125  };
126  bool runOnSCC(CallGraphSCC &SCC) override { return false; }
127  void getAnalysisUsage(AnalysisUsage &AU) const override {
128  AU.setPreservesAll();
129  }
130 };
131 
132 } // End llvm namespace
133 
134 #endif
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:54
bool runOnSCC(CallGraphSCC &SCC) override
runOnSCC - This method should be implemented by the subclass to perform whatever action is necessary ...
CGPassManager.
Definition: Pass.h:57
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & Context
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
iterator begin() const
Definition: ArrayRef.h:137
iterator end() const
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:45
virtual bool doInitialization(CallGraph &CG)
doInitialization - This method is called before the SCC&#39;s of the program has been processed...
A node in the call graph for a module.
Definition: CallGraph.h:165
bool skipSCC(CallGraphSCC &SCC) const
Optional passes call this function to check whether the pass should be skipped.
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...
std::vector< CallGraphNode * >::const_iterator iterator
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:115
const CallGraph & getCallGraph()
PMStack - This class implements a stack data structure of PMDataManager pointers. ...
bool isSingular() const
unsigned size() const
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:110
iterator begin() const
This pass is required by interprocedural register allocation.
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
createPrinterPass - Get a pass that prints the Module corresponding to a CallGraph.
Represent the analysis usage information of a pass.
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
void initialize(ArrayRef< CallGraphNode *> NewNodes)
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manager this pass.
void initializeDummyCGSCCPassPass(PassRegistry &)
iterator end() const
Definition: ArrayRef.h:138
void setPreservesAll()
Set by analyses that do not transform their input at all.
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:74
CallGraphSCC(CallGraph &cg, void *context)
virtual bool doFinalization(CallGraph &CG)
doFinalization - This method is called after the SCC&#39;s of the program has been processed, allowing the pass to do final cleanup as necessary.
virtual bool runOnSCC(CallGraphSCC &SCC)=0
runOnSCC - This method should be implemented by the subclass to perform whatever action is necessary ...
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:40
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...