[lld] [LLD] [MinGW] Implement the -lto-sample-profile option (PR #85841)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 10:56:33 PDT 2024


https://github.com/chrulski-intel updated https://github.com/llvm/llvm-project/pull/85841

>From 489ee5ac025368553509355f18450148ba953afc Mon Sep 17 00:00:00 2001
From: chrulski-intel <christopher.m.chrulski at intel.com>
Date: Tue, 19 Mar 2024 11:22:28 -0700
Subject: [PATCH 1/2] [LLD] [MinGW] Implement the -lto-sample-profile option

This has been a supported option for ELF and is added to the COFF Linker
in https://github.com/llvm/llvm-project/pull/85701
---
 lld/MinGW/Driver.cpp       | 2 ++
 lld/MinGW/Options.td       | 2 ++
 lld/test/MinGW/driver.test | 3 +++
 3 files changed, 7 insertions(+)

diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index efd643f9a32203..bb08c77b2e11d4 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -455,6 +455,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
     add("-lldemit:llvm");
   if (args.hasArg(OPT_lto_emit_asm))
     add("-lldemit:asm");
+  if (auto *arg = args.getLastArg(OPT_lto_sample_profile))
+    add("-lto-sample-profile:" + StringRef(arg->getValue()));
 
   if (auto *a = args.getLastArg(OPT_thinlto_cache_dir))
     add("-lldltocache:" + StringRef(a->getValue()));
diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td
index 9a0a96aac7f1c6..56f67e3dd96c42 100644
--- a/lld/MinGW/Options.td
+++ b/lld/MinGW/Options.td
@@ -160,6 +160,8 @@ def lto_cs_profile_file: JJ<"lto-cs-profile-file=">,
   HelpText<"Context sensitive profile file path">;
 def lto_emit_asm: FF<"lto-emit-asm">,
   HelpText<"Emit assembly code">;
+def lto_sample_profile: JJ<"lto-sample-profile=">,
+  HelpText<"Sample profile file path">;
 
 def thinlto_cache_dir: JJ<"thinlto-cache-dir=">,
   HelpText<"Path to ThinLTO cached object file directory">;
diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test
index a4e9e5e1b19b45..c945be84b5c30e 100644
--- a/lld/test/MinGW/driver.test
+++ b/lld/test/MinGW/driver.test
@@ -422,6 +422,9 @@ LTO_EMIT_ASM: -lldemit:asm
 RUN: ld.lld -### foo.o -m i386pe -plugin-opt=emit-llvm 2>&1 | FileCheck -check-prefix=LTO_EMIT_LLVM %s
 LTO_EMIT_LLVM: -lldemit:llvm
 
+RUN: ld.lld -### foo.o -m i386pep --lto-sample-profile=foo 2>&1 | FileCheck -check-prefix=LTO_SAMPLE_PROFILE %s
+LTO_SAMPLE_PROFILE:-lto-sample-profile:foo
+
 Test GCC specific LTO options that GCC passes unconditionally, that we ignore.
 
 RUN: ld.lld -### foo.o -m i386pep -plugin /usr/lib/gcc/x86_64-w64-mingw32/10-posix/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-w64-mingw32/10-posix/lto-wrapper -plugin-opt=-fresolution=/tmp/ccM9d4fP.res -plugin-opt=-pass-through=-lmingw32 2> /dev/null

>From d75b53aea35efc186c6a92b5f4c6330a0244091f Mon Sep 17 00:00:00 2001
From: chrulski-intel <christopher.m.chrulski at intel.com>
Date: Wed, 20 Mar 2024 07:31:59 -0700
Subject: [PATCH 2/2] Fix spacing in test line

---
 lld/test/MinGW/driver.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test
index c945be84b5c30e..619fee8dee7c1f 100644
--- a/lld/test/MinGW/driver.test
+++ b/lld/test/MinGW/driver.test
@@ -423,7 +423,7 @@ RUN: ld.lld -### foo.o -m i386pe -plugin-opt=emit-llvm 2>&1 | FileCheck -check-p
 LTO_EMIT_LLVM: -lldemit:llvm
 
 RUN: ld.lld -### foo.o -m i386pep --lto-sample-profile=foo 2>&1 | FileCheck -check-prefix=LTO_SAMPLE_PROFILE %s
-LTO_SAMPLE_PROFILE:-lto-sample-profile:foo
+LTO_SAMPLE_PROFILE: -lto-sample-profile:foo
 
 Test GCC specific LTO options that GCC passes unconditionally, that we ignore.
 



More information about the llvm-commits mailing list