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

Commit 1bba097

Browse files
c-adotdash
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 b279154 commit 1bba097

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
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,13 +83,14 @@ 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:
9092
explicit Pass(PassKind K, char &pid)
91-
: Resolver(nullptr), PassID(&pid), Kind(K) { }
93+
: Resolver(nullptr), PassID(&pid), PI(nullptr), Kind(K) { }
9294
virtual ~Pass();
9395

9496

@@ -105,6 +107,13 @@ class Pass {
105107
return PassID;
106108
}
107109

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

lib/IR/LegacyPassManager.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,7 @@ void PMTopLevelManager::schedulePass(Pass *P) {
607607
// If P is an analysis pass and it is available then do not
608608
// generate the analysis again. Stale analysis info should not be
609609
// available at this point.
610-
const PassInfo *PI =
611-
PassRegistry::getPassRegistry()->getPassInfo(P->getPassID());
610+
const PassInfo *PI = P->getPassInfo();
612611
if (PI && PI->isAnalysis() && findAnalysisPass(P->getPassID())) {
613612
delete P;
614613
return;
@@ -723,8 +722,7 @@ Pass *PMTopLevelManager::findAnalysisPass(AnalysisID AID) {
723722
return *I;
724723

725724
// If Pass not found then check the interfaces implemented by Immutable Pass
726-
const PassInfo *PassInf =
727-
PassRegistry::getPassRegistry()->getPassInfo(PI);
725+
const PassInfo *PassInf = (*I)->getPassInfo();
728726
assert(PassInf && "Expected all immutable passes to be initialized");
729727
const std::vector<const PassInfo*> &ImmPI =
730728
PassInf->getInterfacesImplemented();
@@ -766,8 +764,7 @@ void PMTopLevelManager::dumpArguments() const {
766764
dbgs() << "Pass Arguments: ";
767765
for (SmallVectorImpl<ImmutablePass *>::const_iterator I =
768766
ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
769-
if (const PassInfo *PI =
770-
PassRegistry::getPassRegistry()->getPassInfo((*I)->getPassID())) {
767+
if (const PassInfo *PI = (*I)->getPassInfo()) {
771768
assert(PI && "Expected all immutable passes to be initialized");
772769
if (!PI->isAnalysisGroup())
773770
dbgs() << " -" << PI->getPassArgument();
@@ -831,8 +828,8 @@ void PMDataManager::recordAvailableAnalysis(Pass *P) {
831828

832829
// This pass is the current implementation of all of the interfaces it
833830
// implements as well.
834-
const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI);
835-
if (!PInf) return;
831+
const PassInfo *PInf = P->getPassInfo();
832+
if (PInf == 0) return;
836833
const std::vector<const PassInfo*> &II = PInf->getInterfacesImplemented();
837834
for (unsigned i = 0, e = II.size(); i != e; ++i)
838835
AvailableAnalysis[II[i]->getTypeInfo()] = P;
@@ -963,10 +960,9 @@ void PMDataManager::freePass(Pass *P, StringRef Msg,
963960
P->releaseMemory();
964961
}
965962

966-
AnalysisID PI = P->getPassID();
967-
if (const PassInfo *PInf = PassRegistry::getPassRegistry()->getPassInfo(PI)) {
963+
if (const PassInfo *PInf = P->getPassInfo()) {
968964
// Remove the pass itself (if it is not already removed).
969-
AvailableAnalysis.erase(PI);
965+
AvailableAnalysis.erase(P->getPassID());
970966

971967
// Remove all interfaces this pass implements, for which it is also
972968
// listed as the available implementation.
@@ -1148,8 +1144,7 @@ void PMDataManager::dumpPassArguments() const {
11481144
if (PMDataManager *PMD = (*I)->getAsPMDataManager())
11491145
PMD->dumpPassArguments();
11501146
else
1151-
if (const PassInfo *PI =
1152-
PassRegistry::getPassRegistry()->getPassInfo((*I)->getPassID()))
1147+
if (const PassInfo *PI = (*I)->getPassInfo())
11531148
if (!PI->isAnalysisGroup())
11541149
dbgs() << " -" << PI->getPassArgument();
11551150
}

0 commit comments

Comments
 (0)