[llvm] f756224 - [llvm-lto2] Added llvm-lto2 -unified-lto descriptions (revised) (#155462)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 10 09:00:18 PDT 2025
Author: Faith Rivera
Date: 2025-09-10T17:00:14+01:00
New Revision: f75622469588f1f20e53752df29fb403bd6084a7
URL: https://github.com/llvm/llvm-project/commit/f75622469588f1f20e53752df29fb403bd6084a7
DIFF: https://github.com/llvm/llvm-project/commit/f75622469588f1f20e53752df29fb403bd6084a7.diff
LOG: [llvm-lto2] Added llvm-lto2 -unified-lto descriptions (revised) (#155462)
This is a revised PR of #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`
Added:
Modified:
llvm/test/LTO/Resolution/X86/unified-lto-check.ll
llvm/tools/llvm-lto2/llvm-lto2.cpp
Removed:
################################################################################
diff --git a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
index cf1e5693165e3..3d751ab205244 100644
--- a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
+++ b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
@@ -38,6 +38,17 @@
; RUN: llvm-lto2 run --debug-only=lto -o %t3 %t1 %t2 2>&1 | \
; RUN: FileCheck --allow-empty %s --check-prefix THIN
+; Test invalid unified-lto mode causes an error message return.
+; RUN: not llvm-lto2 run --unified-lto=foo -o %t3 %t1 %t2 2>&1 | \
+; RUN: FileCheck %s --check-prefix INVALIDMODE
+; RUN: not llvm-lto2 run --unified-lto="foo" -o %t3 %t1 %t2 2>&1 | \
+; RUN: FileCheck %s --check-prefix INVALIDMODE
+; RUN: not llvm-lto2 run --unified-lto=1 -o %t3 %t1 %t2 2>&1 | \
+; RUN: FileCheck %s --check-prefix INVALIDMODE
+
+; INVALIDMODE: for the --unified-lto option: Cannot find option named
+
+
; UNIFIEDERR: unified LTO compilation must use compatible bitcode modules
; NOUNIFIEDERR-NOT: unified LTO compilation must use compatible bitcode modules
@@ -54,3 +65,4 @@
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
+
diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index dd9b6ba95a439..ff75bb564b1e8 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -198,9 +198,16 @@ static cl::list<std::string>
PassPlugins("load-pass-plugin",
cl::desc("Load passes from plugin library"));
-static cl::opt<std::string> UnifiedLTOMode("unified-lto", cl::Optional,
- cl::desc("Set LTO mode"),
- cl::value_desc("mode"));
+static cl::opt<LTO::LTOKind> UnifiedLTOMode(
+ "unified-lto", cl::Optional,
+ cl::desc("Set LTO mode with the following options:"),
+ cl::values(clEnumValN(LTO::LTOK_UnifiedThin, "thin",
+ "ThinLTO with Unified LTO enabled"),
+ clEnumValN(LTO::LTOK_UnifiedRegular, "full",
+ "Regular LTO with Unified LTO enabled"),
+ clEnumValN(LTO::LTOK_Default, "default",
+ "Any LTO mode without Unified LTO")),
+ cl::value_desc("mode"), cl::init(LTO::LTOK_Default));
static cl::opt<bool> EnableFreestanding(
"lto-freestanding",
@@ -403,18 +410,7 @@ static int run(int argc, char **argv) {
HasErrors = true;
};
- LTO::LTOKind LTOMode = LTO::LTOK_Default;
-
- if (UnifiedLTOMode == "full") {
- LTOMode = LTO::LTOK_UnifiedRegular;
- } else if (UnifiedLTOMode == "thin") {
- LTOMode = LTO::LTOK_UnifiedThin;
- } else if (UnifiedLTOMode == "default") {
- LTOMode = LTO::LTOK_Default;
- } else if (!UnifiedLTOMode.empty()) {
- llvm::errs() << "invalid LTO mode\n";
- return 1;
- }
+ LTO::LTOKind LTOMode = UnifiedLTOMode;
LTO Lto(std::move(Conf), std::move(Backend), 1, LTOMode);
@@ -577,7 +573,8 @@ static int dumpSymtab(int argc, char **argv) {
}
if (TT.isOSBinFormatCOFF() && Sym.isWeak() && Sym.isIndirect())
- outs() << " fallback " << Sym.getCOFFWeakExternalFallback() << '\n';
+ outs() << " fallback " << Sym.getCOFFWeakExternalFallback()
+ << '\n';
if (!Sym.getSectionName().empty())
outs() << " section " << Sym.getSectionName() << "\n";
More information about the llvm-commits
mailing list