[cleanup] Fix up trailing whitespace and formatting in the pass regitsry
[oota-llvm.git] / include / llvm / PassRegistry.h
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"
26 #include "llvm/Support/CBindingWrapping.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.
45   typedef DenseMap<const void *, const PassInfo *> MapType;
46   MapType PassInfoMap;
47
48   typedef StringMap<const PassInfo *> StringMapType;
49   StringMapType PassInfoStringMap;
50
51   /// AnalysisGroupInfo - Keep track of information for each analysis group.
52   struct AnalysisGroupInfo {
53     SmallPtrSet<const PassInfo *, 8> Implementations;
54   };
55   DenseMap<const PassInfo *, AnalysisGroupInfo> AnalysisGroupInfoMap;
56
57   std::vector<std::unique_ptr<const PassInfo>> ToFree;
58   std::vector<PassRegistrationListener *> Listeners;
59
60 public:
61   PassRegistry() {}
62   ~PassRegistry();
63
64   /// getPassRegistry - Access the global registry object, which is
65   /// automatically initialized at application launch and destroyed by
66   /// llvm_shutdown.
67   static PassRegistry *getPassRegistry();
68
69   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
70   /// type identifier (&MyPass::ID).
71   const PassInfo *getPassInfo(const void *TI) const;
72
73   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
74   /// argument string.
75   const PassInfo *getPassInfo(StringRef Arg) const;
76
77   /// registerPass - Register a pass (by means of its PassInfo) with the
78   /// registry.  Required in order to use the pass with a PassManager.
79   void registerPass(const PassInfo &PI, bool ShouldFree = false);
80
81   /// registerPass - Unregister a pass (by means of its PassInfo) with the
82   /// registry.
83   void unregisterPass(const PassInfo &PI);
84
85   /// registerAnalysisGroup - Register an analysis group (or a pass implementing
86   // an analysis group) with the registry.  Like registerPass, this is required
87   // in order for a PassManager to be able to use this group/pass.
88   void registerAnalysisGroup(const void *InterfaceID, const void *PassID,
89                              PassInfo &Registeree, bool isDefault,
90                              bool ShouldFree = false);
91
92   /// enumerateWith - Enumerate the registered passes, calling the provided
93   /// PassRegistrationListener's passEnumerate() callback on each of them.
94   void enumerateWith(PassRegistrationListener *L);
95
96   /// addRegistrationListener - Register the given PassRegistrationListener
97   /// to receive passRegistered() callbacks whenever a new pass is registered.
98   void addRegistrationListener(PassRegistrationListener *L);
99
100   /// removeRegistrationListener - Unregister a PassRegistrationListener so that
101   /// it no longer receives passRegistered() callbacks.
102   void removeRegistrationListener(PassRegistrationListener *L);
103 };
104
105 // Create wrappers for C Binding types (see CBindingWrapping.h).
106 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef)
107
108 }
109
110 #endif