yaxunl updated this revision to Diff 437587.
yaxunl added a comment.

use compiler-rt as runtime lib by default for --hip-link


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127142/new/

https://reviews.llvm.org/D127142

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/hip-runtime-libs-linux.hip
  clang/test/Driver/hip-runtime-libs-msvc.hip

Index: clang/test/Driver/hip-runtime-libs-msvc.hip
===================================================================
--- clang/test/Driver/hip-runtime-libs-msvc.hip
+++ clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -2,9 +2,15 @@
 
 // RUN:  touch %t.o
 
+// Get compiler-rt library full path.
+// RUN: %clang -target x86_64-pc-windows-msvc -rtlib=compiler-rt \
+// RUN:   -print-libgcc-file-name >%t.1
+
 // Test HIP runtime lib args specified by --rocm-path.
 // RUN: %clang -### --hip-link -target x86_64-pc-windows-msvc \
-// RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
-// RUN:   | FileCheck %s
+// RUN:   --rocm-path=%S/Inputs/rocm %t.o >%t.2 2>&1
+// RUN: cat %t.1 %t.2 | FileCheck %s
 
+// CHECK: [[COMPILER_RT:.*clang_rt\.builtins.*]]
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"
+// CHECK-SAME: "[[COMPILER_RT]]"
Index: clang/test/Driver/hip-runtime-libs-linux.hip
===================================================================
--- clang/test/Driver/hip-runtime-libs-linux.hip
+++ clang/test/Driver/hip-runtime-libs-linux.hip
@@ -2,15 +2,19 @@
 
 // RUN:  touch %t.o
 
+// Get compiler-rt library full path.
+// RUN: %clang -target x86_64-linux-gnu -rtlib=compiler-rt \
+// RUN:   -print-libgcc-file-name >%t.1
+
 // Test HIP runtime lib args specified by --rocm-path.
 // RUN: %clang -### --hip-link -target x86_64-linux-gnu \
-// RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
+// RUN:   --rocm-path=%S/Inputs/rocm %t.o >%t.2 2>&1
+// RUN: cat %t.1 %t.2 | FileCheck -check-prefixes=ROCM-PATH,COMMON %s
 
 // Test HIP runtime lib args specified by environment variable ROCM_PATH.
 // RUN: env ROCM_PATH=%S/Inputs/rocm %clang -### --hip-link \
-// RUN:   -target x86_64-linux-gnu %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=ROCM-PATH %s
+// RUN:   -target x86_64-linux-gnu %t.o >%t.2 2>&1
+// RUN: cat %t.1 %t.2 | FileCheck -check-prefixes=ROCM-PATH,COMMON %s
 
 // Test detecting latest /opt/rocm-{release} directory.
 // RUN: rm -rf %T/opt
@@ -18,26 +22,30 @@
 // RUN: cp -r %S/Inputs/rocm %T/opt/rocm-3.9.0-1234
 // RUN: cp -r %S/Inputs/rocm %T/opt/rocm-3.10.0
 // RUN: %clang -### --hip-link -target x86_64-linux-gnu \
-// RUN:   --sysroot=%T %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=ROCM-REL %s
+// RUN:   --sysroot=%T %t.o >%t.2 2>&1
+// RUN: cat %t.1 %t.2 | FileCheck -check-prefixes=ROCM-REL,COMMON %s
 
 // Test HIP runtime lib is not linked without --hip-link.
 // RUN: %clang -### -target x86_64-linux-gnu \
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
-// Test HIP runtime lib is not linked with -nostdlib.
-// RUN: %clang -### --hip-link -nostdlib -target x86_64-linux-gnu \
+// Test HIP runtime lib is not linked with -rtlib=gcc.
+// RUN: %clang -### --hip-link -rtlib=gcc -target x86_64-linux-gnu \
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
-// RUN:   | FileCheck -check-prefixes=NOHIPRT %s
+// RUN:   | FileCheck -check-prefixes=LIBGCC %s
 
 // Test HIP runtime lib is not linked with -no-hip-rt.
 // RUN: %clang -### --hip-link -no-hip-rt -target x86_64-linux-gnu \
 // RUN:   --rocm-path=%S/Inputs/rocm %t.o 2>&1 \
 // RUN:   | FileCheck -check-prefixes=NOHIPRT %s
 
+// COMMON: [[COMPILER_RT:/.*/libclang_rt\.builtins.*]]
 // ROCM-PATH: "-L[[HIPRT:.*/Inputs/rocm/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
 // ROCM-REL: "-L[[HIPRT:.*/opt/rocm-3.10.0/lib]]" "-rpath" "[[HIPRT]]" "-lamdhip64"
+// COMMON-SAME: "[[COMPILER_RT]]"
+
 // NOHIPRT-NOT: "-L{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-rpath" "{{.*/Inputs/rocm/lib}}"
 // NOHIPRT-NOT: "-lamdhip64"
+// LIBGCC-NOT: "{{/[^"]*clang_rt\.builtins[^"]*}}"
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -832,8 +832,12 @@
   if (runtimeLibType)
     return *runtimeLibType;
 
+  // HIP needs compier-rt for _Float16 conversion functions.
   const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ);
-  StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB;
+  StringRef LibName =
+      A ? A->getValue()
+        : (Args.hasArg(options::OPT_hip_link) ? "compiler-rt"
+                                              : CLANG_DEFAULT_RTLIB);
 
   // Only use "platform" in tests to override CLANG_DEFAULT_RTLIB!
   if (LibName == "compiler-rt")
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to