[PATCH] D154145: [HIP] Fix -mllvm option for device lld linker

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 29 13:11:29 PDT 2023


yaxunl created this revision.
yaxunl added reviewers: tra, jhuber6.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: MaskRay.

currently clang passes -mllvm options to the device lld linker plugin
when compiling HIP. This is against default clang behavior
which is only passing -mllvm options to linker plugin specified through -Wl
options. This patch lets clang only pass -Xoffload-linker -mllvm= options
to device lld linker plugin.

Fixes: https://github.com/llvm/llvm-project/issues/63604


https://reviews.llvm.org/D154145

Files:
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/test/Driver/hip-toolchain-mllvm.hip


Index: clang/test/Driver/hip-toolchain-mllvm.hip
===================================================================
--- clang/test/Driver/hip-toolchain-mllvm.hip
+++ clang/test/Driver/hip-toolchain-mllvm.hip
@@ -1,30 +1,47 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: amdgpu-registered-target
 
+// Check only -Xoffload-linker -mllvm=* options are passed
+// to device lld linker.
+// -mllvm options are passed to clang only.
+
 // RUN: %clang -### --target=x86_64-linux-gnu \
 // RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
-// RUN:   -mllvm -amdgpu-function-calls=0 \
+// RUN:   -mllvm -unroll-count=10 \
+// RUN:   -Xoffload-linker -mllvm=-inline-threshold=100 \
 // RUN:   %s 2>&1 | FileCheck %s
 
 // RUN: %clang -### --target=x86_64-linux-gnu \
 // RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
-// RUN:   -fgpu-rdc -mllvm -amdgpu-function-calls=0 \
-// RUN:   %s 2>&1 | FileCheck -check-prefixes=CHECK,RDC %s
+// RUN:   -mllvm -unroll-count=10 \
+// RUN:   -Xoffload-linker -mllvm=-inline-threshold=100 \
+// RUN:   %s 2>&1 | FileCheck -check-prefix=NEG %s
+
+// RUN: %clang -### --target=x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN:   -fgpu-rdc -mllvm -unroll-count=10 \
+// RUN:   -Xoffload-linker -mllvm=-inline-threshold=100 \
+// RUN:   %s 2>&1 | FileCheck %s
+
+// RUN: %clang -### --target=x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 \
+// RUN:   -fgpu-rdc -mllvm -unroll-count=10 \
+// RUN:   -Xoffload-linker -mllvm=-inline-threshold=100 \
+// RUN:   %s 2>&1 | FileCheck -check-prefix=NEG %s
 
 // CHECK: [[CLANG:".*clang.*"]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
 // CHECK-SAME: {{.*}} "-target-cpu" "gfx803"
-// CHECK-SAME: {{.*}} "-mllvm" "-amdgpu-function-calls=0" {{.*}}
-
-// CHECK-NOT: {{".*opt"}}
-// CHECK-NOT: {{".*llc"}}
-// RDC: [[LLD:".*lld.*"]] {{.*}} "-plugin-opt=-amdgpu-function-calls=0"
+// CHECK-SAME: {{.*}} "-mllvm" "-unroll-count=10" {{.*}}
+// CHECK: [[LLD:".*lld.*"]] {{.*}}"-m" "elf64_amdgpu"{{.*}} "-plugin-opt=-inline-threshold=100"
 
 // CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
 // CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
 // CHECK-SAME: {{.*}} "-target-cpu" "gfx900"
-// CHECK-SAME: {{.*}} "-mllvm" "-amdgpu-function-calls=0" {{.*}}
+// CHECK-SAME: {{.*}} "-mllvm" "-unroll-count=10" {{.*}}
+// CHECK: [[LLD:".*lld.*"]] {{.*}} "-plugin-opt=-inline-threshold=100"
 
-// CHECK-NOT: {{".*opt"}}
-// CHECK-NOT: {{".*llc"}}
-// RDC: [[LLD:".*lld.*"]] {{.*}} "-plugin-opt=-amdgpu-function-calls=0"
+// NEG-NOT: {{".*opt"}}
+// NEG-NOT: {{".*llc"}}
+// NEG-NOT: "-plugin-opt=-unroll-count=10"
+// NEG-NOT: "-m" "elf_x86_64"{{.*}} "-plugin-opt=-inline-threshold=100"
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===================================================================
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -142,11 +142,6 @@
   if (IsThinLTO)
     LldArgs.push_back(Args.MakeArgString("-plugin-opt=-force-import-all"));
 
-  for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
-    LldArgs.push_back(
-        Args.MakeArgString(Twine("-plugin-opt=") + A->getValue(0)));
-  }
-
   if (C.getDriver().isSaveTempsEnabled())
     LldArgs.push_back("-save-temps");
 
@@ -165,7 +160,12 @@
   LldArgs.push_back("--whole-archive");
 
   for (auto *Arg : Args.filtered(options::OPT_Xoffload_linker)) {
-    LldArgs.push_back(Arg->getValue(1));
+    StringRef ArgVal = Arg->getValue(1);
+    if (ArgVal.startswith("-mllvm=")) {
+      ArgVal = ArgVal.substr(strlen("-mllvm="));
+      LldArgs.push_back(Args.MakeArgString(Twine("-plugin-opt=") + ArgVal));
+    } else
+      LldArgs.push_back(Args.MakeArgString(ArgVal));
     Arg->claim();
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154145.535969.patch
Type: text/x-patch
Size: 3830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230629/81ac530b/attachment-0001.bin>


More information about the cfe-commits mailing list