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