forked from OSchip/llvm-project
[NFC] Derive from PassInfoMixin for no-op/printing passes
PassInfoMixin should be used for all NPM passes, rater than a custom `name()`. This caused ambiguous references in LegacyPassManager.cpp, so had to remove "using namespace llvm::legacy" and move some things around. The passes had to be moved to the llvm namespace, or else they would get printed as "(anonymous namespace)::FooPass". Reviewed By: ychen, asbirlea Differential Revision: https://reviews.llvm.org/D83498
This commit is contained in:
parent
e296e9dfd6
commit
8039d2c3bf
|
@ -19,17 +19,10 @@
|
|||
#define LLVM_IR_IRPRINTINGPASSES_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include <string>
|
||||
|
||||
namespace llvm {
|
||||
class Pass;
|
||||
class Function;
|
||||
class FunctionPass;
|
||||
class Module;
|
||||
class ModulePass;
|
||||
class PreservedAnalyses;
|
||||
class raw_ostream;
|
||||
template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
|
||||
|
||||
/// Create and return a pass that writes the module to the specified
|
||||
/// \c raw_ostream.
|
||||
|
@ -71,7 +64,7 @@ extern bool shouldPrintAfterPass(StringRef);
|
|||
///
|
||||
/// Note: This pass is for use with the new pass manager. Use the create...Pass
|
||||
/// functions above to create passes for use with the legacy pass manager.
|
||||
class PrintModulePass {
|
||||
class PrintModulePass : public PassInfoMixin<PrintModulePass> {
|
||||
raw_ostream &OS;
|
||||
std::string Banner;
|
||||
bool ShouldPreserveUseListOrder;
|
||||
|
@ -82,15 +75,13 @@ public:
|
|||
bool ShouldPreserveUseListOrder = false);
|
||||
|
||||
PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
|
||||
|
||||
static StringRef name() { return "PrintModulePass"; }
|
||||
};
|
||||
|
||||
/// Pass for printing a Function as LLVM's text IR assembly.
|
||||
///
|
||||
/// Note: This pass is for use with the new pass manager. Use the create...Pass
|
||||
/// functions above to create passes for use with the legacy pass manager.
|
||||
class PrintFunctionPass {
|
||||
class PrintFunctionPass : public PassInfoMixin<PrintFunctionPass> {
|
||||
raw_ostream &OS;
|
||||
std::string Banner;
|
||||
|
||||
|
@ -99,8 +90,6 @@ public:
|
|||
PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
|
||||
|
||||
PreservedAnalyses run(Function &F, AnalysisManager<Function> &);
|
||||
|
||||
static StringRef name() { return "PrintFunctionPass"; }
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <algorithm>
|
||||
#include <unordered_set>
|
||||
using namespace llvm;
|
||||
using namespace llvm::legacy;
|
||||
|
||||
// See PassManagers.h for Pass Manager infrastructure overview.
|
||||
|
||||
|
@ -387,6 +386,66 @@ public:
|
|||
void FunctionPassManagerImpl::anchor() {}
|
||||
|
||||
char FunctionPassManagerImpl::ID = 0;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// FunctionPassManagerImpl implementation
|
||||
//
|
||||
bool FunctionPassManagerImpl::doInitialization(Module &M) {
|
||||
bool Changed = false;
|
||||
|
||||
dumpArguments();
|
||||
dumpPasses();
|
||||
|
||||
for (ImmutablePass *ImPass : getImmutablePasses())
|
||||
Changed |= ImPass->doInitialization(M);
|
||||
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
||||
Changed |= getContainedManager(Index)->doInitialization(M);
|
||||
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool FunctionPassManagerImpl::doFinalization(Module &M) {
|
||||
bool Changed = false;
|
||||
|
||||
for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index)
|
||||
Changed |= getContainedManager(Index)->doFinalization(M);
|
||||
|
||||
for (ImmutablePass *ImPass : getImmutablePasses())
|
||||
Changed |= ImPass->doFinalization(M);
|
||||
|
||||
return Changed;
|
||||
}
|
||||
|
||||
void FunctionPassManagerImpl::releaseMemoryOnTheFly() {
|
||||
if (!wasRun)
|
||||
return;
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
|
||||
FPPassManager *FPPM = getContainedManager(Index);
|
||||
for (unsigned Index = 0; Index < FPPM->getNumContainedPasses(); ++Index) {
|
||||
FPPM->getContainedPass(Index)->releaseMemory();
|
||||
}
|
||||
}
|
||||
wasRun = false;
|
||||
}
|
||||
|
||||
// Execute all the passes managed by this top level manager.
|
||||
// Return true if any function is modified by a pass.
|
||||
bool FunctionPassManagerImpl::run(Function &F) {
|
||||
bool Changed = false;
|
||||
|
||||
initializeAllAnalysisInfo();
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
|
||||
Changed |= getContainedManager(Index)->runOnFunction(F);
|
||||
F.getContext().yield();
|
||||
}
|
||||
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
||||
getContainedManager(Index)->cleanup();
|
||||
|
||||
wasRun = true;
|
||||
return Changed;
|
||||
}
|
||||
} // namespace legacy
|
||||
} // namespace llvm
|
||||
|
||||
|
@ -406,7 +465,7 @@ public:
|
|||
// Delete on the fly managers.
|
||||
~MPPassManager() override {
|
||||
for (auto &OnTheFlyManager : OnTheFlyManagers) {
|
||||
FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
|
||||
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
|
||||
delete FPP;
|
||||
}
|
||||
}
|
||||
|
@ -451,7 +510,7 @@ public:
|
|||
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
|
||||
ModulePass *MP = getContainedPass(Index);
|
||||
MP->dumpPassStructure(Offset + 1);
|
||||
MapVector<Pass *, FunctionPassManagerImpl *>::const_iterator I =
|
||||
MapVector<Pass *, legacy::FunctionPassManagerImpl *>::const_iterator I =
|
||||
OnTheFlyManagers.find(MP);
|
||||
if (I != OnTheFlyManagers.end())
|
||||
I->second->dumpPassStructure(Offset + 2);
|
||||
|
@ -471,7 +530,7 @@ public:
|
|||
private:
|
||||
/// Collection of on the fly FPPassManagers. These managers manage
|
||||
/// function passes that are required by module passes.
|
||||
MapVector<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
|
||||
MapVector<Pass *, legacy::FunctionPassManagerImpl *> OnTheFlyManagers;
|
||||
};
|
||||
|
||||
char MPPassManager::ID = 0;
|
||||
|
@ -534,6 +593,33 @@ public:
|
|||
void PassManagerImpl::anchor() {}
|
||||
|
||||
char PassManagerImpl::ID = 0;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// PassManagerImpl implementation
|
||||
|
||||
//
|
||||
/// run - Execute all of the passes scheduled for execution. Keep track of
|
||||
/// whether any of the passes modifies the module, and if so, return true.
|
||||
bool PassManagerImpl::run(Module &M) {
|
||||
bool Changed = false;
|
||||
|
||||
dumpArguments();
|
||||
dumpPasses();
|
||||
|
||||
for (ImmutablePass *ImPass : getImmutablePasses())
|
||||
Changed |= ImPass->doInitialization(M);
|
||||
|
||||
initializeAllAnalysisInfo();
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
|
||||
Changed |= getContainedManager(Index)->runOnModule(M);
|
||||
M.getContext().yield();
|
||||
}
|
||||
|
||||
for (ImmutablePass *ImPass : getImmutablePasses())
|
||||
Changed |= ImPass->doFinalization(M);
|
||||
|
||||
return Changed;
|
||||
}
|
||||
} // namespace legacy
|
||||
} // namespace llvm
|
||||
|
||||
|
@ -1314,12 +1400,15 @@ AnalysisResolver::findImplPass(Pass *P, AnalysisID AnalysisPI, Function &F) {
|
|||
return PM.getOnTheFlyPass(P, AnalysisPI, F);
|
||||
}
|
||||
|
||||
namespace llvm {
|
||||
namespace legacy {
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// FunctionPassManager implementation
|
||||
|
||||
/// Create new Function pass manager
|
||||
FunctionPassManager::FunctionPassManager(Module *m) : M(m) {
|
||||
FPM = new FunctionPassManagerImpl();
|
||||
FPM = new legacy::FunctionPassManagerImpl();
|
||||
// FPM is the top level manager.
|
||||
FPM->setTopLevelManager(FPM);
|
||||
|
||||
|
@ -1358,36 +1447,8 @@ bool FunctionPassManager::doInitialization() {
|
|||
bool FunctionPassManager::doFinalization() {
|
||||
return FPM->doFinalization(*M);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// FunctionPassManagerImpl implementation
|
||||
//
|
||||
bool FunctionPassManagerImpl::doInitialization(Module &M) {
|
||||
bool Changed = false;
|
||||
|
||||
dumpArguments();
|
||||
dumpPasses();
|
||||
|
||||
for (ImmutablePass *ImPass : getImmutablePasses())
|
||||
Changed |= ImPass->doInitialization(M);
|
||||
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
||||
Changed |= getContainedManager(Index)->doInitialization(M);
|
||||
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool FunctionPassManagerImpl::doFinalization(Module &M) {
|
||||
bool Changed = false;
|
||||
|
||||
for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index)
|
||||
Changed |= getContainedManager(Index)->doFinalization(M);
|
||||
|
||||
for (ImmutablePass *ImPass : getImmutablePasses())
|
||||
Changed |= ImPass->doFinalization(M);
|
||||
|
||||
return Changed;
|
||||
}
|
||||
} // namespace legacy
|
||||
} // namespace llvm
|
||||
|
||||
/// cleanup - After running all passes, clean up pass manager cache.
|
||||
void FPPassManager::cleanup() {
|
||||
|
@ -1399,35 +1460,6 @@ void FPPassManager::cleanup() {
|
|||
}
|
||||
}
|
||||
|
||||
void FunctionPassManagerImpl::releaseMemoryOnTheFly() {
|
||||
if (!wasRun)
|
||||
return;
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
|
||||
FPPassManager *FPPM = getContainedManager(Index);
|
||||
for (unsigned Index = 0; Index < FPPM->getNumContainedPasses(); ++Index) {
|
||||
FPPM->getContainedPass(Index)->releaseMemory();
|
||||
}
|
||||
}
|
||||
wasRun = false;
|
||||
}
|
||||
|
||||
// Execute all the passes managed by this top level manager.
|
||||
// Return true if any function is modified by a pass.
|
||||
bool FunctionPassManagerImpl::run(Function &F) {
|
||||
bool Changed = false;
|
||||
|
||||
initializeAllAnalysisInfo();
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
|
||||
Changed |= getContainedManager(Index)->runOnFunction(F);
|
||||
F.getContext().yield();
|
||||
}
|
||||
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index)
|
||||
getContainedManager(Index)->cleanup();
|
||||
|
||||
wasRun = true;
|
||||
return Changed;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// FPPassManager implementation
|
||||
|
@ -1554,7 +1586,7 @@ MPPassManager::runOnModule(Module &M) {
|
|||
|
||||
// Initialize on-the-fly passes
|
||||
for (auto &OnTheFlyManager : OnTheFlyManagers) {
|
||||
FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
|
||||
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
|
||||
Changed |= FPP->doInitialization(M);
|
||||
}
|
||||
|
||||
|
@ -1615,7 +1647,7 @@ MPPassManager::runOnModule(Module &M) {
|
|||
|
||||
// Finalize on-the-fly passes
|
||||
for (auto &OnTheFlyManager : OnTheFlyManagers) {
|
||||
FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
|
||||
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
|
||||
// We don't know when is the last time an on-the-fly pass is run,
|
||||
// so we need to releaseMemory / finalize here
|
||||
FPP->releaseMemoryOnTheFly();
|
||||
|
@ -1636,9 +1668,9 @@ void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
|
|||
RequiredPass->getPotentialPassManagerType()) &&
|
||||
"Unable to handle Pass that requires lower level Analysis pass");
|
||||
|
||||
FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
|
||||
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
|
||||
if (!FPP) {
|
||||
FPP = new FunctionPassManagerImpl();
|
||||
FPP = new legacy::FunctionPassManagerImpl();
|
||||
// FPP is the top level manager.
|
||||
FPP->setTopLevelManager(FPP);
|
||||
|
||||
|
@ -1669,7 +1701,7 @@ void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
|
|||
/// its runOnFunction() for function F.
|
||||
std::tuple<Pass *, bool> MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI,
|
||||
Function &F) {
|
||||
FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
|
||||
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
|
||||
assert(FPP && "Unable to find on the fly pass");
|
||||
|
||||
FPP->releaseMemoryOnTheFly();
|
||||
|
@ -1678,32 +1710,8 @@ std::tuple<Pass *, bool> MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI,
|
|||
Changed);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// PassManagerImpl implementation
|
||||
|
||||
//
|
||||
/// run - Execute all of the passes scheduled for execution. Keep track of
|
||||
/// whether any of the passes modifies the module, and if so, return true.
|
||||
bool PassManagerImpl::run(Module &M) {
|
||||
bool Changed = false;
|
||||
|
||||
dumpArguments();
|
||||
dumpPasses();
|
||||
|
||||
for (ImmutablePass *ImPass : getImmutablePasses())
|
||||
Changed |= ImPass->doInitialization(M);
|
||||
|
||||
initializeAllAnalysisInfo();
|
||||
for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) {
|
||||
Changed |= getContainedManager(Index)->runOnModule(M);
|
||||
M.getContext().yield();
|
||||
}
|
||||
|
||||
for (ImmutablePass *ImPass : getImmutablePasses())
|
||||
Changed |= ImPass->doFinalization(M);
|
||||
|
||||
return Changed;
|
||||
}
|
||||
namespace llvm {
|
||||
namespace legacy {
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// PassManager implementation
|
||||
|
@ -1728,6 +1736,8 @@ void PassManager::add(Pass *P) {
|
|||
bool PassManager::run(Module &M) {
|
||||
return PM->run(M);
|
||||
}
|
||||
} // namespace legacy
|
||||
} // namespace llvm
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// PMStack implementation
|
||||
|
@ -1818,4 +1828,4 @@ void FunctionPass::assignPassManager(PMStack &PMS,
|
|||
PM->add(this);
|
||||
}
|
||||
|
||||
PassManagerBase::~PassManagerBase() {}
|
||||
legacy::PassManagerBase::~PassManagerBase() {}
|
||||
|
|
|
@ -299,11 +299,16 @@ const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::Oz = {
|
|||
|
||||
namespace {
|
||||
|
||||
// The following passes/analyses have custom names, otherwise their name will
|
||||
// include `(anonymous namespace)`. These are special since they are only for
|
||||
// testing purposes and don't live in a header file.
|
||||
|
||||
/// No-op module pass which does nothing.
|
||||
struct NoOpModulePass {
|
||||
struct NoOpModulePass : PassInfoMixin<NoOpModulePass> {
|
||||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
||||
static StringRef name() { return "NoOpModulePass"; }
|
||||
};
|
||||
|
||||
|
@ -319,7 +324,7 @@ public:
|
|||
};
|
||||
|
||||
/// No-op CGSCC pass which does nothing.
|
||||
struct NoOpCGSCCPass {
|
||||
struct NoOpCGSCCPass : PassInfoMixin<NoOpCGSCCPass> {
|
||||
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
|
||||
LazyCallGraph &, CGSCCUpdateResult &UR) {
|
||||
return PreservedAnalyses::all();
|
||||
|
@ -341,7 +346,7 @@ public:
|
|||
};
|
||||
|
||||
/// No-op function pass which does nothing.
|
||||
struct NoOpFunctionPass {
|
||||
struct NoOpFunctionPass : PassInfoMixin<NoOpFunctionPass> {
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
@ -360,7 +365,7 @@ public:
|
|||
};
|
||||
|
||||
/// No-op loop pass which does nothing.
|
||||
struct NoOpLoopPass {
|
||||
struct NoOpLoopPass : PassInfoMixin<NoOpLoopPass> {
|
||||
PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
|
||||
LoopStandardAnalysisResults &, LPMUpdater &) {
|
||||
return PreservedAnalyses::all();
|
||||
|
@ -386,7 +391,7 @@ AnalysisKey NoOpCGSCCAnalysis::Key;
|
|||
AnalysisKey NoOpFunctionAnalysis::Key;
|
||||
AnalysisKey NoOpLoopAnalysis::Key;
|
||||
|
||||
} // End anonymous namespace.
|
||||
} // namespace
|
||||
|
||||
void PassBuilder::invokePeepholeEPCallbacks(
|
||||
FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
|
||||
|
|
Loading…
Reference in New Issue