PassRegistry.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. //mutable sys::SmartRWMutex<true> Lock; // HLSL Change - no lock needed
  38. /// PassInfoMap - Keep track of the PassInfo object for each registered pass.
  39. typedef DenseMap<const void *, const PassInfo *> MapType;
  40. MapType PassInfoMap;
  41. typedef StringMap<const PassInfo *> StringMapType;
  42. StringMapType PassInfoStringMap;
  43. std::vector<std::unique_ptr<const PassInfo>> ToFree;
  44. std::vector<PassRegistrationListener *> Listeners;
  45. public:
  46. PassRegistry() {}
  47. ~PassRegistry();
  48. /// getPassRegistry - Access the global registry object, which is
  49. /// automatically initialized at application launch and destroyed by
  50. /// llvm_shutdown.
  51. static PassRegistry *getPassRegistry();
  52. /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
  53. /// type identifier (&MyPass::ID).
  54. const PassInfo *getPassInfo(const void *TI) const;
  55. /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
  56. /// argument string.
  57. const PassInfo *getPassInfo(StringRef Arg) const;
  58. /// registerPass - Register a pass (by means of its PassInfo) with the
  59. /// registry. Required in order to use the pass with a PassManager.
  60. void registerPass(const PassInfo &PI, bool ShouldFree = false);
  61. /// registerAnalysisGroup - Register an analysis group (or a pass implementing
  62. // an analysis group) with the registry. Like registerPass, this is required
  63. // in order for a PassManager to be able to use this group/pass.
  64. void registerAnalysisGroup(const void *InterfaceID, const void *PassID,
  65. PassInfo &Registeree, bool isDefault,
  66. bool ShouldFree = false);
  67. /// enumerateWith - Enumerate the registered passes, calling the provided
  68. /// PassRegistrationListener's passEnumerate() callback on each of them.
  69. void enumerateWith(PassRegistrationListener *L);
  70. /// addRegistrationListener - Register the given PassRegistrationListener
  71. /// to receive passRegistered() callbacks whenever a new pass is registered.
  72. void addRegistrationListener(PassRegistrationListener *L);
  73. /// removeRegistrationListener - Unregister a PassRegistrationListener so that
  74. /// it no longer receives passRegistered() callbacks.
  75. void removeRegistrationListener(PassRegistrationListener *L);
  76. };
  77. // Create wrappers for C Binding types (see CBindingWrapping.h).
  78. DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef)
  79. }
  80. #endif