Skip to content

Commit f756224

Browse files
authored
[llvm-lto2] Added llvm-lto2 -unified-lto descriptions (revised) (llvm#155462)
This is a revised PR of llvm#148309 (closed due to some git issues). The changes do the following: - Adds description for the modes of `-unified-lto=mode` option - Changes parsing of `unified-lto` descriptions from string to cEnumValN for continuity of description formatting - Adds testing of error output in `unified-lto-check.ll`
1 parent 41c6859 commit f756224

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

llvm/test/LTO/Resolution/X86/unified-lto-check.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838
; RUN: llvm-lto2 run --debug-only=lto -o %t3 %t1 %t2 2>&1 | \
3939
; RUN: FileCheck --allow-empty %s --check-prefix THIN
4040

41+
; Test invalid unified-lto mode causes an error message return.
42+
; RUN: not llvm-lto2 run --unified-lto=foo -o %t3 %t1 %t2 2>&1 | \
43+
; RUN: FileCheck %s --check-prefix INVALIDMODE
44+
; RUN: not llvm-lto2 run --unified-lto="foo" -o %t3 %t1 %t2 2>&1 | \
45+
; RUN: FileCheck %s --check-prefix INVALIDMODE
46+
; RUN: not llvm-lto2 run --unified-lto=1 -o %t3 %t1 %t2 2>&1 | \
47+
; RUN: FileCheck %s --check-prefix INVALIDMODE
48+
49+
; INVALIDMODE: for the --unified-lto option: Cannot find option named
50+
51+
4152
; UNIFIEDERR: unified LTO compilation must use compatible bitcode modules
4253
; NOUNIFIEDERR-NOT: unified LTO compilation must use compatible bitcode modules
4354

@@ -54,3 +65,4 @@
5465

5566
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5667
target triple = "x86_64-unknown-linux-gnu"
68+

llvm/tools/llvm-lto2/llvm-lto2.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,16 @@ static cl::list<std::string>
198198
PassPlugins("load-pass-plugin",
199199
cl::desc("Load passes from plugin library"));
200200

201-
static cl::opt<std::string> UnifiedLTOMode("unified-lto", cl::Optional,
202-
cl::desc("Set LTO mode"),
203-
cl::value_desc("mode"));
201+
static cl::opt<LTO::LTOKind> UnifiedLTOMode(
202+
"unified-lto", cl::Optional,
203+
cl::desc("Set LTO mode with the following options:"),
204+
cl::values(clEnumValN(LTO::LTOK_UnifiedThin, "thin",
205+
"ThinLTO with Unified LTO enabled"),
206+
clEnumValN(LTO::LTOK_UnifiedRegular, "full",
207+
"Regular LTO with Unified LTO enabled"),
208+
clEnumValN(LTO::LTOK_Default, "default",
209+
"Any LTO mode without Unified LTO")),
210+
cl::value_desc("mode"), cl::init(LTO::LTOK_Default));
204211

205212
static cl::opt<bool> EnableFreestanding(
206213
"lto-freestanding",
@@ -403,18 +410,7 @@ static int run(int argc, char **argv) {
403410
HasErrors = true;
404411
};
405412

406-
LTO::LTOKind LTOMode = LTO::LTOK_Default;
407-
408-
if (UnifiedLTOMode == "full") {
409-
LTOMode = LTO::LTOK_UnifiedRegular;
410-
} else if (UnifiedLTOMode == "thin") {
411-
LTOMode = LTO::LTOK_UnifiedThin;
412-
} else if (UnifiedLTOMode == "default") {
413-
LTOMode = LTO::LTOK_Default;
414-
} else if (!UnifiedLTOMode.empty()) {
415-
llvm::errs() << "invalid LTO mode\n";
416-
return 1;
417-
}
413+
LTO::LTOKind LTOMode = UnifiedLTOMode;
418414

419415
LTO Lto(std::move(Conf), std::move(Backend), 1, LTOMode);
420416

@@ -577,7 +573,8 @@ static int dumpSymtab(int argc, char **argv) {
577573
}
578574

579575
if (TT.isOSBinFormatCOFF() && Sym.isWeak() && Sym.isIndirect())
580-
outs() << " fallback " << Sym.getCOFFWeakExternalFallback() << '\n';
576+
outs() << " fallback " << Sym.getCOFFWeakExternalFallback()
577+
<< '\n';
581578

582579
if (!Sym.getSectionName().empty())
583580
outs() << " section " << Sym.getSectionName() << "\n";

0 commit comments

Comments
 (0)