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