LegacyPassManager.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //===- LegacyPassManager.h - Legacy Container for Passes --------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the legacy PassManager class. This class is used to hold,
  10. // maintain, and optimize execution of Passes. The PassManager class ensures
  11. // that analysis results are available before a pass runs, and that Pass's are
  12. // destroyed when the PassManager is destroyed.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_IR_LEGACYPASSMANAGER_H
  16. #define LLVM_IR_LEGACYPASSMANAGER_H
  17. #include "llvm/Pass.h"
  18. #include "llvm/Support/CBindingWrapping.h"
  19. namespace llvm {
  20. class Pass;
  21. class Module;
  22. namespace legacy {
  23. // Whether or not -debug-pass has been specified. For use to check if it's
  24. // specified alongside the new PM.
  25. bool debugPassSpecified();
  26. class PassManagerImpl;
  27. class FunctionPassManagerImpl;
  28. /// PassManagerBase - An abstract interface to allow code to add passes to
  29. /// a pass manager without having to hard-code what kind of pass manager
  30. /// it is.
  31. class PassManagerBase {
  32. public:
  33. virtual ~PassManagerBase();
  34. /// Add a pass to the queue of passes to run. This passes ownership of
  35. /// the Pass to the PassManager. When the PassManager is destroyed, the pass
  36. /// will be destroyed as well, so there is no need to delete the pass. This
  37. /// may even destroy the pass right away if it is found to be redundant. This
  38. /// implies that all passes MUST be allocated with 'new'.
  39. virtual void add(Pass *P) = 0;
  40. };
  41. /// PassManager manages ModulePassManagers
  42. class PassManager : public PassManagerBase {
  43. public:
  44. PassManager();
  45. ~PassManager() override;
  46. void add(Pass *P) override;
  47. /// run - Execute all of the passes scheduled for execution. Keep track of
  48. /// whether any of the passes modifies the module, and if so, return true.
  49. bool run(Module &M);
  50. private:
  51. /// PassManagerImpl_New is the actual class. PassManager is just the
  52. /// wraper to publish simple pass manager interface
  53. PassManagerImpl *PM;
  54. };
  55. /// FunctionPassManager manages FunctionPasses.
  56. class FunctionPassManager : public PassManagerBase {
  57. public:
  58. /// FunctionPassManager ctor - This initializes the pass manager. It needs,
  59. /// but does not take ownership of, the specified Module.
  60. explicit FunctionPassManager(Module *M);
  61. ~FunctionPassManager() override;
  62. void add(Pass *P) override;
  63. /// run - Execute all of the passes scheduled for execution. Keep
  64. /// track of whether any of the passes modifies the function, and if
  65. /// so, return true.
  66. ///
  67. bool run(Function &F);
  68. /// doInitialization - Run all of the initializers for the function passes.
  69. ///
  70. bool doInitialization();
  71. /// doFinalization - Run all of the finalizers for the function passes.
  72. ///
  73. bool doFinalization();
  74. private:
  75. FunctionPassManagerImpl *FPM;
  76. Module *M;
  77. };
  78. } // End legacy namespace
  79. // Create wrappers for C Binding types (see CBindingWrapping.h).
  80. DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef)
  81. } // End llvm namespace
  82. #endif