Skip to content

Conversation

fnriv
Copy link
Contributor

@fnriv fnriv commented Aug 26, 2025

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

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the LTO Link time optimization (regular/full LTO or ThinLTO) label Aug 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 26, 2025

@llvm/pr-subscribers-lto

Author: Faith Rivera (fnriv)

Changes

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 --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);
 

Copy link
Member

@jmorse jmorse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Developer Policy and LLVM Discourse for more information.

Copy link

github-actions bot commented Aug 27, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@jmorse
Copy link
Member

jmorse commented Aug 28, 2025

Narrowing down the CI failure,

2025-08-27T16:03:16.7830674Z /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/LTO/Resolution/X86/unified-lto-check.ll:49:16: error: INVALIDMODE: expected string not found in input
2025-08-27T16:03:16.7831783Z ; INVALIDMODE: invalid LTO mode
2025-08-27T16:03:16.7832139Z                ^
2025-08-27T16:03:16.7832461Z <stdin>:1:1: note: scanning from here
2025-08-27T16:03:16.7834187Z llvm-lto2: for the --unified-lto option: Cannot find option named 'foo'!
2025-08-27T16:03:16.7834718Z ^
2025-08-27T16:03:16.7835051Z <stdin>:1:61: note: possible intended match here
2025-08-27T16:03:16.7835606Z llvm-lto2: for the --unified-lto option: Cannot find option named 'foo'!
2025-08-27T16:03:16.7836510Z                                                             ^
2025-08-27T16:03:16.7836806Z 
2025-08-27T16:03:16.7836958Z Input file: <stdin>
2025-08-27T16:03:16.7837758Z Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/LTO/Resolution/X86/unified-lto-check.ll
2025-08-27T16:03:16.7838499Z 
2025-08-27T16:03:16.7838695Z -dump-input=help explains the following input dump.
2025-08-27T16:03:16.7839090Z 
2025-08-27T16:03:16.7839219Z Input was:
2025-08-27T16:03:16.7839481Z <<<<<<
2025-08-27T16:03:16.7839941Z             1: llvm-lto2: for the --unified-lto option: Cannot find option named 'foo'! 
2025-08-27T16:03:16.7840658Z check:49'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
2025-08-27T16:03:16.7841303Z check:49'1                                                                 ?             possible intended match
2025-08-27T16:03:16.7841754Z >>>>>>
2025-08-27T16:03:16.7841911Z 

I guess that's the correct behaviour, in that an error is produced if the wrong argument is given, it's just not quite the same error text as what you're' checking for?

@jmorse
Copy link
Member

jmorse commented Sep 4, 2025

Digging through the windows-bot failure,

2025-09-04T03:13:36.8396084Z # | C:\_work\llvm-project\llvm-project\llvm\test\LTO\Resolution\X86\unified-lto-check.ll:49:16: error: INVALIDMODE: expected string not found in input
2025-09-04T03:13:36.8397077Z # | ; INVALIDMODE: llvm-lto2: for the --unified-lto option: Cannot find option named
2025-09-04T03:13:36.8397650Z # |                ^
2025-09-04T03:13:36.8397937Z # | <stdin>:1:1: note: scanning from here
2025-09-04T03:13:36.8398465Z # | llvm-lto2.exe: for the --unified-lto option: Cannot find option named 'foo'!
2025-09-04T03:13:36.8398954Z # | ^
2025-09-04T03:13:36.8399175Z # | 
2025-09-04T03:13:36.8399428Z # | Input file: <stdin>
2025-09-04T03:13:36.8400020Z # | Check file: C:\_work\llvm-project\llvm-project\llvm\test\LTO\Resolution\X86\unified-lto-check.ll
2025-09-04T03:13:36.8400637Z # | 
2025-09-04T03:13:36.8400924Z # | -dump-input=help explains the following input dump.
2025-09-04T03:13:36.8401318Z # | 
2025-09-04T03:13:36.8401508Z # | Input was:
2025-09-04T03:13:36.8401728Z # | <<<<<<
2025-09-04T03:13:36.8402111Z # |           1: llvm-lto2.exe: for the --unified-lto option: Cannot find option named 'foo'! 
2025-09-04T03:13:36.8402728Z # | check:49     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
2025-09-04T03:13:36.8403171Z # | >>>>>>
2025-09-04T03:13:36.8403382Z # `-----------------------------

That's a Windows issue where llvm-lto2 has ".exe" on the end if on Windows, and doesn't on Linux. I suppose that's solveable through using an optional regex for ".exe", or just not checking for the binary name and only the error message.

@jmorse jmorse merged commit f756224 into llvm:main Sep 10, 2025
9 checks passed
Copy link

@fnriv Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@wrotki
Copy link
Contributor

wrotki commented Sep 11, 2025

I see LTO test failures on macOS llvm.org bot: https://green.lab.llvm.org/job/llvm.org/job/clang-stage2-cmake-RgSan/1057/

Can you check if this change might have affected it?

@jmorse
Copy link
Member

jmorse commented Sep 12, 2025

Alas we don't have any mac environments to test in; a speculative revert and then reapplication if it doesn't fix anything would be alright, this a user-facing options fix.

By my reading the relevant error message on green-dragon is the preloaded "libclang_rt.asan_osx_dynamic.dylib: command not found" message; it seems unlikely that this options change would manage to change something and propagate that far into a build without causing some other error. (I know nothing about green dragon though!)

@fnriv
Copy link
Contributor Author

fnriv commented Sep 15, 2025

Hi,

I had a mac machine when developing this and currently do not have access to a Windows/Linux machine.

An alternative approach I can change could be to revert it to string checking rather than clEnumValN checking (as was done before)? I had changed it to clEnumValN due to precedence of that type of check (you can see conversation about this in #148309)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LTO Link time optimization (regular/full LTO or ThinLTO)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants