2010-07-20 21:23:55 +02:00
|
|
|
//===- PassRegistry.cpp - Pass Registration Implementation ----------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the PassRegistry, with which passes are registered on
|
|
|
|
// initialization, and supports the PassManager in dependency resolution.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/PassRegistry.h"
|
2012-12-03 17:50:05 +01:00
|
|
|
#include "llvm/PassSupport.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2010-07-20 23:22:24 +02:00
|
|
|
|
2010-07-21 01:41:56 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2010-09-07 22:48:10 +02:00
|
|
|
// FIXME: We use ManagedStatic to erase the pass registrar on shutdown.
|
2010-07-20 23:22:24 +02:00
|
|
|
// Unfortunately, passes are registered with static ctors, and having
|
2011-04-15 07:18:47 +02:00
|
|
|
// llvm_shutdown clear this map prevents successful resurrection after
|
2010-07-20 23:22:24 +02:00
|
|
|
// llvm_shutdown is run. Ideally we should find a solution so that we don't
|
|
|
|
// leak the map, AND can still resurrect after shutdown.
|
2010-09-07 22:48:10 +02:00
|
|
|
static ManagedStatic<PassRegistry> PassRegistryObj;
|
|
|
|
PassRegistry *PassRegistry::getPassRegistry() {
|
|
|
|
return &*PassRegistryObj;
|
2010-07-20 23:22:24 +02:00
|
|
|
}
|
2010-07-20 21:23:55 +02:00
|
|
|
|
2010-09-07 21:16:25 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Accessors
|
|
|
|
//
|
|
|
|
|
2014-10-06 01:59:03 +02:00
|
|
|
PassRegistry::~PassRegistry() {}
|
2010-09-07 22:48:10 +02:00
|
|
|
|
2010-08-06 20:33:48 +02:00
|
|
|
const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
|
2015-03-05 18:53:00 +01:00
|
|
|
sys::SmartScopedReader<true> Guard(Lock);
|
2014-06-12 18:06:51 +02:00
|
|
|
MapType::const_iterator I = PassInfoMap.find(TI);
|
|
|
|
return I != PassInfoMap.end() ? I->second : nullptr;
|
2010-07-20 21:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
|
2015-03-05 18:53:00 +01:00
|
|
|
sys::SmartScopedReader<true> Guard(Lock);
|
2014-06-12 18:06:51 +02:00
|
|
|
StringMapType::const_iterator I = PassInfoStringMap.find(Arg);
|
|
|
|
return I != PassInfoStringMap.end() ? I->second : nullptr;
|
2010-07-20 21:23:55 +02:00
|
|
|
}
|
|
|
|
|
2010-07-21 01:41:56 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Pass Registration mechanism
|
|
|
|
//
|
|
|
|
|
2010-10-21 00:22:30 +02:00
|
|
|
void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
|
2014-06-12 18:06:51 +02:00
|
|
|
sys::SmartScopedWriter<true> Guard(Lock);
|
2010-07-20 21:23:55 +02:00
|
|
|
bool Inserted =
|
2014-10-06 01:59:03 +02:00
|
|
|
PassInfoMap.insert(std::make_pair(PI.getTypeInfo(), &PI)).second;
|
2011-01-05 22:50:21 +01:00
|
|
|
assert(Inserted && "Pass registered multiple times!");
|
|
|
|
(void)Inserted;
|
2014-06-12 18:06:51 +02:00
|
|
|
PassInfoStringMap[PI.getPassArgument()] = &PI;
|
2014-10-06 01:59:03 +02:00
|
|
|
|
2010-07-21 01:41:56 +02:00
|
|
|
// Notify any listeners.
|
2014-10-06 02:06:48 +02:00
|
|
|
for (auto *Listener : Listeners)
|
|
|
|
Listener->passRegistered(&PI);
|
2014-10-06 01:59:03 +02:00
|
|
|
|
|
|
|
if (ShouldFree)
|
|
|
|
ToFree.push_back(std::unique_ptr<const PassInfo>(&PI));
|
2010-07-20 21:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PassRegistry::enumerateWith(PassRegistrationListener *L) {
|
2014-06-12 18:06:51 +02:00
|
|
|
sys::SmartScopedReader<true> Guard(Lock);
|
2014-10-06 02:06:48 +02:00
|
|
|
for (auto PassInfoPair : PassInfoMap)
|
|
|
|
L->passEnumerate(PassInfoPair.second);
|
2010-07-20 21:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Analysis Group Mechanisms.
|
2014-10-06 01:59:03 +02:00
|
|
|
void PassRegistry::registerAnalysisGroup(const void *InterfaceID,
|
2010-08-06 20:33:48 +02:00
|
|
|
const void *PassID,
|
2014-10-06 01:59:03 +02:00
|
|
|
PassInfo &Registeree, bool isDefault,
|
2010-10-21 00:22:30 +02:00
|
|
|
bool ShouldFree) {
|
2014-10-06 01:59:03 +02:00
|
|
|
PassInfo *InterfaceInfo = const_cast<PassInfo *>(getPassInfo(InterfaceID));
|
2014-04-09 08:08:46 +02:00
|
|
|
if (!InterfaceInfo) {
|
2010-07-21 19:52:45 +02:00
|
|
|
// First reference to Interface, register it now.
|
|
|
|
registerPass(Registeree);
|
|
|
|
InterfaceInfo = &Registeree;
|
|
|
|
}
|
2014-10-06 01:59:03 +02:00
|
|
|
assert(Registeree.isAnalysisGroup() &&
|
2010-07-21 19:52:45 +02:00
|
|
|
"Trying to join an analysis group that is a normal pass!");
|
|
|
|
|
|
|
|
if (PassID) {
|
2014-10-06 01:59:03 +02:00
|
|
|
PassInfo *ImplementationInfo = const_cast<PassInfo *>(getPassInfo(PassID));
|
2010-07-21 19:52:45 +02:00
|
|
|
assert(ImplementationInfo &&
|
|
|
|
"Must register pass before adding to AnalysisGroup!");
|
|
|
|
|
2014-06-12 18:06:51 +02:00
|
|
|
sys::SmartScopedWriter<true> Guard(Lock);
|
2014-10-06 01:59:03 +02:00
|
|
|
|
2010-07-21 19:52:45 +02:00
|
|
|
// Make sure we keep track of the fact that the implementation implements
|
|
|
|
// the interface.
|
|
|
|
ImplementationInfo->addInterfaceImplemented(InterfaceInfo);
|
|
|
|
|
|
|
|
if (isDefault) {
|
2014-04-15 08:32:26 +02:00
|
|
|
assert(InterfaceInfo->getNormalCtor() == nullptr &&
|
2010-07-21 19:52:45 +02:00
|
|
|
"Default implementation for analysis group already specified!");
|
2014-10-06 01:59:03 +02:00
|
|
|
assert(
|
|
|
|
ImplementationInfo->getNormalCtor() &&
|
|
|
|
"Cannot specify pass as default if it does not have a default ctor");
|
2010-07-21 19:52:45 +02:00
|
|
|
InterfaceInfo->setNormalCtor(ImplementationInfo->getNormalCtor());
|
2014-01-16 22:44:34 +01:00
|
|
|
InterfaceInfo->setTargetMachineCtor(
|
|
|
|
ImplementationInfo->getTargetMachineCtor());
|
2010-07-21 19:52:45 +02:00
|
|
|
}
|
2010-07-20 21:23:55 +02:00
|
|
|
}
|
2014-10-06 01:59:03 +02:00
|
|
|
|
2014-04-15 17:17:14 +02:00
|
|
|
if (ShouldFree)
|
2014-06-12 18:06:51 +02:00
|
|
|
ToFree.push_back(std::unique_ptr<const PassInfo>(&Registeree));
|
2010-07-20 21:23:55 +02:00
|
|
|
}
|
2010-07-21 01:41:56 +02:00
|
|
|
|
|
|
|
void PassRegistry::addRegistrationListener(PassRegistrationListener *L) {
|
2014-06-12 18:06:51 +02:00
|
|
|
sys::SmartScopedWriter<true> Guard(Lock);
|
|
|
|
Listeners.push_back(L);
|
2010-07-21 01:41:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PassRegistry::removeRegistrationListener(PassRegistrationListener *L) {
|
2014-06-12 18:06:51 +02:00
|
|
|
sys::SmartScopedWriter<true> Guard(Lock);
|
2014-10-06 01:59:03 +02:00
|
|
|
|
2014-06-12 18:06:51 +02:00
|
|
|
auto I = std::find(Listeners.begin(), Listeners.end(), L);
|
|
|
|
Listeners.erase(I);
|
2010-07-21 01:41:56 +02:00
|
|
|
}
|