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

Add getPassInfo() function to llvm::Pass #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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();


Expand All @@ -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.
///
Expand Down
19 changes: 7 additions & 12 deletions lib/IR/LegacyPassManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<const PassInfo*> &ImmPI =
PassInf->getInterfacesImplemented();
Expand Down Expand Up @@ -762,8 +760,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 @@ -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<const PassInfo*> &II = PInf->getInterfacesImplemented();
for (unsigned i = 0, e = II.size(); i != e; ++i)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
}
Expand Down