https://github.com/maarquitos14 updated https://github.com/llvm/llvm-project/pull/206497
>From 4629781052af485b8cbffeb4f1a31a20cead5dc5 Mon Sep 17 00:00:00 2001 From: Marcos Maronas <[email protected]> Date: Mon, 29 Jun 2026 08:29:23 -0500 Subject: [PATCH 1/5] [Clang][HIP] Forward hipstdpar flag to clang-linker-wrapper --- clang/lib/Driver/ToolChains/Clang.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index a3a3954bc464e..d39983a4922b6 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -9915,6 +9915,18 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA, !UsesProfileGenerate && !TC->getTriple().isSPIRV()) CmdArgs.push_back("--no-lto"); } + + if (Kind == Action::OFK_HIP && TC->getTriple().isAMDGCN() && + Args.hasArg(options::OPT_hipstdpar)) { + CmdArgs.push_back(Args.MakeArgString( + "--device-compiler=" + TC->getTripleString() + "=-mllvm")); + CmdArgs.push_back(Args.MakeArgString( + "--device-compiler=" + TC->getTripleString() + + "=-amdgpu-enable-hipstdpar")); + CmdArgs.push_back(Args.MakeArgString( + "--device-linker=" + TC->getTripleString() + + "=-plugin-opt=-amdgpu-enable-hipstdpar")); + } } } >From f49ef7ba15fd14336a7b045bdde55e60ce483498 Mon Sep 17 00:00:00 2001 From: Marcos Maronas <[email protected]> Date: Mon, 29 Jun 2026 10:23:07 -0500 Subject: [PATCH 2/5] Move to AMDGPU toolchain. --- clang/lib/Driver/ToolChains/AMDGPU.cpp | 6 ++++++ clang/lib/Driver/ToolChains/Clang.cpp | 15 ++------------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index 325dba03c4136..032c108d3d10d 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -610,6 +610,9 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-shared"); } + if (Args.hasArg(options::OPT_hipstdpar)) + CmdArgs.push_back("-plugin-opt=-amdgpu-enable-hipstdpar"); + if (auto LTO = getToolChain().getLTOMode(Args); LTO != LTOK_None) { addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs, LTO == LTOK_Thin); @@ -893,6 +896,9 @@ void AMDGPUToolChain::addClangTargetOptions( !DriverArgs.hasArg(options::OPT_disable_llvm_optzns)) CC1Args.push_back("-disable-llvm-optzns"); + if (DriverArgs.hasArg(options::OPT_hipstdpar)) + CC1Args.append({"-mllvm", "-amdgpu-enable-hipstdpar"}); + if (DeviceOffloadingKind == Action::OFK_None) addOpenCLBuiltinsLib(getDriver(), getTriple(), DriverArgs, CC1Args); } diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index d39983a4922b6..bdacc39fecea4 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -9787,7 +9787,8 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA, OPT_fsanitize_trap_EQ, OPT_fno_sanitize_trap_EQ, OPT_fslp_vectorize, - OPT_fno_slp_vectorize}; + OPT_fno_slp_vectorize, + OPT_hipstdpar}; const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input}; auto ToolChainHasRT = [&](const ToolChain &TC, StringRef Name) { return TC.getVFS().exists( @@ -9915,18 +9916,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA, !UsesProfileGenerate && !TC->getTriple().isSPIRV()) CmdArgs.push_back("--no-lto"); } - - if (Kind == Action::OFK_HIP && TC->getTriple().isAMDGCN() && - Args.hasArg(options::OPT_hipstdpar)) { - CmdArgs.push_back(Args.MakeArgString( - "--device-compiler=" + TC->getTripleString() + "=-mllvm")); - CmdArgs.push_back(Args.MakeArgString( - "--device-compiler=" + TC->getTripleString() + - "=-amdgpu-enable-hipstdpar")); - CmdArgs.push_back(Args.MakeArgString( - "--device-linker=" + TC->getTripleString() + - "=-plugin-opt=-amdgpu-enable-hipstdpar")); - } } } >From 5b8a3d3a0f0e89e5b8faa54bbaf74ffe8ef9a567 Mon Sep 17 00:00:00 2001 From: Marcos Maronas <[email protected]> Date: Tue, 30 Jun 2026 03:10:33 -0500 Subject: [PATCH 3/5] Add testing --- clang/test/Driver/hipstdpar.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/clang/test/Driver/hipstdpar.c b/clang/test/Driver/hipstdpar.c index 7d02e0258853e..8420b55f4bfd3 100644 --- a/clang/test/Driver/hipstdpar.c +++ b/clang/test/Driver/hipstdpar.c @@ -21,3 +21,34 @@ // HIPSTDPAR-COMPILE: "-include" "hipstdpar_lib.hpp" // HIPSTDPAR-LINK: "-rpath" // HIPSTDPAR-LINK: "{{.*hip.*}}" + +// Check that --hipstdpar is forwarded to the linker wrapper as a device +// compiler arg when using the new offloading driver. +// RUN: %clang -### --target=x86_64-unknown-linux-gnu \ +// RUN: --hipstdpar --hipstdpar-path=%S/Inputs/hipstdpar \ +// RUN: -nogpulib -nogpuinc -c %s 2>&1 | \ +// RUN: FileCheck --check-prefix=HIPSTDPAR-NEW-DRV %s +// HIPSTDPAR-NEW-DRV: {{".*clang-linker-wrapper"}} +// HIPSTDPAR-NEW-DRV-SAME: "--device-compiler=amdgcn-amd-amdhsa=--hipstdpar" + +// Check that the base AMDGPU toolchain translates --hipstdpar to the backend +// flag. This is the path taken by the inner clang invocation from the linker +// wrapper (clang --target=amdgcn-amd-amdhsa --hipstdpar ...). +// RUN: %clang -### --target=amdgcn-amd-amdhsa \ +// RUN: --hipstdpar %s 2>&1 | \ +// RUN: FileCheck --check-prefix=HIPSTDPAR-AMDGPU-TC %s +// HIPSTDPAR-AMDGPU-TC: "-mllvm" "-amdgpu-enable-hipstdpar" + +// Check that the base AMDGPU toolchain linker forwards the hipstdpar flag as a +// plugin-opt for the LTO path. +// RUN: %clang -### --target=amdgcn-amd-amdhsa \ +// RUN: --hipstdpar -flto %s 2>&1 | \ +// RUN: FileCheck --check-prefix=HIPSTDPAR-AMDGPU-LTO %s +// HIPSTDPAR-AMDGPU-LTO: ld.lld +// HIPSTDPAR-AMDGPU-LTO-SAME: "-plugin-opt=-amdgpu-enable-hipstdpar" + +// Check that without --hipstdpar none of the backend flags are added. +// RUN: %clang -### --target=amdgcn-amd-amdhsa \ +// RUN: -flto %s 2>&1 | \ +// RUN: FileCheck --check-prefix=NO-HIPSTDPAR %s +// NO-HIPSTDPAR-NOT: "-amdgpu-enable-hipstdpar" >From 714defa4e994521c89dc6773ea129aaf91df7bd4 Mon Sep 17 00:00:00 2001 From: Marcos Maronas <[email protected]> Date: Tue, 30 Jun 2026 09:50:36 -0500 Subject: [PATCH 4/5] Fix failing test. --- clang/test/Driver/hipstdpar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/test/Driver/hipstdpar.c b/clang/test/Driver/hipstdpar.c index 8420b55f4bfd3..2aa7e5b10d644 100644 --- a/clang/test/Driver/hipstdpar.c +++ b/clang/test/Driver/hipstdpar.c @@ -26,6 +26,8 @@ // compiler arg when using the new offloading driver. // RUN: %clang -### --target=x86_64-unknown-linux-gnu \ // RUN: --hipstdpar --hipstdpar-path=%S/Inputs/hipstdpar \ +// RUN: --hipstdpar-thrust-path=%S/Inputs/hipstdpar/thrust \ +// RUN: --hipstdpar-prim-path=%S/Inputs/hipstdpar/rocprim \ // RUN: -nogpulib -nogpuinc -c %s 2>&1 | \ // RUN: FileCheck --check-prefix=HIPSTDPAR-NEW-DRV %s // HIPSTDPAR-NEW-DRV: {{".*clang-linker-wrapper"}} @@ -35,8 +37,7 @@ // flag. This is the path taken by the inner clang invocation from the linker // wrapper (clang --target=amdgcn-amd-amdhsa --hipstdpar ...). // RUN: %clang -### --target=amdgcn-amd-amdhsa \ -// RUN: --hipstdpar %s 2>&1 | \ -// RUN: FileCheck --check-prefix=HIPSTDPAR-AMDGPU-TC %s +// RUN: --hipstdpar %s 2>&1 | FileCheck --check-prefix=HIPSTDPAR-AMDGPU-TC %s // HIPSTDPAR-AMDGPU-TC: "-mllvm" "-amdgpu-enable-hipstdpar" // Check that the base AMDGPU toolchain linker forwards the hipstdpar flag as a @@ -49,6 +50,5 @@ // Check that without --hipstdpar none of the backend flags are added. // RUN: %clang -### --target=amdgcn-amd-amdhsa \ -// RUN: -flto %s 2>&1 | \ -// RUN: FileCheck --check-prefix=NO-HIPSTDPAR %s +// RUN: -flto %s 2>&1 | FileCheck --check-prefix=NO-HIPSTDPAR %s // NO-HIPSTDPAR-NOT: "-amdgpu-enable-hipstdpar" >From d1c8c8ed93203ba3c0dc5f3bd996cd4cdeb0e7c0 Mon Sep 17 00:00:00 2001 From: Marcos Maronas <[email protected]> Date: Tue, 30 Jun 2026 10:28:57 -0500 Subject: [PATCH 5/5] Further test fixes --- clang/test/Driver/hipstdpar.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/Driver/hipstdpar.c b/clang/test/Driver/hipstdpar.c index 2aa7e5b10d644..bc585272497f2 100644 --- a/clang/test/Driver/hipstdpar.c +++ b/clang/test/Driver/hipstdpar.c @@ -37,13 +37,13 @@ // flag. This is the path taken by the inner clang invocation from the linker // wrapper (clang --target=amdgcn-amd-amdhsa --hipstdpar ...). // RUN: %clang -### --target=amdgcn-amd-amdhsa \ -// RUN: --hipstdpar %s 2>&1 | FileCheck --check-prefix=HIPSTDPAR-AMDGPU-TC %s +// RUN: --hipstdpar -x c %s 2>&1 | FileCheck --check-prefix=HIPSTDPAR-AMDGPU-TC %s // HIPSTDPAR-AMDGPU-TC: "-mllvm" "-amdgpu-enable-hipstdpar" // Check that the base AMDGPU toolchain linker forwards the hipstdpar flag as a // plugin-opt for the LTO path. // RUN: %clang -### --target=amdgcn-amd-amdhsa \ -// RUN: --hipstdpar -flto %s 2>&1 | \ +// RUN: --hipstdpar -flto -x c %s 2>&1 | \ // RUN: FileCheck --check-prefix=HIPSTDPAR-AMDGPU-LTO %s // HIPSTDPAR-AMDGPU-LTO: ld.lld // HIPSTDPAR-AMDGPU-LTO-SAME: "-plugin-opt=-amdgpu-enable-hipstdpar" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
