LLVM API Documentation

PassRegistry.h
Go to the documentation of this file.
00001 //===- llvm/PassRegistry.h - Pass Information Registry ----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines PassRegistry, a class that is used in the initialization
00011 // and registration of passes.  At application startup, passes are registered
00012 // with the PassRegistry, which is later provided to the PassManager for 
00013 // dependency resolution and similar tasks.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_PASSREGISTRY_H
00018 #define LLVM_PASSREGISTRY_H
00019 
00020 #include "llvm-c/Core.h"
00021 #include "llvm/ADT/DenseMap.h"
00022 #include "llvm/ADT/SmallPtrSet.h"
00023 #include "llvm/ADT/StringMap.h"
00024 #include "llvm/ADT/StringRef.h"
00025 #include "llvm/PassInfo.h"
00026 #include "llvm/Support/CBindingWrapping.h"
00027 #include "llvm/Support/RWMutex.h"
00028 #include <vector>
00029 
00030 namespace llvm {
00031 
00032 class PassInfo;
00033 struct PassRegistrationListener;
00034 
00035 /// PassRegistry - This class manages the registration and intitialization of
00036 /// the pass subsystem as application startup, and assists the PassManager
00037 /// in resolving pass dependencies.
00038 /// NOTE: PassRegistry is NOT thread-safe.  If you want to use LLVM on multiple
00039 /// threads simultaneously, you will need to use a separate PassRegistry on
00040 /// each thread.
00041 class PassRegistry {
00042   mutable sys::SmartRWMutex<true> Lock;
00043 
00044   /// PassInfoMap - Keep track of the PassInfo object for each registered pass.
00045   typedef DenseMap<const void*, const PassInfo*> MapType;
00046   MapType PassInfoMap;
00047   
00048   typedef StringMap<const PassInfo*> StringMapType;
00049   StringMapType PassInfoStringMap;
00050   
00051   /// AnalysisGroupInfo - Keep track of information for each analysis group.
00052   struct AnalysisGroupInfo {
00053     SmallPtrSet<const PassInfo *, 8> Implementations;
00054   };
00055   DenseMap<const PassInfo*, AnalysisGroupInfo> AnalysisGroupInfoMap;
00056   
00057   std::vector<std::unique_ptr<const PassInfo>> ToFree;
00058   std::vector<PassRegistrationListener*> Listeners;
00059    
00060 public:
00061   PassRegistry() { }
00062   ~PassRegistry();
00063   
00064   /// getPassRegistry - Access the global registry object, which is 
00065   /// automatically initialized at application launch and destroyed by
00066   /// llvm_shutdown.
00067   static PassRegistry *getPassRegistry();
00068   
00069   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
00070   /// type identifier (&MyPass::ID).
00071   const PassInfo *getPassInfo(const void *TI) const;
00072   
00073   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
00074   /// argument string.
00075   const PassInfo *getPassInfo(StringRef Arg) const;
00076   
00077   /// registerPass - Register a pass (by means of its PassInfo) with the 
00078   /// registry.  Required in order to use the pass with a PassManager.
00079   void registerPass(const PassInfo &PI, bool ShouldFree = false);
00080   
00081   /// registerPass - Unregister a pass (by means of its PassInfo) with the 
00082   /// registry.
00083   void unregisterPass(const PassInfo &PI);
00084   
00085   /// registerAnalysisGroup - Register an analysis group (or a pass implementing
00086   // an analysis group) with the registry.  Like registerPass, this is required 
00087   // in order for a PassManager to be able to use this group/pass.
00088   void registerAnalysisGroup(const void *InterfaceID, const void *PassID,
00089                              PassInfo& Registeree, bool isDefault,
00090                              bool ShouldFree = false);
00091   
00092   /// enumerateWith - Enumerate the registered passes, calling the provided
00093   /// PassRegistrationListener's passEnumerate() callback on each of them.
00094   void enumerateWith(PassRegistrationListener *L);
00095   
00096   /// addRegistrationListener - Register the given PassRegistrationListener
00097   /// to receive passRegistered() callbacks whenever a new pass is registered.
00098   void addRegistrationListener(PassRegistrationListener *L);
00099   
00100   /// removeRegistrationListener - Unregister a PassRegistrationListener so that
00101   /// it no longer receives passRegistered() callbacks.
00102   void removeRegistrationListener(PassRegistrationListener *L);
00103 };
00104 
00105 // Create wrappers for C Binding types (see CBindingWrapping.h).
00106 DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassRegistry, LLVMPassRegistryRef)
00107 
00108 }
00109 
00110 #endif