LLVM 20.0.0git
PassRegistry.cpp
Go to the documentation of this file.
1//===- PassRegistry.cpp - Pass Registration Implementation ----------------===//
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 implements the PassRegistry, with which passes are registered on
10// initialization, and supports the PassManager in dependency resolution.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/PassRegistry.h"
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/Pass.h"
17#include "llvm/PassInfo.h"
18#include <cassert>
19#include <memory>
20#include <utility>
21
22using namespace llvm;
23
25 static PassRegistry PassRegistryObj;
26 return &PassRegistryObj;
27}
28
29//===----------------------------------------------------------------------===//
30// Accessors
31//
32
34
35const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
37 return PassInfoMap.lookup(TI);
38}
39
42 return PassInfoStringMap.lookup(Arg);
43}
44
45//===----------------------------------------------------------------------===//
46// Pass Registration mechanism
47//
48
49void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
51 bool Inserted =
52 PassInfoMap.insert(std::make_pair(PI.getTypeInfo(), &PI)).second;
53 assert(Inserted && "Pass registered multiple times!");
54 (void)Inserted;
55 PassInfoStringMap[PI.getPassArgument()] = &PI;
56
57 // Notify any listeners.
58 for (auto *Listener : Listeners)
59 Listener->passRegistered(&PI);
60
61 if (ShouldFree)
62 ToFree.push_back(std::unique_ptr<const PassInfo>(&PI));
63}
64
67 for (auto PassInfoPair : PassInfoMap)
68 L->passEnumerate(PassInfoPair.second);
69}
70
73 Listeners.push_back(L);
74}
75
78
79 auto I = llvm::find(Listeners, L);
80 Listeners.erase(I);
81}
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:194
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:211
PassInfo class - An instance of this class exists for every pass known by the system,...
Definition: PassInfo.h:30
StringRef getPassArgument() const
getPassArgument - Return the command line option that may be passed to 'opt' that will cause this pas...
Definition: PassInfo.h:59
const void * getTypeInfo() const
getTypeInfo - Return the id object for the pass... TODO : Rename
Definition: PassInfo.h:63
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:37
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void addRegistrationListener(PassRegistrationListener *L)
addRegistrationListener - Register the given PassRegistrationListener to receive passRegistered() cal...
void removeRegistrationListener(PassRegistrationListener *L)
removeRegistrationListener - Unregister a PassRegistrationListener so that it no longer receives pass...
void registerPass(const PassInfo &PI, bool ShouldFree=false)
registerPass - Register a pass (by means of its PassInfo) with the registry.
void enumerateWith(PassRegistrationListener *L)
enumerateWith - Enumerate the registered passes, calling the provided PassRegistrationListener's pass...
const PassInfo * getPassInfo(const void *TI) const
getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass' type identifier (&MyPass::...
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: StringMap.h:253
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
const std::shared_lock< SmartRWMutex< mt_only > > SmartScopedReader
ScopedReader - RAII acquisition of a reader lock.
Definition: RWMutex.h:170
std::lock_guard< SmartRWMutex< mt_only > > SmartScopedWriter
ScopedWriter - RAII acquisition of a writer lock.
Definition: RWMutex.h:187
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1742
PassRegistrationListener class - This class is meant to be derived from by clients that are intereste...
Definition: PassSupport.h:124