Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Commit

Permalink
Add getPassInfo() function to llvm::Pass
Browse files Browse the repository at this point in the history
PassRegistry::getPass() is quite heavy since it involves taking a lock and
looking up the info in a hashtable.
  • Loading branch information
c-a authored and dotdash committed Jun 20, 2014
1 parent b279154 commit 1bba097
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
11 changes: 10 additions & 1 deletion include/llvm/Pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#ifndef LLVM_PASS_H
#define LLVM_PASS_H

#include "llvm/PassRegistry.h"
#include "llvm/Support/Compiler.h"
#include <string>

Expand Down Expand Up @@ -82,13 +83,14 @@ 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(nullptr), PassID(&pid), Kind(K) { }
: Resolver(nullptr), PassID(&pid), PI(nullptr), Kind(K) { }
virtual ~Pass();


Expand All @@ -105,6 +107,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.
///
Expand Down
21 changes: 8 additions & 13 deletions lib/IR/LegacyPassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,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;
Expand Down Expand Up @@ -723,8 +722,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<const PassInfo*> &ImmPI =
PassInf->getInterfacesImplemented();
Expand Down Expand Up @@ -766,8 +764,7 @@ void PMTopLevelManager::dumpArguments() const {
dbgs() << "Pass Arguments: ";
for (SmallVectorImpl<ImmutablePass *>::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();
Expand Down Expand Up @@ -831,8 +828,8 @@ 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);
if (!PInf) return;
const PassInfo *PInf = P->getPassInfo();
if (PInf == 0) return;
const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
for (unsigned i = 0, e = II.size(); i != e; ++i)
AvailableAnalysis[II[i]->getTypeInfo()] = P;
Expand Down Expand Up @@ -963,10 +960,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.
Expand Down Expand Up @@ -1148,8 +1144,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();
}
Expand Down

0 comments on commit 1bba097

Please sign in to comment.