Skip to content

Commit 2e31727

Browse files
committed
[NFC] Clean up PassBuilder
Make DebugLogging a member variable so that users of PassBuilder don't need to pass it around so much. Move call to TargetMachine::registerPassBuilderCallbacks() within PassBuilder so users don't need to remember to call it. Reviewed By: asbirlea Differential Revision: https://reviews.llvm.org/D90437
1 parent 10f2a0d commit 2e31727

File tree

8 files changed

+152
-217
lines changed

8 files changed

+152
-217
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
12031203
PassInstrumentationCallbacks PIC;
12041204
StandardInstrumentations SI(CodeGenOpts.DebugPassManager);
12051205
SI.registerCallbacks(PIC);
1206-
PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
1206+
PassBuilder PB(CodeGenOpts.DebugPassManager, TM.get(), PTO, PGOOpt, &PIC);
12071207

12081208
// Attempt to load pass plugins and register their callbacks with PB.
12091209
for (auto &PluginFN : CodeGenOpts.PassPlugins) {
@@ -1241,9 +1241,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
12411241
PB.registerLoopAnalyses(LAM);
12421242
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
12431243

1244-
if (TM)
1245-
TM->registerPassBuilderCallbacks(PB, CodeGenOpts.DebugPassManager);
1246-
12471244
ModulePassManager MPM(CodeGenOpts.DebugPassManager);
12481245

12491246
if (!CodeGenOpts.DisableLLVMPasses) {
@@ -1280,7 +1277,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
12801277
if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
12811278
PGOOpt->Action == PGOOptions::IRUse))
12821279
PB.addPGOInstrPassesForO0(
1283-
MPM, CodeGenOpts.DebugPassManager,
1280+
MPM,
12841281
/* RunProfileGen */ (PGOOpt->Action == PGOOptions::IRInstr),
12851282
/* IsCS */ false, PGOOpt->ProfileFile,
12861283
PGOOpt->ProfileRemappingFile);
@@ -1407,18 +1404,15 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
14071404
});
14081405

14091406
if (IsThinLTO) {
1410-
MPM = PB.buildThinLTOPreLinkDefaultPipeline(
1411-
Level, CodeGenOpts.DebugPassManager);
1407+
MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
14121408
MPM.addPass(CanonicalizeAliasesPass());
14131409
MPM.addPass(NameAnonGlobalPass());
14141410
} else if (IsLTO) {
1415-
MPM = PB.buildLTOPreLinkDefaultPipeline(Level,
1416-
CodeGenOpts.DebugPassManager);
1411+
MPM = PB.buildLTOPreLinkDefaultPipeline(Level);
14171412
MPM.addPass(CanonicalizeAliasesPass());
14181413
MPM.addPass(NameAnonGlobalPass());
14191414
} else {
1420-
MPM = PB.buildPerModuleDefaultPipeline(Level,
1421-
CodeGenOpts.DebugPassManager);
1415+
MPM = PB.buildPerModuleDefaultPipeline(Level);
14221416
}
14231417
}
14241418

