Skip to content

Commit 1dd2fb6

Browse files
committed
[PassBuilder][FatLTO] Expose FatLTO pipeline via pipeline string
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 7f223d1 commit 1dd2fb6

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
@@ -1511,6 +1511,41 @@ Expected<bool> parseVirtRegRewriterPassOptions(StringRef Params) {
15111511
return ClearVirtRegs;
15121512
}
15131513

1514+
struct FatLTOOptions {
1515+
OptimizationLevel OptLevel;
1516+
bool ThinLTO = false;
1517+
bool EmitSummary = false;
1518+
};
1519+
1520+
Expected<FatLTOOptions> parseFatLTOOptions(StringRef Params) {
1521+
FatLTOOptions Result;
1522+
bool HaveOptLevel = false;
1523+
while (!Params.empty()) {
1524+
StringRef ParamName;
1525+
std::tie(ParamName, Params) = Params.split(';');
1526+
1527+
if (ParamName == "thinlto") {
1528+
Result.ThinLTO = true;
1529+
} else if (ParamName == "emit-summary") {
1530+
Result.EmitSummary = true;
1531+
} else if (std::optional<OptimizationLevel> OptLevel =
1532+
parseOptLevel(ParamName)) {
1533+
Result.OptLevel = *OptLevel;
1534+
HaveOptLevel = true;
1535+
} else {
1536+
return make_error<StringError>(
1537+
formatv("invalid fatlto-pre-link pass parameter '{}'", ParamName)
1538+
.str(),
1539+
inconvertibleErrorCode());
1540+
}
1541+
}
1542+
if (!HaveOptLevel)
1543+
return make_error<StringError>(
1544+
"missing optimization level for fatlto-pre-link pipeline",
1545+
inconvertibleErrorCode());
1546+
return Result;
1547+
}
1548+
15141549
} // namespace
15151550

15161551
/// 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)