LegacyPassManager.h 3.4 KB

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