Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.9 KiB

  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. #ifndef LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
  21. #define LLVM_ANALYSIS_CALLGRAPHSCCPASS_H
  22. #include "llvm/Analysis/CallGraph.h"
  23. #include "llvm/Pass.h"
  24. namespace llvm {
  25. class CallGraphNode;
  26. class CallGraph;
  27. class PMStack;
  28. class CallGraphSCC;
  29. class CallGraphSCCPass : public Pass {
  30. public:
  31. explicit CallGraphSCCPass(char &pid) : Pass(PT_CallGraphSCC, pid) {}
  32. /// createPrinterPass - Get a pass that prints the Module
  33. /// corresponding to a CallGraph.
  34. Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const;
  35. using llvm::Pass::doInitialization;
  36. using llvm::Pass::doFinalization;
  37. /// doInitialization - This method is called before the SCC's of the program
  38. /// has been processed, allowing the pass to do initialization as necessary.
  39. virtual bool doInitialization(CallGraph &CG) {
  40. return false;
  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. /// SCC passes that add or delete functions to the SCC are required to update
  48. /// the SCC list, otherwise stale pointers may be dereferenced.
  49. ///
  50. virtual bool runOnSCC(CallGraphSCC &SCC) = 0;
  51. /// doFinalization - This method is called after the SCC's of the program has
  52. /// been processed, allowing the pass to do final cleanup as necessary.
  53. virtual bool doFinalization(CallGraph &CG) {
  54. return false;
  55. }
  56. /// Assign pass manager to manager this pass
  57. virtual void assignPassManager(PMStack &PMS,
  58. PassManagerType PMT);
  59. /// Return what kind of Pass Manager can manage this pass.
  60. virtual PassManagerType getPotentialPassManagerType() const {
  61. return PMT_CallGraphPassManager;
  62. }
  63. /// getAnalysisUsage - For this class, we declare that we require and preserve
  64. /// the call graph. If the derived class implements this method, it should
  65. /// always explicitly call the implementation here.
  66. virtual void getAnalysisUsage(AnalysisUsage &Info) const;
  67. };
  68. /// CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
  69. class CallGraphSCC {
  70. void *Context; // The CGPassManager object that is vending this.
  71. std::vector<CallGraphNode*> Nodes;
  72. public:
  73. CallGraphSCC(void *context) : Context(context) {}
  74. void initialize(CallGraphNode*const*I, CallGraphNode*const*E) {
  75. Nodes.assign(I, E);
  76. }
  77. bool isSingular() const { return Nodes.size() == 1; }
  78. unsigned size() const { return Nodes.size(); }
  79. /// ReplaceNode - This informs the SCC and the pass manager that the specified
  80. /// Old node has been deleted, and New is to be used in its place.
  81. void ReplaceNode(CallGraphNode *Old, CallGraphNode *New);
  82. typedef std::vector<CallGraphNode*>::const_iterator iterator;
  83. iterator begin() const { return Nodes.begin(); }
  84. iterator end() const { return Nodes.end(); }
  85. };
  86. } // End llvm namespace
  87. #endif