blob: 57462138c5aeb86bca7f9abff04e608e31c8ae83 [file] [log] [blame]
Owen Andersond15d2f52010-07-20 18:53:25 +00001//===- 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 Anderson6bcd3a0262010-09-07 19:16:25 +000011// and registration of passes. At application startup, passes are registered
Fangrui Songaf7b1832018-07-30 19:41:25 +000012// with the PassRegistry, which is later provided to the PassManager for
Owen Anderson6bcd3a0262010-09-07 19:16:25 +000013// dependency resolution and similar tasks.
Owen Andersond15d2f52010-07-20 18:53:25 +000014//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_PASSREGISTRY_H
18#define LLVM_PASSREGISTRY_H
19
Zachary Turner070d5322014-06-12 16:06:51 +000020#include "llvm/ADT/DenseMap.h"
Zachary Turner070d5322014-06-12 16:06:51 +000021#include "llvm/ADT/StringMap.h"
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000022#include "llvm/ADT/StringRef.h"
Filip Pizlo40be1e82013-05-01 20:59:00 +000023#include "llvm/Support/CBindingWrapping.h"
Zachary Turner070d5322014-06-12 16:06:51 +000024#include "llvm/Support/RWMutex.h"
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000025#include <memory>
Zachary Turner070d5322014-06-12 16:06:51 +000026#include <vector>
Owen Andersond15d2f52010-07-20 18:53:25 +000027
28namespace llvm {
29
Owen Anderson53967352010-07-20 23:41:56 +000030class PassInfo;
31struct PassRegistrationListener;
32
Owen Anderson6bcd3a0262010-09-07 19:16:25 +000033/// 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 Andersond15d2f52010-07-20 18:53:25 +000039class PassRegistry {
Zachary Turner070d5322014-06-12 16:06:51 +000040 mutable sys::SmartRWMutex<true> Lock;
41
42 /// PassInfoMap - Keep track of the PassInfo object for each registered pass.
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000043 using MapType = DenseMap<const void *, const PassInfo *>;
Zachary Turner070d5322014-06-12 16:06:51 +000044 MapType PassInfoMap;
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000045
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000046 using StringMapType = StringMap<const PassInfo *>;
Zachary Turner070d5322014-06-12 16:06:51 +000047 StringMapType PassInfoStringMap;
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000048
Zachary Turner070d5322014-06-12 16:06:51 +000049 std::vector<std::unique_ptr<const PassInfo>> ToFree;
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000050 std::vector<PassRegistrationListener *> Listeners;
51
Owen Andersond15d2f52010-07-20 18:53:25 +000052public:
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000053 PassRegistry() = default;
Owen Anderson381f17e2010-09-07 20:48:10 +000054 ~PassRegistry();
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000055
56 /// getPassRegistry - Access the global registry object, which is
Owen Andersona4b06f72010-09-07 20:04:26 +000057 /// automatically initialized at application launch and destroyed by
58 /// llvm_shutdown.
Owen Andersonaac07ea2010-07-20 21:22:24 +000059 static PassRegistry *getPassRegistry();
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000060
Owen Andersona4b06f72010-09-07 20:04:26 +000061 /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
62 /// type identifier (&MyPass::ID).
Owen Anderson90c579d2010-08-06 18:33:48 +000063 const PassInfo *getPassInfo(const void *TI) const;
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000064
Owen Andersona4b06f72010-09-07 20:04:26 +000065 /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
66 /// argument string.
Owen Andersond15d2f52010-07-20 18:53:25 +000067 const PassInfo *getPassInfo(StringRef Arg) const;
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000068
69 /// registerPass - Register a pass (by means of its PassInfo) with the
Owen Andersona4b06f72010-09-07 20:04:26 +000070 /// registry. Required in order to use the pass with a PassManager.
Owen Anderson75f6df22010-10-20 22:22:30 +000071 void registerPass(const PassInfo &PI, bool ShouldFree = false);
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000072
Owen Andersona4b06f72010-09-07 20:04:26 +000073 /// registerAnalysisGroup - Register an analysis group (or a pass implementing
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000074 // an analysis group) with the registry. Like registerPass, this is required
Owen Andersona4b06f72010-09-07 20:04:26 +000075 // in order for a PassManager to be able to use this group/pass.
Owen Anderson90c579d2010-08-06 18:33:48 +000076 void registerAnalysisGroup(const void *InterfaceID, const void *PassID,
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000077 PassInfo &Registeree, bool isDefault,
Owen Anderson75f6df22010-10-20 22:22:30 +000078 bool ShouldFree = false);
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000079
Owen Andersona4b06f72010-09-07 20:04:26 +000080 /// enumerateWith - Enumerate the registered passes, calling the provided
81 /// PassRegistrationListener's passEnumerate() callback on each of them.
Owen Andersond15d2f52010-07-20 18:53:25 +000082 void enumerateWith(PassRegistrationListener *L);
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000083
Owen Andersona4b06f72010-09-07 20:04:26 +000084 /// addRegistrationListener - Register the given PassRegistrationListener
85 /// to receive passRegistered() callbacks whenever a new pass is registered.
Chris Lattner223c92c2010-09-05 22:43:56 +000086 void addRegistrationListener(PassRegistrationListener *L);
Chandler Carruthb3d7f9c2014-10-05 23:59:03 +000087
Owen Andersona4b06f72010-09-07 20:04:26 +000088 /// removeRegistrationListener - Unregister a PassRegistrationListener so that
89 /// it no longer receives passRegistered() callbacks.
Owen Anderson53967352010-07-20 23:41:56 +000090 void removeRegistrationListener(PassRegistrationListener *L);
Owen Andersond15d2f52010-07-20 18:53:25 +000091};
92
Filip Pizlo40be1e82013-05-01 20:59:00 +000093// Create wrappers for C Binding types (see CBindingWrapping.h).
94DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef)
95
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000096} // end namespace llvm
Owen Andersond15d2f52010-07-20 18:53:25 +000097
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000098#endif // LLVM_PASSREGISTRY_H