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