PassRegistry.h 3.9 KB

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