llvm/include/llvm/Passes/PassBuilder.h

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class PipelineTuningOptions {
118118
/// of the built-in passes, and those may reference these members during
119119
/// construction.
120120
class PassBuilder {
121+
bool DebugLogging;
121122
TargetMachine *TM;
122123
PipelineTuningOptions PTO;
123124
Optional<PGOOptions> PGOOpt;
@@ -259,11 +260,10 @@ class PassBuilder {
259260
unsigned getSizeLevel() const { return SizeLevel; }
260261
};
261262

262-
explicit PassBuilder(TargetMachine *TM = nullptr,
263+
explicit PassBuilder(bool DebugLogging = false, TargetMachine *TM = nullptr,
263264
PipelineTuningOptions PTO = PipelineTuningOptions(),
264265
Optional<PGOOptions> PGOOpt = None,
265-
PassInstrumentationCallbacks *PIC = nullptr)
266-
: TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {}
266+
PassInstrumentationCallbacks *PIC = nullptr);
267267

268268
/// Cross register the analysis managers through their proxies.
269269
///
@@ -321,8 +321,7 @@ class PassBuilder {
321321
/// \p Phase indicates the current ThinLTO phase.
322322
FunctionPassManager
323323
buildFunctionSimplificationPipeline(OptimizationLevel Level,
324-
ThinLTOPhase Phase,
325-
bool DebugLogging = false);
324+
ThinLTOPhase Phase);
326325

327326
/// Construct the core LLVM module canonicalization and simplification
328327
/// pipeline.
@@ -339,16 +338,13 @@ class PassBuilder {
339338
/// build them.
340339
///
341340
/// \p Phase indicates the current ThinLTO phase.
342-
ModulePassManager
343-
buildModuleSimplificationPipeline(OptimizationLevel Level,
344-
ThinLTOPhase Phase,
345-
bool DebugLogging = false);
341+
ModulePassManager buildModuleSimplificationPipeline(OptimizationLevel Level,
342+
ThinLTOPhase Phase);
346343

347344
/// Construct the module pipeline that performs inlining as well as
348345
/// the inlining-driven cleanups.
349346
ModuleInlinerWrapperPass buildInlinerPipeline(OptimizationLevel Level,
350-
ThinLTOPhase Phase,
351-
bool DebugLogging = false);
347+
ThinLTOPhase Phase);
352348

353349
/// Construct the core LLVM module optimization pipeline.
354350
///
@@ -364,7 +360,6 @@ class PassBuilder {
364360
/// require some transformations for semantic reasons, they should explicitly
365361
/// build them.
366362
ModulePassManager buildModuleOptimizationPipeline(OptimizationLevel Level,
367-
bool DebugLogging = false,
368363
bool LTOPreLink = false);
369364

370365
/// Build a per-module default optimization pipeline.
@@ -379,7 +374,6 @@ class PassBuilder {
379374
/// require some transformations for semantic reasons, they should explicitly
380375
/// build them.
381376
ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level,
382-
bool DebugLogging = false,
383377
bool LTOPreLink = false);
384378

385379
/// Build a pre-link, ThinLTO-targeting default optimization pipeline to
@@ -394,9 +388,7 @@ class PassBuilder {
394388
/// only intended for use when attempting to optimize code. If frontends
395389
/// require some transformations for semantic reasons, they should explicitly
396390
/// build them.
397-
ModulePassManager
398-
buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level,
399-
bool DebugLogging = false);
391+
ModulePassManager buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level);
400392

401393
/// Build an ThinLTO default optimization pipeline to a pass manager.
402394
///
@@ -410,7 +402,7 @@ class PassBuilder {
410402
/// require some transformations for semantic reasons, they should explicitly
411403
/// build them.
412404
ModulePassManager
413-
buildThinLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging,
405+
buildThinLTODefaultPipeline(OptimizationLevel Level,
414406
const ModuleSummaryIndex *ImportSummary);
415407

416408
/// Build a pre-link, LTO-targeting default optimization pipeline to a pass
@@ -425,8 +417,7 @@ class PassBuilder {
425417
/// only intended for use when attempting to optimize code. If frontends
426418
/// require some transformations for semantic reasons, they should explicitly
427419
/// build them.
428-
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level,
429-
bool DebugLogging = false);
420+
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level);
430421

431422
/// Build an LTO default optimization pipeline to a pass manager.
432423
///
@@ -440,7 +431,6 @@ class PassBuilder {
440431
/// require some transformations for semantic reasons, they should explicitly
441432
/// build them.
442433
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level,
443-
bool DebugLogging,
444434
ModuleSummaryIndex *ExportSummary);
445435

446436
/// Build the default `AAManager` with the default alias analysis pipeline
@@ -487,8 +477,7 @@ class PassBuilder {
487477
/// specifically want the pass to run under a adaptor directly. This is
488478
/// preferred when a pipeline is largely of one type, but one or just a few
489479
/// passes are of different types(See PassBuilder.cpp for examples).
490-
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
491-
bool DebugLogging = false);
480+
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText);
492481

493482
/// {{@ Parse a textual pass pipeline description into a specific PassManager
494483
///
@@ -497,12 +486,9 @@ class PassBuilder {
497486
/// this is the valid pipeline text:
498487
///
499488
/// function(lpass)
500-
Error parsePassPipeline(CGSCCPassManager &CGPM, StringRef PipelineText,
501-
bool DebugLogging = false);
502-
Error parsePassPipeline(FunctionPassManager &FPM, StringRef PipelineText,
503-
bool DebugLogging = false);
504-
Error parsePassPipeline(LoopPassManager &LPM, StringRef PipelineText,
505-
bool DebugLogging = false);
489+
Error parsePassPipeline(CGSCCPassManager &CGPM, StringRef PipelineText);
490+
Error parsePassPipeline(FunctionPassManager &FPM, StringRef PipelineText);
491+
Error parsePassPipeline(LoopPassManager &LPM, StringRef PipelineText);
506492
/// @}}
507493

508494
/// Parse a textual alias analysis pipeline into the provided AA manager.
@@ -681,12 +667,10 @@ class PassBuilder {
681667
bool DebugLogging)> &C);
682668

683669
/// Add PGOInstrumenation passes for O0 only.
684-
void addPGOInstrPassesForO0(ModulePassManager &MPM, bool DebugLogging,
685-
bool RunProfileGen, bool IsCS,
686-
std::string ProfileFile,
670+
void addPGOInstrPassesForO0(ModulePassManager &MPM, bool RunProfileGen,
671+
bool IsCS, std::string ProfileFile,
687672
std::string ProfileRemappingFile);
688673

689-
690674
/// Returns PIC. External libraries can use this to register pass
691675
/// instrumentation callbacks.
692676
PassInstrumentationCallbacks *getPassInstrumentationCallbacks() const {
@@ -695,38 +679,30 @@ class PassBuilder {
695679

696680
private:
697681
// O1 pass pipeline
698-
FunctionPassManager buildO1FunctionSimplificationPipeline(
699-
OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging = false);
682+
FunctionPassManager
683+
buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
684+
ThinLTOPhase Phase);
700685

701686
static Optional<std::vector<PipelineElement>>
702687
parsePipelineText(StringRef Text);
703688

704-
Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E,
705-
bool DebugLogging);
706-
Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E,
707-
bool DebugLogging);
708-
Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E,
709-
bool DebugLogging);
710-
Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
711-
bool DebugLogging);
689+
Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E);
690+
Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E);
691+
Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E);
692+
Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E);
712693
bool parseAAPassName(AAManager &AA, StringRef Name);
713694

