[llvm] [llvm-lto2] Added llvm-lto2 -unified-lto descriptions (revised) (PR #155462)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 26 11:05:41 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lto
Author: Faith Rivera (fnriv)
<details>
<summary>Changes</summary>
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`
---
Full diff: https://github.com/llvm/llvm-project/pull/155462.diff
2 Files Affected:
- (modified) llvm/test/LTO/Resolution/X86/unified-lto-check.ll (+11)
- (modified) llvm/tools/llvm-lto2/llvm-lto2.cpp (+13-15)
``````````diff
diff --git a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
index cf1e5693165e3..e1a93e5665702 100644
--- a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
+++ b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
@@ -38,6 +38,16 @@
; 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: invalid LTO mode
+
; UNIFIEDERR: unified LTO compilation must use compatible bitcode modules
; NOUNIFIEDERR-NOT: unified LTO compilation must use compatible bitcode modules
@@ -54,3 +64,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 fbde66666a596..00021c9a32fa3 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -198,9 +198,18 @@ 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. The default mode")
+ ),
+ cl::value_desc("mode"), cl::init(LTO::LTOK_Default));
static cl::opt<bool> EnableFreestanding(
"lto-freestanding",
@@ -404,18 +413,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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/155462
More information about the llvm-commits
mailing list