Owen Anderson | d15d2f5 | 2010-07-20 18:53:25 +0000 | [diff] [blame] | 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 |
Owen Anderson | 6bcd3a026 | 2010-09-07 19:16:25 +0000 | [diff] [blame] | 11 | // and registration of passes. At application startup, passes are registered |
Fangrui Song | af7b183 | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 12 | // with the PassRegistry, which is later provided to the PassManager for |
Owen Anderson | 6bcd3a026 | 2010-09-07 19:16:25 +0000 | [diff] [blame] | 13 | // dependency resolution and similar tasks. |
Owen Anderson | d15d2f5 | 2010-07-20 18:53:25 +0000 | [diff] [blame] | 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #ifndef LLVM_PASSREGISTRY_H |
| 18 | #define LLVM_PASSREGISTRY_H |
| 19 | |
Zachary Turner | 070d532 | 2014-06-12 16:06:51 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/DenseMap.h" |
Zachary Turner | 070d532 | 2014-06-12 16:06:51 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/StringMap.h" |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringRef.h" |
Filip Pizlo | 40be1e8 | 2013-05-01 20:59:00 +0000 | [diff] [blame] | 23 | #include "llvm/Support/CBindingWrapping.h" |
Zachary Turner | 070d532 | 2014-06-12 16:06:51 +0000 | [diff] [blame] | 24 | #include "llvm/Support/RWMutex.h" |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 25 | #include <memory> |
Zachary Turner | 070d532 | 2014-06-12 16:06:51 +0000 | [diff] [blame] | 26 | #include <vector> |
Owen Anderson | d15d2f5 | 2010-07-20 18:53:25 +0000 | [diff] [blame] | 27 | |
| 28 | namespace llvm { |
| 29 | |
Owen Anderson | 5396735 | 2010-07-20 23:41:56 +0000 | [diff] [blame] | 30 | class PassInfo; |
| 31 | struct PassRegistrationListener; |
| 32 | |
Owen Anderson | 6bcd3a026 | 2010-09-07 19:16:25 +0000 | [diff] [blame] | 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 |
| 38 | /// each thread. |
Owen Anderson | d15d2f5 | 2010-07-20 18:53:25 +0000 | [diff] [blame] | 39 | class PassRegistry { |
Zachary Turner | 070d532 | 2014-06-12 16:06:51 +0000 | [diff] [blame] | 40 | mutable sys::SmartRWMutex<true> Lock; |
| 41 | |
| 42 | /// PassInfoMap - Keep track of the PassInfo object for each registered pass. |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 43 | using MapType = DenseMap<const void *, const PassInfo *>; |
Zachary Turner | 070d532 | 2014-06-12 16:06:51 +0000 | [diff] [blame] | 44 | MapType PassInfoMap; |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 45 | |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 46 | using StringMapType = StringMap<const PassInfo *>; |
Zachary Turner | 070d532 | 2014-06-12 16:06:51 +0000 | [diff] [blame] | 47 | StringMapType PassInfoStringMap; |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 48 | |
Zachary Turner | 070d532 | 2014-06-12 16:06:51 +0000 | [diff] [blame] | 49 | std::vector<std::unique_ptr<const PassInfo>> ToFree; |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 50 | std::vector<PassRegistrationListener *> Listeners; |
| 51 | |
Owen Anderson | d15d2f5 | 2010-07-20 18:53:25 +0000 | [diff] [blame] | 52 | public: |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 53 | PassRegistry() = default; |
Owen Anderson | 381f17e | 2010-09-07 20:48:10 +0000 | [diff] [blame] | 54 | ~PassRegistry(); |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 55 | |
| 56 | /// getPassRegistry - Access the global registry object, which is |
Owen Anderson | a4b06f7 | 2010-09-07 20:04:26 +0000 | [diff] [blame] | 57 | /// automatically initialized at application launch and destroyed by |
| 58 | /// llvm_shutdown. |
Owen Anderson | aac07ea | 2010-07-20 21:22:24 +0000 | [diff] [blame] | 59 | static PassRegistry *getPassRegistry(); |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 60 | |
Owen Anderson | a4b06f7 | 2010-09-07 20:04:26 +0000 | [diff] [blame] | 61 | /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass' |
| 62 | /// type identifier (&MyPass::ID). |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 63 | const PassInfo *getPassInfo(const void *TI) const; |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 64 | |
Owen Anderson | a4b06f7 | 2010-09-07 20:04:26 +0000 | [diff] [blame] | 65 | /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass' |
| 66 | /// argument string. |
Owen Anderson | d15d2f5 | 2010-07-20 18:53:25 +0000 | [diff] [blame] | 67 | const PassInfo *getPassInfo(StringRef Arg) const; |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 68 | |
| 69 | /// registerPass - Register a pass (by means of its PassInfo) with the |
Owen Anderson | a4b06f7 | 2010-09-07 20:04:26 +0000 | [diff] [blame] | 70 | /// registry. Required in order to use the pass with a PassManager. |
Owen Anderson | 75f6df2 | 2010-10-20 22:22:30 +0000 | [diff] [blame] | 71 | void registerPass(const PassInfo &PI, bool ShouldFree = false); |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 72 | |
Owen Anderson | a4b06f7 | 2010-09-07 20:04:26 +0000 | [diff] [blame] | 73 | /// registerAnalysisGroup - Register an analysis group (or a pass implementing |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 74 | // an analysis group) with the registry. Like registerPass, this is required |
Owen Anderson | a4b06f7 | 2010-09-07 20:04:26 +0000 | [diff] [blame] | 75 | // in order for a PassManager to be able to use this group/pass. |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 76 | void registerAnalysisGroup(const void *InterfaceID, const void *PassID, |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 77 | PassInfo &Registeree, bool isDefault, |
Owen Anderson | 75f6df2 | 2010-10-20 22:22:30 +0000 | [diff] [blame] | 78 | bool ShouldFree = false); |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 79 | |
Owen Anderson | a4b06f7 | 2010-09-07 20:04:26 +0000 | [diff] [blame] | 80 | /// enumerateWith - Enumerate the registered passes, calling the provided |
| 81 | /// PassRegistrationListener's passEnumerate() callback on each of them. |
Owen Anderson | d15d2f5 | 2010-07-20 18:53:25 +0000 | [diff] [blame] | 82 | void enumerateWith(PassRegistrationListener *L); |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 83 | |
Owen Anderson | a4b06f7 | 2010-09-07 20:04:26 +0000 | [diff] [blame] | 84 | /// addRegistrationListener - Register the given PassRegistrationListener |
| 85 | /// to receive passRegistered() callbacks whenever a new pass is registered. |
Chris Lattner | 223c92c | 2010-09-05 22:43:56 +0000 | [diff] [blame] | 86 | void addRegistrationListener(PassRegistrationListener *L); |
Chandler Carruth | b3d7f9c | 2014-10-05 23:59:03 +0000 | [diff] [blame] | 87 | |
Owen Anderson | a4b06f7 | 2010-09-07 20:04:26 +0000 | [diff] [blame] | 88 | /// removeRegistrationListener - Unregister a PassRegistrationListener so that |
| 89 | /// it no longer receives passRegistered() callbacks. |
Owen Anderson | 5396735 | 2010-07-20 23:41:56 +0000 | [diff] [blame] | 90 | void removeRegistrationListener(PassRegistrationListener *L); |
Owen Anderson | d15d2f5 | 2010-07-20 18:53:25 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Filip Pizlo | 40be1e8 | 2013-05-01 20:59:00 +0000 | [diff] [blame] | 93 | // Create wrappers for C Binding types (see CBindingWrapping.h). |
| 94 | DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef) |
| 95 | |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 96 | } // end namespace llvm |
Owen Anderson | d15d2f5 | 2010-07-20 18:53:25 +0000 | [diff] [blame] | 97 | |
Eugene Zelenko | 9797e4a | 2017-09-06 23:05:38 +0000 | [diff] [blame] | 98 | #endif // LLVM_PASSREGISTRY_H |