1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

Revert "[NFC] Derive from PassInfoMixin for no-op/printing passes"

This reverts commit 8039d2c3bf14585ef37dc9343bf393ecad9aead9 as
it breaks the modules build on macOS.
This commit is contained in:
Davide Italiano 2020-07-10 11:16:33 -07:00
parent 9a060a30d3
commit a9d8e1a922
3 changed files with 115 additions and 119 deletions

View File

@ -19,10 +19,17 @@
#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.
@ -64,7 +71,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 : public PassInfoMixin<PrintModulePass> {
class PrintModulePass {
raw_ostream &OS;
std::string Banner;
bool ShouldPreserveUseListOrder;
@ -75,13 +82,15 @@ 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 : public PassInfoMixin<PrintFunctionPass> {
class PrintFunctionPass {
raw_ostream &OS;
std::string Banner;
@ -90,6 +99,8 @@ public:
PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
PreservedAnalyses run(Function &F, AnalysisManager<Function> &);
static StringRef name() { return "PrintFunctionPass"; }
};
} // End llvm namespace

View File

@ -33,6 +33,7 @@
#include <algorithm>
#include <unordered_set>
using namespace llvm;
using namespace llvm::legacy;
// See PassManagers.h for Pass Manager infrastructure overview.
@ -386,66 +387,6 @@ 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
@ -465,7 +406,7 @@ public:
// Delete on the fly managers.
~MPPassManager() override {
for (auto &OnTheFlyManager : OnTheFlyManagers) {
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
delete FPP;
}
}
@ -510,7 +451,7 @@ public:
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
ModulePass *MP = getContainedPass(Index);
MP->dumpPassStructure(Offset + 1);
MapVector<Pass *, legacy::FunctionPassManagerImpl *>::const_iterator I =
MapVector<Pass *, FunctionPassManagerImpl *>::const_iterator I =
OnTheFlyManagers.find(MP);
if (I != OnTheFlyManagers.end())
I->second->dumpPassStructure(Offset + 2);
@ -530,7 +471,7 @@ public:
private:
/// Collection of on the fly FPPassManagers. These managers manage
/// function passes that are required by module passes.
MapVector<Pass *, legacy::FunctionPassManagerImpl *> OnTheFlyManagers;
MapVector<Pass *, FunctionPassManagerImpl *> OnTheFlyManagers;
};
char MPPassManager::ID = 0;
@ -593,33 +534,6 @@ 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
@ -1400,15 +1314,12 @@ 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 legacy::FunctionPassManagerImpl();
FPM = new FunctionPassManagerImpl();
// FPM is the top level manager.
FPM->setTopLevelManager(FPM);
@ -1447,8 +1358,36 @@ bool FunctionPassManager::doInitialization() {
bool FunctionPassManager::doFinalization() {
return FPM->doFinalization(*M);
}
} // namespace legacy
} // namespace llvm
//===----------------------------------------------------------------------===//
// 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;
}
/// cleanup - After running all passes, clean up pass manager cache.
void FPPassManager::cleanup() {
@ -1460,6 +1399,35 @@ 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
@ -1586,7 +1554,7 @@ MPPassManager::runOnModule(Module &M) {
// Initialize on-the-fly passes
for (auto &OnTheFlyManager : OnTheFlyManagers) {
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
Changed |= FPP->doInitialization(M);
}
@ -1647,7 +1615,7 @@ MPPassManager::runOnModule(Module &M) {
// Finalize on-the-fly passes
for (auto &OnTheFlyManager : OnTheFlyManagers) {
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManager.second;
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();
@ -1668,9 +1636,9 @@ void MPPassManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
RequiredPass->getPotentialPassManagerType()) &&
"Unable to handle Pass that requires lower level Analysis pass");
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
FunctionPassManagerImpl *FPP = OnTheFlyManagers[P];
if (!FPP) {
FPP = new legacy::FunctionPassManagerImpl();
FPP = new FunctionPassManagerImpl();
// FPP is the top level manager.
FPP->setTopLevelManager(FPP);
@ -1701,7 +1669,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) {
legacy::FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
FunctionPassManagerImpl *FPP = OnTheFlyManagers[MP];
assert(FPP && "Unable to find on the fly pass");
FPP->releaseMemoryOnTheFly();
@ -1710,8 +1678,32 @@ std::tuple<Pass *, bool> MPPassManager::getOnTheFlyPass(Pass *MP, AnalysisID PI,
Changed);
}
namespace llvm {
namespace legacy {
//===----------------------------------------------------------------------===//
// 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;
}
//===----------------------------------------------------------------------===//
// PassManager implementation
@ -1736,8 +1728,6 @@ void PassManager::add(Pass *P) {
bool PassManager::run(Module &M) {
return PM->run(M);
}
} // namespace legacy
} // namespace llvm
//===----------------------------------------------------------------------===//
// PMStack implementation
@ -1828,4 +1818,4 @@ void FunctionPass::assignPassManager(PMStack &PMS,
PM->add(this);
}
legacy::PassManagerBase::~PassManagerBase() {}
PassManagerBase::~PassManagerBase() {}

View File

@ -295,16 +295,11 @@ 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 : PassInfoMixin<NoOpModulePass> {
struct NoOpModulePass {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &) {
return PreservedAnalyses::all();
}
static StringRef name() { return "NoOpModulePass"; }
};
@ -320,7 +315,7 @@ public:
};
/// No-op CGSCC pass which does nothing.
struct NoOpCGSCCPass : PassInfoMixin<NoOpCGSCCPass> {
struct NoOpCGSCCPass {
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &,
LazyCallGraph &, CGSCCUpdateResult &UR) {
return PreservedAnalyses::all();
@ -342,7 +337,7 @@ public:
};
/// No-op function pass which does nothing.
struct NoOpFunctionPass : PassInfoMixin<NoOpFunctionPass> {
struct NoOpFunctionPass {
PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
return PreservedAnalyses::all();
}
@ -361,7 +356,7 @@ public:
};
/// No-op loop pass which does nothing.
struct NoOpLoopPass : PassInfoMixin<NoOpLoopPass> {
struct NoOpLoopPass {
PreservedAnalyses run(Loop &L, LoopAnalysisManager &,
LoopStandardAnalysisResults &, LPMUpdater &) {
return PreservedAnalyses::all();
@ -387,7 +382,7 @@ AnalysisKey NoOpCGSCCAnalysis::Key;
AnalysisKey NoOpFunctionAnalysis::Key;
AnalysisKey NoOpLoopAnalysis::Key;
} // namespace
} // End anonymous namespace.
void PassBuilder::invokePeepholeEPCallbacks(
FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {