Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:46

0001 //===- llvm/PassRegistry.h - Pass Information Registry ----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines PassRegistry, a class that is used in the initialization
0010 // and registration of passes.  At application startup, passes are registered
0011 // with the PassRegistry, which is later provided to the PassManager for
0012 // dependency resolution and similar tasks.
0013 //
0014 //===----------------------------------------------------------------------===//
0015 
0016 #ifndef LLVM_PASSREGISTRY_H
0017 #define LLVM_PASSREGISTRY_H
0018 
0019 #include "llvm/ADT/DenseMap.h"
0020 #include "llvm/ADT/StringMap.h"
0021 #include "llvm/ADT/StringRef.h"
0022 #include "llvm/Support/RWMutex.h"
0023 #include <memory>
0024 #include <vector>
0025 
0026 namespace llvm {
0027 
0028 class PassInfo;
0029 struct PassRegistrationListener;
0030 
0031 /// PassRegistry - This class manages the registration and intitialization of
0032 /// the pass subsystem as application startup, and assists the PassManager
0033 /// in resolving pass dependencies.
0034 /// NOTE: PassRegistry is NOT thread-safe.  If you want to use LLVM on multiple
0035 /// threads simultaneously, you will need to use a separate PassRegistry on
0036 /// each thread.
0037 class PassRegistry {
0038   mutable sys::SmartRWMutex<true> Lock;
0039 
0040   /// PassInfoMap - Keep track of the PassInfo object for each registered pass.
0041   using MapType = DenseMap<const void *, const PassInfo *>;
0042   MapType PassInfoMap;
0043 
0044   using StringMapType = StringMap<const PassInfo *>;
0045   StringMapType PassInfoStringMap;
0046 
0047   std::vector<std::unique_ptr<const PassInfo>> ToFree;
0048   std::vector<PassRegistrationListener *> Listeners;
0049 
0050 public:
0051   PassRegistry() = default;
0052   ~PassRegistry();
0053 
0054   /// getPassRegistry - Access the global registry object, which is
0055   /// automatically initialized at application launch and destroyed by
0056   /// llvm_shutdown.
0057   static PassRegistry *getPassRegistry();
0058 
0059   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
0060   /// type identifier (&MyPass::ID).
0061   const PassInfo *getPassInfo(const void *TI) const;
0062 
0063   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
0064   /// argument string.
0065   const PassInfo *getPassInfo(StringRef Arg) const;
0066 
0067   /// registerPass - Register a pass (by means of its PassInfo) with the
0068   /// registry.  Required in order to use the pass with a PassManager.
0069   void registerPass(const PassInfo &PI, bool ShouldFree = false);
0070 
0071   /// enumerateWith - Enumerate the registered passes, calling the provided
0072   /// PassRegistrationListener's passEnumerate() callback on each of them.
0073   void enumerateWith(PassRegistrationListener *L);
0074 
0075   /// addRegistrationListener - Register the given PassRegistrationListener
0076   /// to receive passRegistered() callbacks whenever a new pass is registered.
0077   void addRegistrationListener(PassRegistrationListener *L);
0078 
0079   /// removeRegistrationListener - Unregister a PassRegistrationListener so that
0080   /// it no longer receives passRegistered() callbacks.
0081   void removeRegistrationListener(PassRegistrationListener *L);
0082 };
0083 
0084 } // end namespace llvm
0085 
0086 #endif // LLVM_PASSREGISTRY_H