[PATCH] D126681: [HIP] Fix static lib name on windows
This revision was automatically updated to reflect the committed changes. yaxunl marked an inline comment as done. Closed by commit rG377806a65ea9: [HIP] Fix static lib name on windows (authored by yaxunl). Herald added a project: clang. Changed prior to commit: https://reviews.llvm.org/D126681?vs=432996&id=433273#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D126681/new/ https://reviews.llvm.org/D126681 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/hip-link-bundle-archive.hip Index: clang/test/Driver/hip-link-bundle-archive.hip === --- clang/test/Driver/hip-link-bundle-archive.hip +++ clang/test/Driver/hip-link-bundle-archive.hip @@ -1,14 +1,28 @@ // REQUIRES: x86-registered-target, amdgpu-registered-target -// RUN: touch %T/libhipBundled.a // Check clang unbundle the archive and link them by lld. +// RUN: touch %T/libhipBundled.a // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ +// RUN: -target x86_64-unknown-linux-gnu \ // RUN: -nogpulib %s -fgpu-rdc -L%T -lhipBundled \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK %s +// RUN: 2>&1 | FileCheck -check-prefix=GNU %s + +// RUN: touch %T/hipBundled2.lib +// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ +// RUN: -target x86_64-pc-windows-msvc \ +// RUN: -nogpulib %s -fgpu-rdc -L%T -lhipBundled2 \ +// RUN: 2>&1 | FileCheck -check-prefix=MSVC %s + +// GNU: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles" +// GNU: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]" +// GNU: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles" +// GNU: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]" +// GNU: "{{.*}}ld{{.*}}" {{.*}}"-o" "a.out" {{.*}}"-lhipBundled" -// CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles" -// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]" -// CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles" -// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]" +// MSVC: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}hipBundled2.lib" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles" +// MSVC: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]" +// MSVC: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}hipBundled2.lib" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles" +// MSVC: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]" +// MSVC: "{{.*}}link{{.*}}" {{.*}}"-out:a.exe" {{.*}}"hipBundled2.lib" Index: clang/lib/Driver/ToolChains/CommonArgs.cpp === --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1782,8 +1782,13 @@ for (auto LPath : LibraryPaths) { ArchiveOfBundles.clear(); -AOBFileNames.push_back(Twine(LPath + "/libdevice/lib" + Lib + ".a").str()); -AOBFileNames.push_back(Twine(LPath + "/lib" + Lib + ".a").str()); +llvm::Triple Triple(D.getTargetTriple()); +bool IsMSVC = Triple.isWindowsMSVCEnvironment(); +for (auto Prefix : {"/libdevice/", "/"}) { + if (IsMSVC) +AOBFileNames.push_back(Twine(LPath + Prefix + Lib + ".lib").str()); + AOBFileNames.push_back(Twine(LPath + Prefix + "lib" + Lib + ".a").str()); +} for (auto AOB : AOBFileNames) { if (llvm::sys::fs::exists(AOB)) { Index: clang/test/Driver/hip-link-bundle-archive.hip === --- clang/test/Driver/hip-link-bundle-archive.hip +++ clang/test/Driver/hip-link-bundle-archive.hip @@ -1,14 +1,28 @@ // REQUIRES: x86-registered-target, amdgpu-registered-target -// RUN: touch %T/libhipBundled.a // Check clang unbundle the archive and link them by lld. +// RUN: touch %T/libhipBundled.a // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ +// RUN: -target x86_64-unknown-linux-gnu \ // RUN: -nogpulib %s -fgpu-rdc -L%T -lhipBundled \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK %s +// RUN: 2>&1 | FileCheck -check-prefix=GNU %s + +// RUN: touch %T/hipBundled2.lib +// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ +// RUN: -target x86_64-pc-windows-msvc \ +// RUN: -nogpulib %s
[PATCH] D126681: [HIP] Fix static lib name on windows
yaxunl marked an inline comment as done. yaxunl added inline comments. Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1788 +for (auto Prefix : {"/libdevice/", "/"}) { + if (IsMSVC) { +AOBFileNames.push_back(Twine(LPath + Prefix + Lib + ".lib").str()); tra wrote: > style nit: no need for braces here > https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements will fix when committing CHANGES SINCE LAST ACTION https://reviews.llvm.org/D126681/new/ https://reviews.llvm.org/D126681 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D126681: [HIP] Fix static lib name on windows
tra accepted this revision. tra added inline comments. This revision is now accepted and ready to land. Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1788 +for (auto Prefix : {"/libdevice/", "/"}) { + if (IsMSVC) { +AOBFileNames.push_back(Twine(LPath + Prefix + Lib + ".lib").str()); style nit: no need for braces here https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements CHANGES SINCE LAST ACTION https://reviews.llvm.org/D126681/new/ https://reviews.llvm.org/D126681 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D126681: [HIP] Fix static lib name on windows
yaxunl created this revision. yaxunl added a reviewer: tra. Herald added a project: All. yaxunl requested review of this revision. Herald added a subscriber: MaskRay. clang by default assumes static library name to be xxx.lib when -lxxx is specified on Windows with MSVC environment, instead of libxxx.a. This patch fixes static device library unbundling for that. It falls back to libxxx.a if xxx.lib is not found. https://reviews.llvm.org/D126681 Files: clang/lib/Driver/ToolChains/CommonArgs.cpp clang/test/Driver/hip-link-bundle-archive.hip Index: clang/test/Driver/hip-link-bundle-archive.hip === --- clang/test/Driver/hip-link-bundle-archive.hip +++ clang/test/Driver/hip-link-bundle-archive.hip @@ -1,14 +1,28 @@ // REQUIRES: x86-registered-target, amdgpu-registered-target -// RUN: touch %T/libhipBundled.a // Check clang unbundle the archive and link them by lld. +// RUN: touch %T/libhipBundled.a // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ +// RUN: -target x86_64-unknown-linux-gnu \ // RUN: -nogpulib %s -fgpu-rdc -L%T -lhipBundled \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK %s +// RUN: 2>&1 | FileCheck -check-prefix=GNU %s + +// RUN: touch %T/hipBundled2.lib +// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ +// RUN: -target x86_64-pc-windows-msvc \ +// RUN: -nogpulib %s -fgpu-rdc -L%T -lhipBundled2 \ +// RUN: 2>&1 | FileCheck -check-prefix=MSVC %s + +// GNU: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles" +// GNU: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]" +// GNU: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles" +// GNU: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]" +// GNU: "{{.*}}ld{{.*}}" {{.*}}"-o" "a.out" {{.*}}"-lhipBundled" -// CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles" -// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]" -// CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles" -// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]" +// MSVC: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}hipBundled2.lib" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles" +// MSVC: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]" +// MSVC: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}hipBundled2.lib" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles" +// MSVC: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]" +// MSVC: "{{.*}}link{{.*}}" {{.*}}"-out:a.exe" {{.*}}"hipBundled2.lib" Index: clang/lib/Driver/ToolChains/CommonArgs.cpp === --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1782,8 +1782,14 @@ for (auto LPath : LibraryPaths) { ArchiveOfBundles.clear(); -AOBFileNames.push_back(Twine(LPath + "/libdevice/lib" + Lib + ".a").str()); -AOBFileNames.push_back(Twine(LPath + "/lib" + Lib + ".a").str()); +llvm::Triple Triple(D.getTargetTriple()); +bool IsMSVC = Triple.isWindowsMSVCEnvironment(); +for (auto Prefix : {"/libdevice/", "/"}) { + if (IsMSVC) { +AOBFileNames.push_back(Twine(LPath + Prefix + Lib + ".lib").str()); + } + AOBFileNames.push_back(Twine(LPath + Prefix + "lib" + Lib + ".a").str()); +} for (auto AOB : AOBFileNames) { if (llvm::sys::fs::exists(AOB)) { Index: clang/test/Driver/hip-link-bundle-archive.hip === --- clang/test/Driver/hip-link-bundle-archive.hip +++ clang/test/Driver/hip-link-bundle-archive.hip @@ -1,14 +1,28 @@ // REQUIRES: x86-registered-target, amdgpu-registered-target -// RUN: touch %T/libhipBundled.a // Check clang unbundle the archive and link them by lld. +// RUN: touch %T/libhipBundled.a // RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ +// RUN: -target x86_64-unknown-linux-gnu \ // RUN: -nogpulib %s -fgpu-rdc -L%T -lhipBundled \ -// RUN: 2>&1 | FileCheck -check-prefix=CHECK %s +// RUN: 2>&1 | FileCheck -check-prefix=GNU %s + +// RUN: touch %T/hipBundled2.lib +// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ +// RUN: -target x86_64-pc-windows-msvc \ +// RUN: -nogpulib %s