2bc163d548755f0e0c2b12e18bddf522c0fbecc7
[oota-llvm.git] / include / llvm / CallGraphSCCPass.h
1 //===- CallGraphSCCPass.h - Pass that operates BU on call graph -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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_CALL_GRAPH_SCC_PASS_H
22 #define LLVM_CALL_GRAPH_SCC_PASS_H
23
24 #include "llvm/Pass.h"
25
26 namespace llvm {
27
28 class CallGraphNode;
29 class CallGraph;
30 class PMStack;
31
32 struct CallGraphSCCPass : public Pass {
33
34   explicit CallGraphSCCPass(intptr_t pid) : Pass(pid) {}
35
36   /// doInitialization - This method is called before the SCC's of the program
37   /// has been processed, allowing the pass to do initialization as necessary.
38   virtual bool doInitialization(CallGraph &CG) {
39     return false;
40   }
41
42   /// runOnSCC - This method should be implemented by the subclass to perform
43   /// whatever action is necessary for the specified SCC.  Note that
44   /// non-recursive (or only self-recursive) functions will have an SCC size of
45   /// 1, where recursive portions of the call graph will have SCC size > 1.
46   ///
47   virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCC) = 0;
48
49   /// doFinalization - This method is called after the SCC's of the program has
50   /// been processed, allowing the pass to do final cleanup as necessary.
51   virtual bool doFinalization(CallGraph &CG) {
52     return false;
53   }
54
55   /// Assign pass manager to manager this pass
56   virtual void assignPassManager(PMStack &PMS,
57                                  PassManagerType PMT = PMT_CallGraphPassManager);
58
59   ///  Return what kind of Pass Manager can manage this pass.
60   virtual PassManagerType getPotentialPassManagerType() const {
61     return PMT_CallGraphPassManager;
62   }
63
64   /// getAnalysisUsage - For this class, we declare that we require and preserve
65   /// the call graph.  If the derived class implements this method, it should
66   /// always explicitly call the implementation here.
67   virtual void getAnalysisUsage(AnalysisUsage &Info) const;
68 };
69
70 } // End llvm namespace
71
72 #endif