LLVM  3.7.0
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 
27 namespace llvm {
28 
29 class CallGraphNode;
30 class CallGraph;
31 class PMStack;
32 class CallGraphSCC;
33 
34 class CallGraphSCCPass : public Pass {
35 public:
36  explicit CallGraphSCCPass(char &pid) : Pass(PT_CallGraphSCC, pid) {}
37 
38  /// createPrinterPass - Get a pass that prints the Module
39  /// corresponding to a CallGraph.
41  const std::string &Banner) const override;
42 
45 
46  /// doInitialization - This method is called before the SCC's of the program
47  /// has been processed, allowing the pass to do initialization as necessary.
48  virtual bool doInitialization(CallGraph &CG) {
49  return false;
50  }
51 
52  /// runOnSCC - This method should be implemented by the subclass to perform
53  /// whatever action is necessary for the specified SCC. Note that
54  /// non-recursive (or only self-recursive) functions will have an SCC size of
55  /// 1, where recursive portions of the call graph will have SCC size > 1.
56  ///
57  /// SCC passes that add or delete functions to the SCC are required to update
58  /// the SCC list, otherwise stale pointers may be dereferenced.
59  ///
60  virtual bool runOnSCC(CallGraphSCC &SCC) = 0;
61 
62  /// doFinalization - This method is called after the SCC's of the program has
63  /// been processed, allowing the pass to do final cleanup as necessary.
64  virtual bool doFinalization(CallGraph &CG) {
65  return false;
66  }
67 
68  /// Assign pass manager to manager this pass
69  void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
70 
71  /// Return what kind of Pass Manager can manage this pass.
74  }
75 
76  /// getAnalysisUsage - For this class, we declare that we require and preserve
77  /// the call graph. If the derived class implements this method, it should
78  /// always explicitly call the implementation here.
79  void getAnalysisUsage(AnalysisUsage &Info) const override;
80 };
81 
82 /// CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
83 class CallGraphSCC {
84  void *Context; // The CGPassManager object that is vending this.
85  std::vector<CallGraphNode*> Nodes;
86 public:
87  CallGraphSCC(void *context) : Context(context) {}
88 
89  void initialize(CallGraphNode*const*I, CallGraphNode*const*E) {
90  Nodes.assign(I, E);
91  }
92 
93  bool isSingular() const { return Nodes.size() == 1; }
94  unsigned size() const { return Nodes.size(); }
95 
96  /// ReplaceNode - This informs the SCC and the pass manager that the specified
97  /// Old node has been deleted, and New is to be used in its place.
98  void ReplaceNode(CallGraphNode *Old, CallGraphNode *New);
99 
100  typedef std::vector<CallGraphNode*>::const_iterator iterator;
101  iterator begin() const { return Nodes.begin(); }
102  iterator end() const { return Nodes.end(); }
103 };
104 
105 } // End llvm namespace
106 
107 #endif
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:82
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:55
CGPassManager.
Definition: Pass.h:58
bool isSingular() const
std::vector< CallGraphNode * >::const_iterator iterator
unsigned size() const
virtual bool doInitialization(CallGraph &CG)
doInitialization - This method is called before the SCC's of the program has been processed...
A node in the call graph for a module.
Definition: CallGraph.h:166
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...
iterator end() const
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:116
PMStack - This class implements a stack data structure of PMDataManager pointers. ...
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:111
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 assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manager this pass.
CallGraphSCC(void *context)
iterator begin() const
The basic data container for the call graph of a Module of IR.
Definition: CallGraph.h:75
void ReplaceNode(CallGraphNode *Old, CallGraphNode *New)
ReplaceNode - This informs the SCC and the pass manager that the specified Old node has been deleted...
#define I(x, y, z)
Definition: MD5.cpp:54
virtual bool doFinalization(CallGraph &CG)
doFinalization - This method is called after the SCC'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:38
void initialize(CallGraphNode *const *I, CallGraphNode *const *E)