Skip to content

[PassBuilder][FatLTO] Expose FatLTO pipeline via pipeline string #146048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,41 @@ Expected<bool> parseVirtRegRewriterPassOptions(StringRef Params) {
return ClearVirtRegs;
}

struct FatLTOOptions {
OptimizationLevel OptLevel;
bool ThinLTO = false;
bool EmitSummary = false;
};

Expected<FatLTOOptions> parseFatLTOOptions(StringRef Params) {
FatLTOOptions Result;
bool HaveOptLevel = false;
while (!Params.empty()) {
StringRef ParamName;
std::tie(ParamName, Params) = Params.split(';');

if (ParamName == "thinlto") {
Result.ThinLTO = true;
} else if (ParamName == "emit-summary") {
Result.EmitSummary = true;
} else if (std::optional<OptimizationLevel> OptLevel =
parseOptLevel(ParamName)) {
Result.OptLevel = *OptLevel;
HaveOptLevel = true;
} else {
return make_error<StringError>(
formatv("invalid fatlto-pre-link pass parameter '{}'", ParamName)
.str(),
inconvertibleErrorCode());
}
}
if (!HaveOptLevel)
return make_error<StringError>(
"missing optimization level for fatlto-pre-link pipeline",
inconvertibleErrorCode());
return Result;
}

} // namespace

/// Tests whether registered callbacks will accept a given pass name.
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ MODULE_PASS_WITH_PARAMS(
return buildLTODefaultPipeline(L, nullptr);
},
parseOptLevelParam, "O0;O1;O2;O3;Os;Oz")
MODULE_PASS_WITH_PARAMS(
"fatlto-pre-link", "", [&](FatLTOOptions Opts) {
setupOptionsForPipelineAlias(PTO, Opts.OptLevel);
return buildFatLTODefaultPipeline(Opts.OptLevel, Opts.ThinLTO,
Opts.EmitSummary);
},
parseFatLTOOptions, "O0;O1;O2;O3;Os;Oz;thinlto;emit-summary")

#undef MODULE_PASS_WITH_PARAMS

Expand Down
7 changes: 7 additions & 0 deletions llvm/test/Other/fatlto.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; RUN: opt -debug-pass-manager -passes='fatlto-pre-link<O2>' -disable-output %s 2>&1 | FileCheck %s
; RUN: opt -debug-pass-manager -passes='fatlto-pre-link<O2;thinlto>' -disable-output %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THINLTO

; CHECK: Running pass: EmbedBitcodePass on [module]
; THINLTO: Running analysis: ModuleSummaryIndexAnalysis on [module]
; CHECK-NEXT: Running pass: FatLtoCleanup on [module]
; CHECK-NEXT: Running pass: LowerTypeTestsPass on [module]
5 changes: 5 additions & 0 deletions llvm/test/Other/pipeline-alias-errors.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
; RUN: not opt -passes="lto-pre-link<foo>" < %s 2>&1 | FileCheck %s --check-prefix=INVALID-OPT-LEVEL
; RUN: not opt -passes="lto" < %s 2>&1 | FileCheck %s --check-prefix=MISSING-OPT-LEVEL
; RUN: not opt -passes="lto<foo>" < %s 2>&1 | FileCheck %s --check-prefix=INVALID-OPT-LEVEL
; RUN: not opt -passes="fatlto-pre-link" < %s 2>&1 | FileCheck %s --check-prefix=FATLTO-MISSING-OPT-LEVEL
; RUN: not opt -passes="fatlto-pre-link<foo>" < %s 2>&1 | FileCheck %s --check-prefix=FATLTO-INVALID-PARAMS

; MISSING-OPT-LEVEL: invalid optimization level ''
; INVALID-OPT-LEVEL: invalid optimization level 'foo'

; FATLTO-MISSING-OPT-LEVEL: missing optimization level for fatlto-pre-link pipeline
; FATLTO-INVALID-PARAMS: invalid fatlto-pre-link pass parameter 'foo'