Index: clang/lib/Driver/ToolChains/HIPAMD.cpp =================================================================== --- clang/lib/Driver/ToolChains/HIPAMD.cpp +++ clang/lib/Driver/ToolChains/HIPAMD.cpp @@ -121,6 +121,14 @@ for (auto Input : Inputs) LldArgs.push_back(Input.getFilename()); + // Look for archive of bundled bitcode in arguments, and add temporary files + // for the extracted archive of bitcode to inputs. + auto TargetID = Args.getLastArgValue(options::OPT_mcpu_EQ); + AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LldArgs, "amdgcn", + TargetID, + /*IsBitCodeSDL=*/true, + /*PostClangLink=*/false); + const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), Lld, LldArgs, Inputs, Output)); Index: clang/test/Driver/clang-offload-bundler.c =================================================================== --- clang/test/Driver/clang-offload-bundler.c +++ clang/test/Driver/clang-offload-bundler.c @@ -365,6 +365,28 @@ // CKLST2-NOT: openmp-powerpc64le-ibm-linux-gnu // CKLST2-NOT: openmp-x86_64-pc-linux-gnu +// +// Check unbundling archive for HIP. +// +// When the input to clang-offload-bundler is an archive of bundled bitcodes, +// for each target, clang-offload-bundler extracts the bitcode from each +// bundle and archives them. Therefore for each target, the output is an +// archive of unbundled bitcodes. +// +// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \ +// RUN: -inputs=%t.tgt1,%t.tgt2 -outputs=%T/hip_bundle1.bc +// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \ +// RUN: -inputs=%t.tgt1,%t.tgt2 -outputs=%T/hip_bundle2.bc +// RUN: llvm-ar cr %T/hip_archive.a %T/hip_bundle1.bc %T/hip_bundle2.bc +// RUN: clang-offload-bundler -unbundle -type=a -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \ +// RUN: -outputs=%T/hip_900.a,%T/hip_906.a -inputs=%T/hip_archive.a +// RUN: llvm-ar t %T/hip_900.a | FileCheck -check-prefix=HIP-AR-900 %s +// RUN: llvm-ar t %T/hip_906.a | FileCheck -check-prefix=HIP-AR-906 %s +// HIP-AR-900-DAG: hip_bundle1-hip-amdgcn-amd-amdhsa--gfx900 +// HIP-AR-900-DAG: hip_bundle2-hip-amdgcn-amd-amdhsa--gfx900 +// HIP-AR-906-DAG: hip_bundle1-hip-amdgcn-amd-amdhsa--gfx906 +// HIP-AR-906-DAG: hip_bundle2-hip-amdgcn-amd-amdhsa--gfx906 + // // Check bundling without host target is allowed for HIP. // Index: clang/test/Driver/hip-link-bundle-archive.hip =================================================================== --- /dev/null +++ clang/test/Driver/hip-link-bundle-archive.hip @@ -0,0 +1,14 @@ +// REQUIRES: clang-driver, x86-registered-target, amdgpu-registered-target + +// RUN: touch %T/libhipBundled.a + +// Check clang unbundle the archive and link them by lld. + +// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \ +// RUN: -nogpulib %s -fgpu-rdc -L%T -lhipBundled \ +// RUN: 2>&1 | FileCheck -check-prefix=CHECK %s + +// CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-inputs={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-outputs=[[A1030:.*\.a]]" "-allow-missing-bundles" +// CHECK: "{{.*}}lld" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]" +// CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-inputs={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-outputs=[[A906:.*\.a]]" "-allow-missing-bundles" +// CHECK: "{{.*}}lld" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"