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.

160 lines
5.6 KiB

  1. //===- LoopPass.h - LoopPass 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 LoopPass class. All loop optimization
  11. // and transformation passes are derived from LoopPass.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_ANALYSIS_LOOPPASS_H
  15. #define LLVM_ANALYSIS_LOOPPASS_H
  16. #include "llvm/Analysis/LoopInfo.h"
  17. #include "llvm/Pass.h"
  18. #include "llvm/PassManagers.h"
  19. #include <deque>
  20. namespace llvm {
  21. class LPPassManager;
  22. class Function;
  23. class PMStack;
  24. class LoopPass : public Pass {
  25. public:
  26. explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
  27. /// getPrinterPass - Get a pass to print the function corresponding
  28. /// to a Loop.
  29. Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const;
  30. // runOnLoop - This method should be implemented by the subclass to perform
  31. // whatever action is necessary for the specified Loop.
  32. virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0;
  33. using llvm::Pass::doInitialization;
  34. using llvm::Pass::doFinalization;
  35. // Initialization and finalization hooks.
  36. virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
  37. return false;
  38. }
  39. // Finalization hook does not supply Loop because at this time
  40. // loop nest is completely different.
  41. virtual bool doFinalization() { return false; }
  42. // Check if this pass is suitable for the current LPPassManager, if
  43. // available. This pass P is not suitable for a LPPassManager if P
  44. // is not preserving higher level analysis info used by other
  45. // LPPassManager passes. In such case, pop LPPassManager from the
  46. // stack. This will force assignPassManager() to create new
  47. // LPPassManger as expected.
  48. void preparePassManager(PMStack &PMS);
  49. /// Assign pass manager to manage this pass
  50. virtual void assignPassManager(PMStack &PMS,
  51. PassManagerType PMT);
  52. /// Return what kind of Pass Manager can manage this pass.
  53. virtual PassManagerType getPotentialPassManagerType() const {
  54. return PMT_LoopPassManager;
  55. }
  56. //===--------------------------------------------------------------------===//
  57. /// SimpleAnalysis - Provides simple interface to update analysis info
  58. /// maintained by various passes. Note, if required this interface can
  59. /// be extracted into a separate abstract class but it would require
  60. /// additional use of multiple inheritance in Pass class hierarchy, something
  61. /// we are trying to avoid.
  62. /// Each loop pass can override these simple analysis hooks to update
  63. /// desired analysis information.
  64. /// cloneBasicBlockAnalysis - Clone analysis info associated with basic block.
  65. virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L) {}
  66. /// deleteAnalysisValue - Delete analysis info associated with value V.
  67. virtual void deleteAnalysisValue(Value *V, Loop *L) {}
  68. };
  69. class LPPassManager : public FunctionPass, public PMDataManager {
  70. public:
  71. static char ID;
  72. explicit LPPassManager();
  73. /// run - Execute all of the passes scheduled for execution. Keep track of
  74. /// whether any of the passes modifies the module, and if so, return true.
  75. bool runOnFunction(Function &F);
  76. /// Pass Manager itself does not invalidate any analysis info.
  77. // LPPassManager needs LoopInfo.
  78. void getAnalysisUsage(AnalysisUsage &Info) const;
  79. virtual const char *getPassName() const {
  80. return "Loop Pass Manager";
  81. }
  82. virtual PMDataManager *getAsPMDataManager() { return this; }
  83. virtual Pass *getAsPass() { return this; }
  84. /// Print passes managed by this manager
  85. void dumpPassStructure(unsigned Offset);
  86. LoopPass *getContainedPass(unsigned N) {
  87. assert(N < PassVector.size() && "Pass number out of range!");
  88. LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
  89. return LP;
  90. }
  91. virtual PassManagerType getPassManagerType() const {
  92. return PMT_LoopPassManager;
  93. }
  94. public:
  95. // Delete loop from the loop queue and loop nest (LoopInfo).
  96. void deleteLoopFromQueue(Loop *L);
  97. // Insert loop into the loop queue and add it as a child of the
  98. // given parent.
  99. void insertLoop(Loop *L, Loop *ParentLoop);
  100. // Insert a loop into the loop queue.
  101. void insertLoopIntoQueue(Loop *L);
  102. // Reoptimize this loop. LPPassManager will re-insert this loop into the
  103. // queue. This allows LoopPass to change loop nest for the loop. This
  104. // utility may send LPPassManager into infinite loops so use caution.
  105. void redoLoop(Loop *L);
  106. //===--------------------------------------------------------------------===//
  107. /// SimpleAnalysis - Provides simple interface to update analysis info
  108. /// maintained by various passes. Note, if required this interface can
  109. /// be extracted into a separate abstract class but it would require
  110. /// additional use of multiple inheritance in Pass class hierarchy, something
  111. /// we are trying to avoid.
  112. /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
  113. /// all passes that implement simple analysis interface.
  114. void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L);
  115. /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
  116. /// that implement simple analysis interface.
  117. void deleteSimpleAnalysisValue(Value *V, Loop *L);
  118. private:
  119. std::deque<Loop *> LQ;
  120. bool skipThisLoop;
  121. bool redoThisLoop;
  122. LoopInfo *LI;
  123. Loop *CurrentLoop;
  124. };
  125. } // End llvm namespace
  126. #endif