LegacyPassManager.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/Pass.h"
  23. #include "llvm/Support/CBindingWrapping.h"
  24. namespace llvm {
  25. class Pass;
  26. class Module;
  27. namespace legacy {
  28. class PassManagerImpl;
  29. class FunctionPassManagerImpl;
  30. /// PassManagerBase - An abstract interface to allow code to add passes to
  31. /// a pass manager without having to hard-code what kind of pass manager
  32. /// it is.
  33. class PassManagerBase {
  34. public:
  35. virtual ~PassManagerBase();
  36. /// Add a pass to the queue of passes to run. This passes ownership of
  37. /// the Pass to the PassManager. When the PassManager is destroyed, the pass
  38. /// will be destroyed as well, so there is no need to delete the pass. This
  39. /// may even destroy the pass right away if it is found to be redundant. This
  40. /// implies that all passes MUST be allocated with 'new'.
  41. virtual void add(Pass *P) = 0;
  42. };
  43. /// PassManager manages ModulePassManagers
  44. class PassManager : public PassManagerBase {
  45. public:
  46. PassManager();
  47. ~PassManager() override;
  48. void add(Pass *P) override;
  49. /// run - Execute all of the passes scheduled for execution. Keep track of
  50. /// whether any of the passes modifies the module, and if so, return true.
  51. bool run(Module &M);
  52. private:
  53. /// PassManagerImpl_New is the actual class. PassManager is just the
  54. /// wraper to publish simple pass manager interface
  55. PassManagerImpl *PM;
  56. };
  57. /// FunctionPassManager manages FunctionPasses.
  58. class FunctionPassManager : public PassManagerBase {
  59. public:
  60. /// FunctionPassManager ctor - This initializes the pass manager. It needs,
  61. /// but does not take ownership of, the specified Module.
  62. explicit FunctionPassManager(Module *M);
  63. ~FunctionPassManager() override;
  64. void add(Pass *P) override;
  65. /// run - Execute all of the passes scheduled for execution. Keep
  66. /// track of whether any of the passes modifies the function, and if
  67. /// so, return true.
  68. ///
  69. bool run(Function &F);
  70. /// doInitialization - Run all of the initializers for the function passes.
  71. ///
  72. bool doInitialization();
  73. /// doFinalization - Run all of the finalizers for the function passes.
  74. ///
  75. bool doFinalization();
  76. private:
  77. FunctionPassManagerImpl *FPM;
  78. Module *M;
  79. };
  80. } // End legacy namespace
  81. // Create wrappers for C Binding types (see CBindingWrapping.h).
  82. DEFINE_STDCXX_CONVERSION_FUNCTIONS(legacy::PassManagerBase, LLVMPassManagerRef)
  83. } // End llvm namespace
  84. #endif
  85. #ifdef __GNUC__
  86. #pragma GCC diagnostic pop
  87. #endif