[llvm] [llvm-lto2] Added llvm-lto2 -unified-lto descriptions (revised) (PR #155462)

Faith Rivera via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 09:14:10 PDT 2025


https://github.com/fnriv updated https://github.com/llvm/llvm-project/pull/155462

>From 8b963372696ba3fdeb1f08901487142f3b0c9937 Mon Sep 17 00:00:00 2001
From: Faith Rivera <103224896+fnriv at users.noreply.github.com>
Date: Thu, 10 Jul 2025 13:45:57 -0700
Subject: [PATCH 1/5] Add -unified-lto flag mode descriptions

---
 llvm/tools/llvm-lto2/llvm-lto2.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index fbde66666a596..1f61dfec918b5 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -198,9 +198,13 @@ 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<std::string> UnifiedLTOMode(
+    "unified-lto", cl::Optional,
+    cl::desc("Set LTO mode with the following options:\n"
+             " thin      ThinLTO, with Unified LTO enabled.\n"
+             " full      Regular LTO, with Unified LTO enabled.\n"
+             " default   Any LTO mode without Unified LTO. The default mode."),
+    cl::value_desc("mode"));
 
 static cl::opt<bool> EnableFreestanding(
     "lto-freestanding",

>From b17f952cd9246d7bf026a3fc33647f3999a22679 Mon Sep 17 00:00:00 2001
From: Faith Rivera <103224896+fnriv at users.noreply.github.com>
Date: Wed, 20 Aug 2025 10:40:57 -0700
Subject: [PATCH 2/5] Add testing for -unified-lto error checking

---
 llvm/test/LTO/Resolution/X86/unified-lto-check.ll | 11 +++++++++++
 1 file changed, 11 insertions(+)

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"
+

>From 9a56b8db4e2dbf2408a27d09b07a532a0ae177c4 Mon Sep 17 00:00:00 2001
From: Faith Rivera <103224896+fnriv at users.noreply.github.com>
Date: Mon, 25 Aug 2025 16:19:21 -0700
Subject: [PATCH 3/5] Changed unified-lto mode processing to use clEnumValN

---
 llvm/tools/llvm-lto2/llvm-lto2.cpp | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index 1f61dfec918b5..00021c9a32fa3 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -198,13 +198,18 @@ static cl::list<std::string>
     PassPlugins("load-pass-plugin",
                 cl::desc("Load passes from plugin library"));
 
-static cl::opt<std::string> UnifiedLTOMode(
+static cl::opt<LTO::LTOKind> UnifiedLTOMode(
     "unified-lto", cl::Optional,
-    cl::desc("Set LTO mode with the following options:\n"
-             " thin      ThinLTO, with Unified LTO enabled.\n"
-             " full      Regular LTO, with Unified LTO enabled.\n"
-             " default   Any LTO mode without Unified LTO. The default mode."),
-    cl::value_desc("mode"));
+    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",
@@ -408,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);
 

>From de47c11c6c37bddeffabb08b90b19f65e60b1f3c Mon Sep 17 00:00:00 2001
From: Faith Rivera <103224896+fnriv at users.noreply.github.com>
Date: Wed, 3 Sep 2025 19:50:28 -0700
Subject: [PATCH 4/5] Fixed error test check for unified-lto-check

---
 .../LTO/Resolution/X86/unified-lto-check.ll   |  3 ++-
 llvm/tools/llvm-lto2/llvm-lto2.cpp            | 19 +++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
index e1a93e5665702..6f391b4bd82e4 100644
--- a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
+++ b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
@@ -46,7 +46,8 @@
 ; RUN: not llvm-lto2 run --unified-lto=1 -o %t3 %t1 %t2 2>&1 | \
 ; RUN: FileCheck %s --check-prefix INVALIDMODE
 
-; INVALIDMODE: invalid LTO mode
+; INVALIDMODE: llvm-lto2: 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
diff --git a/llvm/tools/llvm-lto2/llvm-lto2.cpp b/llvm/tools/llvm-lto2/llvm-lto2.cpp
index 00021c9a32fa3..c8f8ca04286c6 100644
--- a/llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ b/llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -201,15 +201,13 @@ static cl::list<std::string>
 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)); 
+    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",
@@ -576,7 +574,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";

>From 5eb95e29be19091a823e90fe029043f4ad921ea8 Mon Sep 17 00:00:00 2001
From: Faith Rivera <103224896+fnriv at users.noreply.github.com>
Date: Thu, 4 Sep 2025 09:09:55 -0700
Subject: [PATCH 5/5] Fixed unified-lto-check test for Windows compatibility

---
 llvm/test/LTO/Resolution/X86/unified-lto-check.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
index 6f391b4bd82e4..3d751ab205244 100644
--- a/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
+++ b/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
@@ -46,7 +46,7 @@
 ; RUN: not llvm-lto2 run --unified-lto=1 -o %t3 %t1 %t2 2>&1 | \
 ; RUN: FileCheck %s --check-prefix INVALIDMODE
 
-; INVALIDMODE: llvm-lto2: for the --unified-lto option: Cannot find option named
+; INVALIDMODE: for the --unified-lto option: Cannot find option named
 
 
 ; UNIFIEDERR: unified LTO compilation must use compatible bitcode modules



More information about the llvm-commits mailing list