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