From 511a86acabf1e628a29f1234eb4028556dfdf76b Mon Sep 17 00:00:00 2001 From: Carl-Anton Ingmarsson Date: Tue, 24 Dec 2013 21:49:55 +0100 Subject: [PATCH] Add getPassInfo() function to llvm::Pass PassRegistry::getPass() is quite heavy since it involves taking a lock and looking up the info in a hashtable. --- include/llvm/Pass.h | 11 ++++++++++- lib/IR/LegacyPassManager.cpp | 19 +++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index 35ec022516a5..8c9b1f051337 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -29,6 +29,7 @@ #ifndef LLVM_PASS_H #define LLVM_PASS_H +#include "llvm/PassRegistry.h" #include "llvm/Support/Compiler.h" #include @@ -82,12 +83,13 @@ enum PassKind { class Pass { AnalysisResolver *Resolver; // Used to resolve analysis const void *PassID; + mutable const PassInfo *PI; PassKind Kind; void operator=(const Pass&) LLVM_DELETED_FUNCTION; Pass(const Pass &) LLVM_DELETED_FUNCTION; public: - explicit Pass(PassKind K, char &pid) : Resolver(0), PassID(&pid), Kind(K) { } + explicit Pass(PassKind K, char &pid) : Resolver(0), PassID(&pid), PI(0), Kind(K) { } virtual ~Pass(); @@ -104,6 +106,13 @@ class Pass { return PassID; } + /// getPassInfo - Return the PassInfo associated with this pass. + const PassInfo *getPassInfo() const { + if (!PI) + PI = PassRegistry::getPassRegistry()->getPassInfo(PassID); + return PI; + } + /// doInitialization - Virtual method overridden by subclasses to do /// any necessary initialization before any pass is run. /// diff --git a/lib/IR/LegacyPassManager.cpp b/lib/IR/LegacyPassManager.cpp index dda623764aef..d0110e4cc62e 100644 --- a/lib/IR/LegacyPassManager.cpp +++ b/lib/IR/LegacyPassManager.cpp @@ -603,8 +603,7 @@ void PMTopLevelManager::schedulePass(Pass *P) { // If P is an analysis pass and it is available then do not // generate the analysis again. Stale analysis info should not be // available at this point. - const PassInfo *PI = - PassRegistry::getPassRegistry()->getPassInfo(P->getPassID()); + const PassInfo *PI = P->getPassInfo(); if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) { delete P; return; @@ -719,8 +718,7 @@ Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) { return *I; // If Pass not found then check the interfaces implemented by Immutable Pass - const PassInfo *PassInf = - PassRegistry::getPassRegistry()->getPassInfo(PI); + const PassInfo *PassInf = (*I)->getPassInfo(); assert(PassInf && "Expected all immutable passes to be initialized"); const std::vector &ImmPI = PassInf->getInterfacesImplemented(); @@ -762,8 +760,7 @@ void PMTopLevelManager::dumpArguments() const { dbgs() << "Pass Arguments: "; for (SmallVectorImpl::const_iterator I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I) - if (const PassInfo *PI = - PassRegistry::getPassRegistry()->getPassInfo((*I)->getPassID())) { + if (const PassInfo *PI = (*I)->getPassInfo()) { assert(PI && "Expected all immutable passes to be initialized"); if (!PI->isAnalysisGroup()) dbgs() << " -" << PI->getPassArgument(); @@ -827,7 +824,7 @@ void PMDataManager::recordAvailableAnalysis(Pass *P) { // This pass is the current implementation of all of the interfaces it // implements as well. - const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI); + const PassInfo *PInf = P->getPassInfo(); if (PInf == 0) return; const std::vector &II = PInf->getInterfacesImplemented(); for (unsigned i = 0, e = II.size(); i != e; ++i) @@ -959,10 +956,9 @@ void PMDataManager::freePass(Pass *P, StringRef Msg, P->releaseMemory(); } - AnalysisID PI = P->getPassID(); - if (const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI)) { + if (const PassInfo *PInf = P->getPassInfo()) { // Remove the pass itself (if it is not already removed). - AvailableAnalysis.erase(PI); + AvailableAnalysis.erase(P->getPassID()); // Remove all interfaces this pass implements, for which it is also // listed as the available implementation. @@ -1144,8 +1140,7 @@ void PMDataManager::dumpPassArguments() const { if (PMDataManager *PMD = (*I)->getAsPMDataManager()) PMD->dumpPassArguments(); else - if (const PassInfo *PI = - PassRegistry::getPassRegistry()->getPassInfo((*I)->getPassID())) + if (const PassInfo *PI = (*I)->getPassInfo()) if (!PI->isAnalysisGroup()) dbgs() << " -" << PI->getPassArgument(); }