LCOV - code coverage report
Current view: top level - lib/IR - PassRegistry.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 28 45 62.2 %
Date: 2018-10-20 13:21:21 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    21116106 : PassRegistry *PassRegistry::getPassRegistry() {
      33    21116106 :   return &*PassRegistryObj;
      34             : }
      35             : 
      36             : //===----------------------------------------------------------------------===//
      37             : // Accessors
      38             : //
      39             : 
      40             : PassRegistry::~PassRegistry() = default;
      41             : 
      42    13792823 : const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
      43    13792823 :   sys::SmartScopedReader<true> Guard(Lock);
      44    13792824 :   MapType::const_iterator I = PassInfoMap.find(TI);
      45    13792826 :   return I != PassInfoMap.end() ? I->second : nullptr;
      46             : }
      47             : 
      48        1282 : const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
      49        1282 :   sys::SmartScopedReader<true> Guard(Lock);
      50        1282 :   StringMapType::const_iterator I = PassInfoStringMap.find(Arg);
      51        2564 :   return I != PassInfoStringMap.end() ? I->second : nullptr;
      52             : }
      53             : 
      54             : //===----------------------------------------------------------------------===//
      55             : // Pass Registration mechanism
      56             : //
      57             : 
      58    23959179 : void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
      59    23959179 :   sys::SmartScopedWriter<true> Guard(Lock);
      60             :   bool Inserted =
      61    23959179 :       PassInfoMap.insert(std::make_pair(PI.getTypeInfo(), &PI)).second;
      62             :   assert(Inserted && "Pass registered multiple times!");
      63             :   (void)Inserted;
      64    23959179 :   PassInfoStringMap[PI.getPassArgument()] = &PI;
      65             : 
      66             :   // Notify any listeners.
      67    76694654 :   for (auto *Listener : Listeners)
      68    52735475 :     Listener->passRegistered(&PI);
      69             : 
      70    23959179 :   if (ShouldFree)
      71    47275188 :     ToFree.push_back(std::unique_ptr<const PassInfo>(&PI));
      72    23959179 : }
      73             : 
      74     1102205 : void PassRegistry::enumerateWith(PassRegistrationListener *L) {
      75     1102205 :   sys::SmartScopedReader<true> Guard(Lock);
      76   304628591 :   for (auto PassInfoPair : PassInfoMap)
      77   303526385 :     L->passEnumerate(PassInfoPair.second);
      78     1102206 : }
      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             :     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      238670 : void PassRegistry::addRegistrationListener(PassRegistrationListener *L) {
     120      238670 :   sys::SmartScopedWriter<true> Guard(Lock);
     121      238670 :   Listeners.push_back(L);
     122      238670 : }
     123             : 
     124           0 : void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) {
     125           0 :   sys::SmartScopedWriter<true> Guard(Lock);
     126             : 
     127             :   auto I = llvm::find(Listeners, L);
     128           0 :   Listeners.erase(I);
     129           0 : }

Generated by: LCOV version 1.13