714695
Error parseLoopPassPipeline(LoopPassManager &LPM,
715-
ArrayRef<PipelineElement> Pipeline,
716-
bool DebugLogging);
696+
ArrayRef<PipelineElement> Pipeline);
717697
Error parseFunctionPassPipeline(FunctionPassManager &FPM,
718-
ArrayRef<PipelineElement> Pipeline,
719-
bool DebugLogging);
698+
ArrayRef<PipelineElement> Pipeline);
720699
Error parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
721-
ArrayRef<PipelineElement> Pipeline,
722-
bool DebugLogging);
700+
ArrayRef<PipelineElement> Pipeline);
723701
Error parseModulePassPipeline(ModulePassManager &MPM,
724-
ArrayRef<PipelineElement> Pipeline,
725-
bool DebugLogging);
702+
ArrayRef<PipelineElement> Pipeline);
726703

727-
void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
728-
OptimizationLevel Level, bool RunProfileGen, bool IsCS,
729-
std::string ProfileFile,
704+
void addPGOInstrPasses(ModulePassManager &MPM, OptimizationLevel Level,
705+
bool RunProfileGen, bool IsCS, std::string ProfileFile,
730706
std::string ProfileRemappingFile);
731707
void invokePeepholeEPCallbacks(FunctionPassManager &, OptimizationLevel);
732708

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
223223
PassInstrumentationCallbacks PIC;
224224
StandardInstrumentations SI(Conf.DebugPassManager);
225225
SI.registerCallbacks(PIC);
226-
PassBuilder PB(TM, Conf.PTO, PGOOpt, &PIC);
226+
PassBuilder PB(Conf.DebugPassManager, TM, Conf.PTO, PGOOpt, &PIC);
227227
AAManager AA;
228228

229229
// Parse a custom AA pipeline if asked to.
@@ -270,10 +270,9 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
270270
}
271271

272272
if (IsThinLTO)
273-
MPM = PB.buildThinLTODefaultPipeline(OL, Conf.DebugPassManager,
274-
ImportSummary);
273+
MPM = PB.buildThinLTODefaultPipeline(OL, ImportSummary);
275274
else
276-
MPM = PB.buildLTODefaultPipeline(OL, Conf.DebugPassManager, ExportSummary);
275+
MPM = PB.buildLTODefaultPipeline(OL, ExportSummary);
277276
MPM.run(Mod, MAM);
278277

279278
// FIXME (davide): verify the output.
@@ -283,7 +282,7 @@ static void runNewPMCustomPasses(const Config &Conf, Module &Mod,
283282
TargetMachine *TM, std::string PipelineDesc,
284283
std::string AAPipelineDesc,
285284
bool DisableVerify) {
286-
PassBuilder PB(TM);
285+
PassBuilder PB(Conf.DebugPassManager, TM);
287286
AAManager AA;
288287

289288
// Parse a custom AA pipeline if asked to.
@@ -722,4 +721,4 @@ bool lto::loadReferencedModules(
722721
OwnedImportsLifetimeManager.push_back(std::move(*MBOrErr));
723722
}
724723
return true;
725-
}
724+
}

0 commit comments

Comments
 (0)