1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[NFC] Combine runNewPMPasses() and runNewPMCustomPasses()

I've already witnessed two separate changes missing runNewPMPasses()
because runNewPMCustomPasses() is so similar.

This cleans up some duplicated code.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D96553
This commit is contained in:
Arthur Eubanks 2021-02-11 14:37:29 -08:00
parent 25ee8ece36
commit fe7a083c4c

View File

@ -224,11 +224,6 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
StandardInstrumentations SI(Conf.DebugPassManager);
SI.registerCallbacks(PIC);
PassBuilder PB(Conf.DebugPassManager, TM, Conf.PTO, PGOOpt, &PIC);
AAManager AA;
// Parse a custom AA pipeline if asked to.
if (auto Err = PB.parseAAPipeline(AA, "default"))
report_fatal_error("Error parsing default AA pipeline");
RegisterPassPlugins(Conf.PassPlugins, PB);
@ -243,6 +238,16 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
TLII->disableAllFunctions();
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
AAManager AA;
// Parse a custom AA pipeline if asked to.
if (!Conf.AAPipeline.empty()) {
if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
report_fatal_error("unable to parse AA pipeline description '" +
Conf.AAPipeline + "': " + toString(std::move(Err)));
}
} else {
AA = PB.buildDefaultAAPipeline();
}
// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return std::move(AA); });
@ -277,63 +282,21 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
break;
}
if (IsThinLTO)
MPM.addPass(PB.buildThinLTODefaultPipeline(OL, ImportSummary));
else
MPM.addPass(PB.buildLTODefaultPipeline(OL, ExportSummary));
if (!Conf.DisableVerify)
MPM.addPass(VerifierPass());
MPM.run(Mod, MAM);
}
static void runNewPMCustomPasses(const Config &Conf, Module &Mod,
TargetMachine *TM) {
PassBuilder PB(Conf.DebugPassManager, TM);
AAManager AA;
// Parse a custom AA pipeline if asked to.
if (!Conf.AAPipeline.empty())
if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline))
report_fatal_error("unable to parse AA pipeline description '" +
Conf.AAPipeline + "': " + toString(std::move(Err)));
RegisterPassPlugins(Conf.PassPlugins, PB);
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;
std::unique_ptr<TargetLibraryInfoImpl> TLII(
new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())));
if (Conf.Freestanding)
TLII->disableAllFunctions();
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return std::move(AA); });
// Register all the basic analyses with the managers.
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerFunctionAnalyses(FAM);
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
ModulePassManager MPM;
// Always verify the input.
MPM.addPass(VerifierPass());
// Now, add all the passes we've been requested to.
if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline))
// Parse a custom pipeline if asked to.
if (!Conf.OptPipeline.empty()) {
if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline)) {
report_fatal_error("unable to parse pass pipeline description '" +
Conf.OptPipeline + "': " + toString(std::move(Err)));
}
} else if (IsThinLTO) {
MPM.addPass(PB.buildThinLTODefaultPipeline(OL, ImportSummary));
} else {
MPM.addPass(PB.buildLTODefaultPipeline(OL, ExportSummary));
}
if (!Conf.DisableVerify)
MPM.addPass(VerifierPass());
MPM.run(Mod, MAM);
}
@ -392,13 +355,12 @@ bool lto::opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
/*Cmdline*/ CmdArgs);
}
// FIXME: Plumb the combined index into the new pass manager.
if (!Conf.OptPipeline.empty())
runNewPMCustomPasses(Conf, Mod, TM);
else if (Conf.UseNewPM)
if (Conf.UseNewPM) {
runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO, ExportSummary,
ImportSummary);
else
} else {
runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary);
}
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
}