1 //===- llvm/PassRegistry.h - Pass Information Registry ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_PASSREGISTRY_H
18 #define LLVM_PASSREGISTRY_H
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"
31 struct PassRegistrationListener
;
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
40 mutable sys::SmartRWMutex
<true> Lock
;
42 /// PassInfoMap - Keep track of the PassInfo object for each registered pass.
43 using MapType
= DenseMap
<const void *, const PassInfo
*>;
46 using StringMapType
= StringMap
<const PassInfo
*>;
47 StringMapType PassInfoStringMap
;
49 std::vector
<std::unique_ptr
<const PassInfo
>> ToFree
;
50 std::vector
<PassRegistrationListener
*> Listeners
;
53 PassRegistry() = default;
56 /// getPassRegistry - Access the global registry object, which is
57 /// automatically initialized at application launch and destroyed by
59 static PassRegistry
*getPassRegistry();
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;
65 /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
67 const PassInfo
*getPassInfo(StringRef Arg
) const;
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);
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);
80 /// enumerateWith - Enumerate the registered passes, calling the provided
81 /// PassRegistrationListener's passEnumerate() callback on each of them.
82 void enumerateWith(PassRegistrationListener
*L
);
84 /// addRegistrationListener - Register the given PassRegistrationListener
85 /// to receive passRegistered() callbacks whenever a new pass is registered.
86 void addRegistrationListener(PassRegistrationListener
*L
);
88 /// removeRegistrationListener - Unregister a PassRegistrationListener so that
89 /// it no longer receives passRegistered() callbacks.
90 void removeRegistrationListener(PassRegistrationListener
*L
);
93 // Create wrappers for C Binding types (see CBindingWrapping.h).
94 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry
, LLVMPassRegistryRef
)
96 } // end namespace llvm
98 #endif // LLVM_PASSREGISTRY_H