LCOV - code coverage report
Current view: top level - lib/IR - PassRegistry.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 28 47 59.6 %
Date: 2017-09-14 15:23:50 Functions: 6 8 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- PassRegistry.cpp - Pass Registration Implementation ----------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements the PassRegistry, with which passes are registered on
      11             : // initialization, and supports the PassManager in dependency resolution.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #include "llvm/PassRegistry.h"
      16             : #include "llvm/ADT/STLExtras.h"
      17             : #include "llvm/PassInfo.h"
      18             : #include "llvm/PassSupport.h"
      19             : #include "llvm/Support/ManagedStatic.h"
      20             : #include <cassert>
      21             : #include <memory>
      22             : #include <utility>
      23             : 
      24             : using namespace llvm;
      25             : 
      26             : // FIXME: We use ManagedStatic to erase the pass registrar on shutdown.
      27             : // Unfortunately, passes are registered with static ctors, and having
      28             : // llvm_shutdown clear this map prevents successful resurrection after
      29             : // llvm_shutdown is run.  Ideally we should find a solution so that we don't
      30             : // leak the map, AND can still resurrect after shutdown.
      31             : static ManagedStatic<PassRegistry> PassRegistryObj;
      32    10650018 : PassRegistry *PassRegistry::getPassRegistry() {
      33    10650018 :   return &*PassRegistryObj;
      34             : }
      35             : 
      36             : //===----------------------------------------------------------------------===//
      37             : // Accessors
      38             : //
      39             : 
      40             : PassRegistry::~PassRegistry() = default;
      41             : 
      42     6566180 : const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
      43    19698554 :   sys::SmartScopedReader<true> Guard(Lock);
      44     6566188 :   MapType::const_iterator I = PassInfoMap.find(TI);
      45    19698564 :   return I != PassInfoMap.end() ? I->second : nullptr;
      46             : }
      47             : 
      48         604 : const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
      49        1812 :   sys::SmartScopedReader<true> Guard(Lock);
      50         604 :   StringMapType::const_iterator I = PassInfoStringMap.find(Arg);
      51        3016 :   return I != PassInfoStringMap.end() ? I->second : nullptr;
      52             : }
      53             : 
      54             : //===----------------------------------------------------------------------===//
      55             : // Pass Registration mechanism
      56             : //
      57             : 
      58    12140336 : void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
      59    36421008 :   sys::SmartScopedWriter<true> Guard(Lock);
      60             :   bool Inserted =
      61    36421008 :       PassInfoMap.insert(std::make_pair(PI.getTypeInfo(), &PI)).second;
      62             :   assert(Inserted && "Pass registered multiple times!");
      63             :   (void)Inserted;
      64    24280672 :   PassInfoStringMap[PI.getPassArgument()] = &PI;
      65             : 
      66             :   // Notify any listeners.
      67    76242517 :   for (auto *Listener : Listeners)
      68    27681173 :     Listener->passRegistered(&PI);
      69             : 
      70    12140336 :   if (ShouldFree)
      71    47917708 :     ToFree.push_back(std::unique_ptr<const PassInfo>(&PI));
      72    12140336 : }
      73             : 
      74      715210 : void PassRegistry::enumerateWith(PassRegistrationListener *L) {
      75     2145630 :   sys::SmartScopedReader<true> Guard(Lock);
      76   160563840 :   for (auto PassInfoPair : PassInfoMap)
      77   158417462 :     L->passEnumerate(PassInfoPair.second);
      78      715210 : }
      79             : 
      80             : /// Analysis Group Mechanisms.
      81           0 : void PassRegistry::registerAnalysisGroup(const void *InterfaceID,
      82             :                                          const void *PassID,
      83             :                                          PassInfo &Registeree, bool isDefault,
      84             :                                          bool ShouldFree) {
      85           0 :   PassInfo *InterfaceInfo = const_cast<PassInfo *>(getPassInfo(InterfaceID));
      86           0 :   if (!InterfaceInfo) {
      87             :     // First reference to Interface, register it now.
      88           0 :     registerPass(Registeree);
      89           0 :     InterfaceInfo = &Registeree;
      90             :   }
      91             :   assert(Registeree.isAnalysisGroup() &&
      92             :          "Trying to join an analysis group that is a normal pass!");
      93             : 
      94           0 :   if (PassID) {
      95           0 :     PassInfo *ImplementationInfo = const_cast<PassInfo *>(getPassInfo(PassID));
      96             :     assert(ImplementationInfo &&
      97             :            "Must register pass before adding to AnalysisGroup!");
      98             : 
      99           0 :     sys::SmartScopedWriter<true> Guard(Lock);
     100             : 
     101             :     // Make sure we keep track of the fact that the implementation implements
     102             :     // the interface.
     103           0 :     ImplementationInfo->addInterfaceImplemented(InterfaceInfo);
     104             : 
     105           0 :     if (isDefault) {
     106             :       assert(InterfaceInfo->getNormalCtor() == nullptr &&
     107             :              "Default implementation for analysis group already specified!");
     108             :       assert(
     109             :           ImplementationInfo->getNormalCtor() &&
     110             :           "Cannot specify pass as default if it does not have a default ctor");
     111           0 :       InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor());
     112             :     }
     113             :   }
     114             : 
     115           0 :   if (ShouldFree)
     116           0 :     ToFree.push_back(std::unique_ptr<const PassInfo>(&Registeree));
     117           0 : }
     118             : 
     119      153818 : void PassRegistry::addRegistrationListener(PassRegistrationListener *L) {
     120      461454 :   sys::SmartScopedWriter<true> Guard(Lock);
     121      153818 :   Listeners.push_back(L);
     122      153818 : }
     123             : 
     124           0 : void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) {
     125           0 :   sys::SmartScopedWriter<true> Guard(Lock);
     126             : 
     127           0 :   auto I = llvm::find(Listeners, L);
     128           0 :   Listeners.erase(I);
     129           0 : }

Generated by: LCOV version 1.13