mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[PM] (NFC) Refactor the CGSCC pass manager tests to use lambda-based
passes. This simplifies the test some and makes it more focused and clear what is being tested. It will also make it much easier to extend with further testing of different pass behaviors. I've also replaced a pointless module pass with running the requires pass directly as that is all that it was really doing. llvm-svn: 280444
This commit is contained in:
parent
e90901530b
commit
d9e2e2c6c3
@ -126,87 +126,27 @@ private:
|
||||
|
||||
char TestImmutableFunctionAnalysis::PassID;
|
||||
|
||||
struct TestModulePass {
|
||||
TestModulePass(int &RunCount) : RunCount(RunCount) {}
|
||||
|
||||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM) {
|
||||
++RunCount;
|
||||
(void)AM.getResult<TestModuleAnalysis>(M);
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
||||
static StringRef name() { return "TestModulePass"; }
|
||||
|
||||
int &RunCount;
|
||||
};
|
||||
|
||||
struct TestSCCPass {
|
||||
TestSCCPass(int &RunCount, int &AnalyzedInstrCount,
|
||||
int &AnalyzedSCCFunctionCount, int &AnalyzedModuleFunctionCount,
|
||||
bool OnlyUseCachedResults = false)
|
||||
: RunCount(RunCount), AnalyzedInstrCount(AnalyzedInstrCount),
|
||||
AnalyzedSCCFunctionCount(AnalyzedSCCFunctionCount),
|
||||
AnalyzedModuleFunctionCount(AnalyzedModuleFunctionCount),
|
||||
OnlyUseCachedResults(OnlyUseCachedResults) {}
|
||||
struct LambdaSCCPass : public PassInfoMixin<LambdaSCCPass> {
|
||||
template <typename T> LambdaSCCPass(T &&Arg) : Func(std::forward<T>(Arg)) {}
|
||||
|
||||
PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM,
|
||||
LazyCallGraph &CG, CGSCCUpdateResult &UR) {
|
||||
++RunCount;
|
||||
|
||||
const ModuleAnalysisManager &MAM =
|
||||
AM.getResult<ModuleAnalysisManagerCGSCCProxy>(C, CG).getManager();
|
||||
FunctionAnalysisManager &FAM =
|
||||
AM.getResult<FunctionAnalysisManagerCGSCCProxy>(C, CG).getManager();
|
||||
if (TestModuleAnalysis::Result *TMA =
|
||||
MAM.getCachedResult<TestModuleAnalysis>(
|
||||
*C.begin()->getFunction().getParent()))
|
||||
AnalyzedModuleFunctionCount += TMA->FunctionCount;
|
||||
|
||||
if (OnlyUseCachedResults) {
|
||||
// Hack to force the use of the cached interface.
|
||||
if (TestSCCAnalysis::Result *AR = AM.getCachedResult<TestSCCAnalysis>(C))
|
||||
AnalyzedSCCFunctionCount += AR->FunctionCount;
|
||||
for (LazyCallGraph::Node &N : C)
|
||||
if (TestFunctionAnalysis::Result *FAR =
|
||||
FAM.getCachedResult<TestFunctionAnalysis>(N.getFunction()))
|
||||
AnalyzedInstrCount += FAR->InstructionCount;
|
||||
} else {
|
||||
// Typical path just runs the analysis as needed.
|
||||
TestSCCAnalysis::Result &AR = AM.getResult<TestSCCAnalysis>(C, CG);
|
||||
AnalyzedSCCFunctionCount += AR.FunctionCount;
|
||||
for (LazyCallGraph::Node &N : C) {
|
||||
TestFunctionAnalysis::Result &FAR =
|
||||
FAM.getResult<TestFunctionAnalysis>(N.getFunction());
|
||||
AnalyzedInstrCount += FAR.InstructionCount;
|
||||
|
||||
// Just ensure we get the immutable results.
|
||||
(void)FAM.getResult<TestImmutableFunctionAnalysis>(N.getFunction());
|
||||
}
|
||||
}
|
||||
|
||||
return PreservedAnalyses::all();
|
||||
return Func(C, AM, CG, UR);
|
||||
}
|
||||
|
||||
static StringRef name() { return "TestSCCPass"; }
|
||||
|
||||
int &RunCount;
|
||||
int &AnalyzedInstrCount;
|
||||
int &AnalyzedSCCFunctionCount;
|
||||
int &AnalyzedModuleFunctionCount;
|
||||
bool OnlyUseCachedResults;
|
||||
std::function<PreservedAnalyses(LazyCallGraph::SCC &, CGSCCAnalysisManager &,
|
||||
LazyCallGraph &, CGSCCUpdateResult &)>
|
||||
Func;
|
||||
};
|
||||
|
||||
struct TestFunctionPass {
|
||||
TestFunctionPass(int &RunCount) : RunCount(RunCount) {}
|
||||
struct LambdaFunctionPass : public PassInfoMixin<LambdaFunctionPass> {
|
||||
template <typename T> LambdaFunctionPass(T &&Arg) : Func(std::forward<T>(Arg)) {}
|
||||
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &) {
|
||||
++RunCount;
|
||||
return PreservedAnalyses::none();
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
|
||||
return Func(F, AM);
|
||||
}
|
||||
|
||||
static StringRef name() { return "TestFunctionPass"; }
|
||||
|
||||
int &RunCount;
|
||||
std::function<PreservedAnalyses(Function &, FunctionAnalysisManager &)> Func;
|
||||
};
|
||||
|
||||
std::unique_ptr<Module> parseIR(const char *IR) {
|
||||
@ -276,28 +216,52 @@ TEST(CGSCCPassManagerTest, Basic) {
|
||||
FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
|
||||
|
||||
ModulePassManager MPM(/*DebugLogging*/ true);
|
||||
int ModulePassRunCount1 = 0;
|
||||
MPM.addPass(TestModulePass(ModulePassRunCount1));
|
||||
MPM.addPass(RequireAnalysisPass<TestModuleAnalysis, Module>());
|
||||
|
||||
CGSCCPassManager CGPM1(/*DebugLogging*/ true);
|
||||
int SCCPassRunCount1 = 0;
|
||||
int AnalyzedInstrCount1 = 0;
|
||||
int AnalyzedSCCFunctionCount1 = 0;
|
||||
int AnalyzedModuleFunctionCount1 = 0;
|
||||
CGPM1.addPass(TestSCCPass(SCCPassRunCount1, AnalyzedInstrCount1,
|
||||
AnalyzedSCCFunctionCount1,
|
||||
AnalyzedModuleFunctionCount1));
|
||||
CGPM1.addPass(
|
||||
LambdaSCCPass([&](LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM,
|
||||
LazyCallGraph &CG, CGSCCUpdateResult &UR) {
|
||||
++SCCPassRunCount1;
|
||||
|
||||
const ModuleAnalysisManager &MAM =
|
||||
AM.getResult<ModuleAnalysisManagerCGSCCProxy>(C, CG).getManager();
|
||||
FunctionAnalysisManager &FAM =
|
||||
AM.getResult<FunctionAnalysisManagerCGSCCProxy>(C, CG).getManager();
|
||||
if (TestModuleAnalysis::Result *TMA =
|
||||
MAM.getCachedResult<TestModuleAnalysis>(
|
||||
*C.begin()->getFunction().getParent()))
|
||||
AnalyzedModuleFunctionCount1 += TMA->FunctionCount;
|
||||
|
||||
TestSCCAnalysis::Result &AR = AM.getResult<TestSCCAnalysis>(C, CG);
|
||||
AnalyzedSCCFunctionCount1 += AR.FunctionCount;
|
||||
for (LazyCallGraph::Node &N : C) {
|
||||
TestFunctionAnalysis::Result &FAR =
|
||||
FAM.getResult<TestFunctionAnalysis>(N.getFunction());
|
||||
AnalyzedInstrCount1 += FAR.InstructionCount;
|
||||
|
||||
// Just ensure we get the immutable results.
|
||||
(void)FAM.getResult<TestImmutableFunctionAnalysis>(N.getFunction());
|
||||
}
|
||||
|
||||
return PreservedAnalyses::all();
|
||||
}));
|
||||
|
||||
FunctionPassManager FPM1(/*DebugLogging*/ true);
|
||||
int FunctionPassRunCount1 = 0;
|
||||
FPM1.addPass(TestFunctionPass(FunctionPassRunCount1));
|
||||
FPM1.addPass(LambdaFunctionPass([&](Function &, FunctionAnalysisManager &) {
|
||||
++FunctionPassRunCount1;
|
||||
return PreservedAnalyses::all();
|
||||
}));
|
||||
CGPM1.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM1)));
|
||||
MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM1)));
|
||||
|
||||
MPM.run(*M, MAM);
|
||||
|
||||
EXPECT_EQ(1, ModulePassRunCount1);
|
||||
|
||||
EXPECT_EQ(1, ModuleAnalysisRuns);
|
||||
EXPECT_EQ(4, SCCAnalysisRuns);
|
||||
EXPECT_EQ(6, FunctionAnalysisRuns);
|
||||
|
Loading…
x
Reference in New Issue
Block a user