PassRegistry.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/PassRegistry.h - Pass Information Registry ----------*- 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 PassRegistry, a class that is used in the initialization
  15. // and registration of passes. At application startup, passes are registered
  16. // with the PassRegistry, which is later provided to the PassManager for
  17. // dependency resolution and similar tasks.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_PASSREGISTRY_H
  21. #define LLVM_PASSREGISTRY_H
  22. #include "llvm/ADT/DenseMap.h"
  23. #include "llvm/ADT/StringMap.h"
  24. #include "llvm/ADT/StringRef.h"
  25. #include "llvm/Support/CBindingWrapping.h"
  26. #include "llvm/Support/RWMutex.h"
  27. #include <memory>
  28. #include <vector>
  29. namespace llvm {
  30. class PassInfo;
  31. struct PassRegistrationListener;
  32. /// PassRegistry - This class manages the registration and intitialization of
  33. /// the pass subsystem as application startup, and assists the PassManager
  34. /// in resolving pass dependencies.
  35. /// NOTE: PassRegistry is NOT thread-safe. If you want to use LLVM on multiple
  36. /// threads simultaneously, you will need to use a separate PassRegistry on
  37. /// each thread.
  38. class PassRegistry {
  39. mutable sys::SmartRWMutex<true> Lock;
  40. /// PassInfoMap - Keep track of the PassInfo object for each registered pass.
  41. using MapType = DenseMap<const void *, const PassInfo *>;
  42. MapType PassInfoMap;
  43. using StringMapType = StringMap<const PassInfo *>;
  44. StringMapType PassInfoStringMap;
  45. std::vector<std::unique_ptr<const PassInfo>> ToFree;
  46. std::vector<PassRegistrationListener *> Listeners;
  47. public:
  48. PassRegistry() = default;
  49. ~PassRegistry();
  50. /// getPassRegistry - Access the global registry object, which is
  51. /// automatically initialized at application launch and destroyed by
  52. /// llvm_shutdown.
  53. static PassRegistry *getPassRegistry();
  54. /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
  55. /// type identifier (&MyPass::ID).
  56. const PassInfo *getPassInfo(const void *TI) const;
  57. /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
  58. /// argument string.
  59. const PassInfo *getPassInfo(StringRef Arg) const;
  60. /// registerPass - Register a pass (by means of its PassInfo) with the
  61. /// registry. Required in order to use the pass with a PassManager.
  62. void registerPass(const PassInfo &PI, bool ShouldFree = false);
  63. /// registerAnalysisGroup - Register an analysis group (or a pass implementing
  64. // an analysis group) with the registry. Like registerPass, this is required
  65. // in order for a PassManager to be able to use this group/pass.
  66. void registerAnalysisGroup(const void *InterfaceID, const void *PassID,
  67. PassInfo &Registeree, bool isDefault,
  68. bool ShouldFree = false);
  69. /// enumerateWith - Enumerate the registered passes, calling the provided
  70. /// PassRegistrationListener's passEnumerate() callback on each of them.
  71. void enumerateWith(PassRegistrationListener *L);
  72. /// addRegistrationListener - Register the given PassRegistrationListener
  73. /// to receive passRegistered() callbacks whenever a new pass is registered.
  74. void addRegistrationListener(PassRegistrationListener *L);
  75. /// removeRegistrationListener - Unregister a PassRegistrationListener so that
  76. /// it no longer receives passRegistered() callbacks.
  77. void removeRegistrationListener(PassRegistrationListener *L);
  78. };
  79. // Create wrappers for C Binding types (see CBindingWrapping.h).
  80. DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef)
  81. } // end namespace llvm
  82. #endif // LLVM_PASSREGISTRY_H
  83. #ifdef __GNUC__
  84. #pragma GCC diagnostic pop
  85. #endif