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

Commit ed0d140

Browse files
c-aalexcrichton
authored andcommitted
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.
1 parent c80cb2e commit ed0d140

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

include/llvm/Pass.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#ifndef LLVM_PASS_H
3030
#define LLVM_PASS_H
3131

32+
#include "llvm/PassRegistry.h"
3233
#include "llvm/Support/Compiler.h"
3334
#include <string>
3435

@@ -82,12 +83,13 @@ enum PassKind {
8283
class Pass {
8384
AnalysisResolver *Resolver; // Used to resolve analysis
8485
const void *PassID;
86+
mutable const PassInfo *PI;
8587
PassKind Kind;
8688
void operator=(const Pass&) LLVM_DELETED_FUNCTION;
8789
Pass(const Pass &) LLVM_DELETED_FUNCTION;
8890

8991
public:
90-
explicit Pass(PassKind K, char &pid) : Resolver(0), PassID(&pid), Kind(K) { }
92+
explicit Pass(PassKind K, char &pid) : Resolver(0), PassID(&pid), PI(0), Kind(K) { }
9193
virtual ~Pass();
9294

9395

@@ -104,6 +106,13 @@ class Pass {
104106
return PassID;
105107
}
106108

109+
/// getPassInfo - Return the PassInfo associated with this pass.
110+
const PassInfo *getPassInfo() const {
111+
if (!PI)
112+
PI = PassRegistry::getPassRegistry()->getPassInfo(PassID);
113+
return PI;
114+
}
115+
107116
/// doInitialization - Virtual method overridden by subclasses to do
108117
/// any necessary initialization before any pass is run.
109118
///

lib/IR/LegacyPassManager.cpp

+7-12
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,7 @@ void PMTopLevelManager::schedulePass(Pass *P) {
602602
// If P is an analysis pass and it is available then do not
603603
// generate the analysis again. Stale analysis info should not be
604604
// available at this point.
605-
const PassInfo *PI =
606-
PassRegistry::getPassRegistry()->getPassInfo(P->getPassID());
605+
const PassInfo *PI = P->getPassInfo();
607606
if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) {
608607
delete P;
609608
return;
@@ -718,8 +717,7 @@ Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
718717
return *I;
719718

720719
// If Pass not found then check the interfaces implemented by Immutable Pass
721-
const PassInfo *PassInf =
722-
PassRegistry::getPassRegistry()->getPassInfo(PI);
720+
const PassInfo *PassInf = (*I)->getPassInfo();
723721
assert(PassInf && "Expected all immutable passes to be initialized");
724722
const std::vector<const PassInfo*> &ImmPI =
725723
PassInf->getInterfacesImplemented();
@@ -761,8 +759,7 @@ void PMTopLevelManager::dumpArguments() const {
761759
dbgs() << "Pass Arguments: ";
762760
for (SmallVectorImpl<ImmutablePass *>::const_iterator I =
763761
ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
764-
if (const PassInfo *PI =
765-
PassRegistry::getPassRegistry()->getPassInfo((*I)->getPassID())) {
762+
if (const PassInfo *PI = (*I)->getPassInfo()) {
766763
assert(PI && "Expected all immutable passes to be initialized");
767764
if (!PI->isAnalysisGroup())
768765
dbgs() << " -" << PI->getPassArgument();
@@ -826,7 +823,7 @@ void PMDataManager::recordAvailableAnalysis(Pass *P) {
826823

827824
// This pass is the current implementation of all of the interfaces it
828825
// implements as well.
829-
const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI);
826+
const PassInfo *PInf = P->getPassInfo();
830827
if (PInf == 0) return;
831828
const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
832829
for (unsigned i = 0, e = II.size(); i != e; ++i)
@@ -958,10 +955,9 @@ void PMDataManager::freePass(Pass *P, StringRef Msg,
958955
P->releaseMemory();
959956
}
960957

961-
AnalysisID PI = P->getPassID();
962-
if (const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI)) {
958+
if (const PassInfo *PInf = P->getPassInfo()) {
963959
// Remove the pass itself (if it is not already removed).
964-
AvailableAnalysis.erase(PI);
960+
AvailableAnalysis.erase(P->getPassID());
965961

966962
// Remove all interfaces this pass implements, for which it is also
967963
// listed as the available implementation.
@@ -1143,8 +1139,7 @@ void PMDataManager::dumpPassArguments() const {
11431139
if (PMDataManager *PMD = (*I)->getAsPMDataManager())
11441140
PMD->dumpPassArguments();
11451141
else
1146-
if (const PassInfo *PI =
1147-
PassRegistry::getPassRegistry()->getPassInfo((*I)->getPassID()))
1142+
if (const PassInfo *PI = (*I)->getPassInfo())
11481143
if (!PI->isAnalysisGroup())
11491144
dbgs() << " -" << PI->getPassArgument();
11501145
}

0 commit comments

Comments
 (0)