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.

127 lines
3.8 KiB

  1. //===- RegionPass.h - RegionPass class ------------------------------------===//
  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 RegionPass class. All region based analysis,
  11. // optimization and transformation passes are derived from RegionPass.
  12. // This class is implemented following the some ideas of the LoopPass.h class.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_ANALYSIS_REGIONPASS_H
  16. #define LLVM_ANALYSIS_REGIONPASS_H
  17. #include "llvm/Analysis/RegionInfo.h"
  18. #include "llvm/IR/Function.h"
  19. #include "llvm/Pass.h"
  20. #include "llvm/PassManagers.h"
  21. #include <deque>
  22. namespace llvm {
  23. class RGPassManager;
  24. class Function;
  25. //===----------------------------------------------------------------------===//
  26. /// @brief A pass that runs on each Region in a function.
  27. ///
  28. /// RegionPass is managed by RGPassManager.
  29. class RegionPass : public Pass {
  30. public:
  31. explicit RegionPass(char &pid) : Pass(PT_Region, pid) {}
  32. //===--------------------------------------------------------------------===//
  33. /// @name To be implemented by every RegionPass
  34. ///
  35. //@{
  36. /// @brief Run the pass on a specific Region
  37. ///
  38. /// Accessing regions not contained in the current region is not allowed.
  39. ///
  40. /// @param R The region this pass is run on.
  41. /// @param RGM The RegionPassManager that manages this Pass.
  42. ///
  43. /// @return True if the pass modifies this Region.
  44. virtual bool runOnRegion(Region *R, RGPassManager &RGM) = 0;
  45. /// @brief Get a pass to print the LLVM IR in the region.
  46. ///
  47. /// @param O The ouput stream to print the Region.
  48. /// @param Banner The banner to separate different printed passes.
  49. ///
  50. /// @return The pass to print the LLVM IR in the region.
  51. Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const;
  52. using llvm::Pass::doInitialization;
  53. using llvm::Pass::doFinalization;
  54. virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; }
  55. virtual bool doFinalization() { return false; }
  56. //@}
  57. //===--------------------------------------------------------------------===//
  58. /// @name PassManager API
  59. ///
  60. //@{
  61. void preparePassManager(PMStack &PMS);
  62. virtual void assignPassManager(PMStack &PMS,
  63. PassManagerType PMT = PMT_RegionPassManager);
  64. virtual PassManagerType getPotentialPassManagerType() const {
  65. return PMT_RegionPassManager;
  66. }
  67. //@}
  68. };
  69. /// @brief The pass manager to schedule RegionPasses.
  70. class RGPassManager : public FunctionPass, public PMDataManager {
  71. std::deque<Region*> RQ;
  72. bool skipThisRegion;
  73. bool redoThisRegion;
  74. RegionInfo *RI;
  75. Region *CurrentRegion;
  76. public:
  77. static char ID;
  78. explicit RGPassManager();
  79. /// @brief Execute all of the passes scheduled for execution.
  80. ///
  81. /// @return True if any of the passes modifies the function.
  82. bool runOnFunction(Function &F);
  83. /// Pass Manager itself does not invalidate any analysis info.
  84. /// RGPassManager needs RegionInfo.
  85. void getAnalysisUsage(AnalysisUsage &Info) const;
  86. virtual const char *getPassName() const {
  87. return "Region Pass Manager";
  88. }
  89. virtual PMDataManager *getAsPMDataManager() { return this; }
  90. virtual Pass *getAsPass() { return this; }
  91. /// @brief Print passes managed by this manager.
  92. void dumpPassStructure(unsigned Offset);
  93. /// @brief Get passes contained by this manager.
  94. Pass *getContainedPass(unsigned N) {
  95. assert(N < PassVector.size() && "Pass number out of range!");
  96. Pass *FP = static_cast<Pass *>(PassVector[N]);
  97. return FP;
  98. }
  99. virtual PassManagerType getPassManagerType() const {
  100. return PMT_RegionPassManager;
  101. }
  102. };
  103. } // End llvm namespace
  104. #endif