LLVM 22.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
75
78
79 auto I = llvm::find(Listeners, L);
80 Listeners.erase(I);
81}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define I(x, y, z)
Definition MD5.cpp:58
This file contains some templates that are useful if you are working with the STL at all.
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
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVM_ABI void addRegistrationListener(PassRegistrationListener *L)
addRegistrationListener - Register the given PassRegistrationListener to receive passRegistered() cal...
LLVM_ABI void removeRegistrationListener(PassRegistrationListener *L)
removeRegistrationListener - Unregister a PassRegistrationListener so that it no longer receives pass...
LLVM_ABI void registerPass(const PassInfo &PI, bool ShouldFree=false)
registerPass - Register a pass (by means of its PassInfo) with the registry.
LLVM_ABI void enumerateWith(PassRegistrationListener *L)
enumerateWith - Enumerate the registered passes, calling the provided PassRegistrationListener's pass...
LLVM_ABI const PassInfo * getPassInfo(const void *TI) const
getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass' type identifier (&MyPass::...
PassRegistry()=default
LLVM_ABI ~PassRegistry()
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::lock_guard< SmartRWMutex< mt_only > > SmartScopedWriter
ScopedWriter - RAII acquisition of a writer lock.
Definition RWMutex.h:187
const std::shared_lock< SmartRWMutex< mt_only > > SmartScopedReader
ScopedReader - RAII acquisition of a reader lock.
Definition RWMutex.h:170
This is an optimization pass for GlobalISel generic memory operations.
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:1733
PassRegistrationListener class - This class is meant to be derived from by clients that are intereste...