1//===- llvm/PassRegistry.h - Pass Information Registry ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines PassRegistry, a class that is used in the initialization
10// and registration of passes. At application startup, passes are registered
11// with the PassRegistry, which is later provided to the PassManager for
12// dependency resolution and similar tasks.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_PASSREGISTRY_H
17#define LLVM_PASSREGISTRY_H
18
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/Compiler.h"
23#include "llvm/Support/RWMutex.h"
24#include <memory>
25#include <vector>
26
27namespace llvm {
28
29class PassInfo;
30struct PassRegistrationListener;
31
32/// PassRegistry - This class manages the registration and intitialization of
33/// the pass subsystem as application startup, and assists the PassManager
34/// in resolving pass dependencies.
35/// NOTE: PassRegistry is NOT thread-safe. If you want to use LLVM on multiple
36/// threads simultaneously, you will need to use a separate PassRegistry on
37/// each thread.
38class PassRegistry {
39 mutable sys::SmartRWMutex<true> Lock;
40
41 /// PassInfoMap - Keep track of the PassInfo object for each registered pass.
42 using MapType = DenseMap<const void *, const PassInfo *>;
43 MapType PassInfoMap;
44
45 using StringMapType = StringMap<const PassInfo *>;
46 StringMapType PassInfoStringMap;
47
48 std::vector<std::unique_ptr<const PassInfo>> ToFree;
49 std::vector<PassRegistrationListener *> Listeners;
50
51public:
52 PassRegistry() = default;
53 LLVM_ABI ~PassRegistry();
54
55 /// getPassRegistry - Access the global registry object, which is
56 /// automatically initialized at application launch and destroyed by
57 /// llvm_shutdown.
58 LLVM_ABI static PassRegistry *getPassRegistry();
59
60 /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
61 /// type identifier (&MyPass::ID).
62 LLVM_ABI const PassInfo *getPassInfo(const void *TI) const;
63
64 /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
65 /// argument string.
66 LLVM_ABI const PassInfo *getPassInfo(StringRef Arg) const;
67
68 /// registerPass - Register a pass (by means of its PassInfo) with the
69 /// registry. Required in order to use the pass with a PassManager.
70 LLVM_ABI void registerPass(const PassInfo &PI, bool ShouldFree = false);
71
72 /// enumerateWith - Enumerate the registered passes, calling the provided
73 /// PassRegistrationListener's passEnumerate() callback on each of them.
74 LLVM_ABI void enumerateWith(PassRegistrationListener *L);
75
76 /// addRegistrationListener - Register the given PassRegistrationListener
77 /// to receive passRegistered() callbacks whenever a new pass is registered.
78 LLVM_ABI void addRegistrationListener(PassRegistrationListener *L);
79
80 /// removeRegistrationListener - Unregister a PassRegistrationListener so that
81 /// it no longer receives passRegistered() callbacks.
82 LLVM_ABI void removeRegistrationListener(PassRegistrationListener *L);
83};
84
85} // end namespace llvm
86
87#endif // LLVM_PASSREGISTRY_H
88

source code of llvm/include/llvm/PassRegistry.h