[clang] 4264e7b - [CUDA][HIP] Disable emitting llvm.linker.options in device compilation

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 4 20:22:22 PST 2019


Author: Yaxun (Sam) Liu
Date: 2019-11-04T23:21:39-05:00
New Revision: 4264e7bbfdb30ed8fe1e0907bfa25e4d1bb04207

URL: https://github.com/llvm/llvm-project/commit/4264e7bbfdb30ed8fe1e0907bfa25e4d1bb04207
DIFF: https://github.com/llvm/llvm-project/commit/4264e7bbfdb30ed8fe1e0907bfa25e4d1bb04207.diff

LOG: [CUDA][HIP] Disable emitting llvm.linker.options in device compilation

The linker options (e.g. pragma detect_mismatch) are intended for host
compilation only, therefore disable it for device compilation.

Differential Revision: https://reviews.llvm.org/D57829

Added: 
    clang/test/CodeGenCUDA/ms-linker-options.cu
    clang/test/Driver/hip-autolink.hip

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 369d8cc1aa96..16bf68254d19 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -378,15 +378,20 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType,
     CmdArgs.push_back("-fexceptions");
 }
 
-static bool ShouldDisableAutolink(const ArgList &Args, const ToolChain &TC) {
+static bool ShouldEnableAutolink(const ArgList &Args, const ToolChain &TC,
+                                 const JobAction &JA) {
   bool Default = true;
   if (TC.getTriple().isOSDarwin()) {
     // The native darwin assembler doesn't support the linker_option directives,
     // so we disable them if we think the .s file will be passed to it.
     Default = TC.useIntegratedAs();
   }
-  return !Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink,
-                       Default);
+  // The linker_option directives are intended for host compilation.
+  if (JA.isDeviceOffloading(Action::OFK_Cuda) ||
+      JA.isDeviceOffloading(Action::OFK_HIP))
+    Default = false;
+  return Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink,
+                      Default);
 }
 
 static bool ShouldDisableDwarfDirectory(const ArgList &Args,
@@ -4391,7 +4396,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   if (ShouldDisableDwarfDirectory(Args, TC))
     CmdArgs.push_back("-fno-dwarf-directory-asm");
 
-  if (ShouldDisableAutolink(Args, TC))
+  if (!ShouldEnableAutolink(Args, TC, JA))
     CmdArgs.push_back("-fno-autolink");
 
   // Add in -fdebug-compilation-dir if necessary.

diff  --git a/clang/test/CodeGenCUDA/ms-linker-options.cu b/clang/test/CodeGenCUDA/ms-linker-options.cu
new file mode 100644
index 000000000000..0be25fbbdfd4
--- /dev/null
+++ b/clang/test/CodeGenCUDA/ms-linker-options.cu
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -emit-llvm -o - -fcuda-is-device -fms-extensions -x hip %s \
+// RUN:   -fno-autolink -triple amdgcn-amd-amdhsa \
+// RUN:   | FileCheck -check-prefix=DEV %s
+// RUN: %clang_cc1 -emit-llvm -o - -fms-extensions -x hip %s -triple \
+// RUN:    x86_64-pc-windows-msvc | FileCheck -check-prefix=HOST %s
+// RUN: %clang_cc1 -emit-llvm -o - -fcuda-is-device -fms-extensions %s \
+// RUN:   -fno-autolink -triple amdgcn-amd-amdhsa \
+// RUN:   | FileCheck -check-prefix=DEV %s
+// RUN: %clang_cc1 -emit-llvm -o - -fms-extensions %s -triple \
+// RUN:    x86_64-pc-windows-msvc | FileCheck -check-prefix=HOST %s
+
+// DEV-NOT: llvm.linker.options
+// DEV-NOT: llvm.dependent-libraries
+// HOST: lvm.linker.options
+// HOST: "/DEFAULTLIB:libcpmt.lib"
+// HOST: "/FAILIFMISMATCH:\22myLib_version=9\22"
+
+#pragma comment(lib, "libcpmt")
+#pragma detect_mismatch("myLib_version", "9")

diff  --git a/clang/test/Driver/hip-autolink.hip b/clang/test/Driver/hip-autolink.hip
new file mode 100644
index 000000000000..9c1b65f1592b
--- /dev/null
+++ b/clang/test/Driver/hip-autolink.hip
@@ -0,0 +1,14 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+//
+// RUN: %clang --target=i386-pc-windows-msvc --cuda-gpu-arch=gfx906 -nogpulib \
+// RUN:   --cuda-device-only -x hip %s -### 2>&1 | FileCheck --check-prefix=DEV %s
+// RUN: %clang --target=i386-pc-windows-msvc --cuda-gpu-arch=gfx906 -nogpulib \
+// RUN:   --cuda-host-only -x hip %s -### 2>&1 | FileCheck --check-prefix=HOST %s
+
+// DEV: "-cc1" "-triple" "amdgcn-amd-amdhsa"
+// DEV-SAME: "-fno-autolink"
+
+// HOST: "-cc1" "-triple" "i386-pc-windows-msvc{{.*}}"
+// HOST-NOT: "-fno-autolink"


        


More information about the cfe-commits mailing list