Skip to content

Commit 964f810

Browse files
committed
[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
1 parent 2dbe88d commit 964f810

File tree

1 file changed

+22
-60
lines changed

1 file changed

+22
-60
lines changed

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,6 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
224224
StandardInstrumentations SI(Conf.DebugPassManager);
225225
SI.registerCallbacks(PIC);
226226
PassBuilder PB(Conf.DebugPassManager, TM, Conf.PTO, PGOOpt, &PIC);
227-
AAManager AA;
228-
229-
// Parse a custom AA pipeline if asked to.
230-
if (auto Err = PB.parseAAPipeline(AA, "default"))
231-
report_fatal_error("Error parsing default AA pipeline");
232227

233228
RegisterPassPlugins(Conf.PassPlugins, PB);
234229

@@ -243,6 +238,16 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
243238
TLII->disableAllFunctions();
244239
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
245240

241+
AAManager AA;
242+
// Parse a custom AA pipeline if asked to.
243+
if (!Conf.AAPipeline.empty()) {
244+
if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
245+
report_fatal_error("unable to parse AA pipeline description '" +
246+
Conf.AAPipeline + "': " + toString(std::move(Err)));
247+
}
248+
} else {
249+
AA = PB.buildDefaultAAPipeline();
250+
}
246251
// Register the AA manager first so that our version is the one used.
247252
FAM.registerPass([&] { return std::move(AA); });
248253

@@ -277,66 +282,24 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
277282
break;
278283
}
279284

280-
if (IsThinLTO)
285+
// Parse a custom pipeline if asked to.
286+
if (!Conf.OptPipeline.empty()) {
287+
if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline)) {
288+
report_fatal_error("unable to parse pass pipeline description '" +
289+
Conf.OptPipeline + "': " + toString(std::move(Err)));
290+
}
291+
} else if (IsThinLTO) {
281292
MPM.addPass(PB.buildThinLTODefaultPipeline(OL, ImportSummary));
282-
else
293+
} else {
283294
MPM.addPass(PB.buildLTODefaultPipeline(OL, ExportSummary));
295+
}
284296

285297
if (!Conf.DisableVerify)
286298
MPM.addPass(VerifierPass());
287299

288300
MPM.run(Mod, MAM);
289301
}
290302

291-
static void runNewPMCustomPasses(const Config &Conf, Module &Mod,
292-
TargetMachine *TM) {
293-
PassBuilder PB(Conf.DebugPassManager, TM);
294-
AAManager AA;
295-
296-
// Parse a custom AA pipeline if asked to.
297-
if (!Conf.AAPipeline.empty())
298-
if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline))
299-
report_fatal_error("unable to parse AA pipeline description '" +
300-
Conf.AAPipeline + "': " + toString(std::move(Err)));
301-
302-
RegisterPassPlugins(Conf.PassPlugins, PB);
303-
304-
LoopAnalysisManager LAM;
305-
FunctionAnalysisManager FAM;
306-
CGSCCAnalysisManager CGAM;
307-
ModuleAnalysisManager MAM;
308-
309-
std::unique_ptr<TargetLibraryInfoImpl> TLII(
310-
new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())));
311-
if (Conf.Freestanding)
312-
TLII->disableAllFunctions();
313-
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
314-
315-
// Register the AA manager first so that our version is the one used.
316-
FAM.registerPass([&] { return std::move(AA); });
317-
318-
// Register all the basic analyses with the managers.
319-
PB.registerModuleAnalyses(MAM);
320-
PB.registerCGSCCAnalyses(CGAM);
321-
PB.registerFunctionAnalyses(FAM);
322-
PB.registerLoopAnalyses(LAM);
323-
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
324-
325-
ModulePassManager MPM;
326-
327-
// Always verify the input.
328-
MPM.addPass(VerifierPass());
329-
330-
// Now, add all the passes we've been requested to.
331-
if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline))
332-
report_fatal_error("unable to parse pass pipeline description '" +
333-
Conf.OptPipeline + "': " + toString(std::move(Err)));
334-
335-
if (!Conf.DisableVerify)
336-
MPM.addPass(VerifierPass());
337-
MPM.run(Mod, MAM);
338-
}
339-
340303
static void runOldPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
341304
bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
342305
const ModuleSummaryIndex *ImportSummary) {
@@ -392,13 +355,12 @@ bool lto::opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
392355
/*Cmdline*/ CmdArgs);
393356
}
394357
// FIXME: Plumb the combined index into the new pass manager.
395-
if (!Conf.OptPipeline.empty())
396-
runNewPMCustomPasses(Conf, Mod, TM);
397-
else if (Conf.UseNewPM)
358+
if (Conf.UseNewPM) {
398359
runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO, ExportSummary,
399360
ImportSummary);
400-
else
361+
} else {
401362
runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary);
363+
}
402364
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
403365
}
404366

0 commit comments

Comments
 (0)