Skip to content

Commit d7a3bdf

Browse files
authored
[PassBuilder][FatLTO] Expose FatLTO pipeline via pipeline string (#146048)
Expose the FatLTO pipeline via `-passes="fatlto-pre-link<Ox>"`, similar to all the other optimization pipelines. This is to allow reproducing it outside clang. (Possibly also useful for C API users.)
1 parent f412842 commit d7a3bdf

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,41 @@ Expected<bool> parseVirtRegRewriterPassOptions(StringRef Params) {
15241524
return ClearVirtRegs;
15251525
}
15261526

1527+
struct FatLTOOptions {
1528+
OptimizationLevel OptLevel;
1529+
bool ThinLTO = false;
1530+
bool EmitSummary = false;
1531+
};
1532+
1533+
Expected<FatLTOOptions> parseFatLTOOptions(StringRef Params) {
1534+
FatLTOOptions Result;
1535+
bool HaveOptLevel = false;
1536+
while (!Params.empty()) {
1537+
StringRef ParamName;
1538+
std::tie(ParamName, Params) = Params.split(';');
1539+
1540+
if (ParamName == "thinlto") {
1541+
Result.ThinLTO = true;
1542+
} else if (ParamName == "emit-summary") {
1543+
Result.EmitSummary = true;
1544+
} else if (std::optional<OptimizationLevel> OptLevel =
1545+
parseOptLevel(ParamName)) {
1546+
Result.OptLevel = *OptLevel;
1547+
HaveOptLevel = true;
1548+
} else {
1549+
return make_error<StringError>(
1550+
formatv("invalid fatlto-pre-link pass parameter '{}'", ParamName)
1551+
.str(),
1552+
inconvertibleErrorCode());
1553+
}
1554+
}
1555+
if (!HaveOptLevel)
1556+
return make_error<StringError>(
1557+
"missing optimization level for fatlto-pre-link pipeline",
1558+
inconvertibleErrorCode());
1559+
return Result;
1560+
}
1561+
15271562
} // namespace
15281563

15291564
/// Tests whether registered callbacks will accept a given pass name.

llvm/lib/Passes/PassRegistry.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ MODULE_PASS_WITH_PARAMS(
276276
return buildLTODefaultPipeline(L, nullptr);
277277
},
278278
parseOptLevelParam, "O0;O1;O2;O3;Os;Oz")
279+
MODULE_PASS_WITH_PARAMS(
280+
"fatlto-pre-link", "", [&](FatLTOOptions Opts) {
281+
setupOptionsForPipelineAlias(PTO, Opts.OptLevel);
282+
return buildFatLTODefaultPipeline(Opts.OptLevel, Opts.ThinLTO,
283+
Opts.EmitSummary);
284+
},
285+
parseFatLTOOptions, "O0;O1;O2;O3;Os;Oz;thinlto;emit-summary")
279286

280287
#undef MODULE_PASS_WITH_PARAMS
281288

llvm/test/Other/fatlto.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; RUN: opt -debug-pass-manager -passes='fatlto-pre-link<O2>' -disable-output %s 2>&1 | FileCheck %s
2+
; RUN: opt -debug-pass-manager -passes='fatlto-pre-link<O2;thinlto>' -disable-output %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THINLTO
3+
4+
; CHECK: Running pass: EmbedBitcodePass on [module]
5+
; THINLTO: Running analysis: ModuleSummaryIndexAnalysis on [module]
6+
; CHECK-NEXT: Running pass: FatLtoCleanup on [module]
7+
; CHECK-NEXT: Running pass: LowerTypeTestsPass on [module]

llvm/test/Other/pipeline-alias-errors.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
; RUN: not opt -passes="lto-pre-link<foo>" < %s 2>&1 | FileCheck %s --check-prefix=INVALID-OPT-LEVEL
99
; RUN: not opt -passes="lto" < %s 2>&1 | FileCheck %s --check-prefix=MISSING-OPT-LEVEL
1010
; RUN: not opt -passes="lto<foo>" < %s 2>&1 | FileCheck %s --check-prefix=INVALID-OPT-LEVEL
11+
; RUN: not opt -passes="fatlto-pre-link" < %s 2>&1 | FileCheck %s --check-prefix=FATLTO-MISSING-OPT-LEVEL
12+
; RUN: not opt -passes="fatlto-pre-link<foo>" < %s 2>&1 | FileCheck %s --check-prefix=FATLTO-INVALID-PARAMS
1113

1214
; MISSING-OPT-LEVEL: invalid optimization level ''
1315
; INVALID-OPT-LEVEL: invalid optimization level 'foo'
16+
17+
; FATLTO-MISSING-OPT-LEVEL: missing optimization level for fatlto-pre-link pipeline
18+
; FATLTO-INVALID-PARAMS: invalid fatlto-pre-link pass parameter 'foo'

0 commit comments

Comments
 (0)