[llvm-branch-commits] [clang] clang/AMDGPU: Pass BoundArch through device libs handling (PR #196586)
arsenm wrote: > This is only required for the isa.bc file right. BC input is "not offload" since there's only one compile for it https://github.com/llvm/llvm-project/pull/196586 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] clang/AMDGPU: Pass BoundArch through device libs handling (PR #196586)
https://github.com/jhuber6 approved this pull request. This is only required for the isa.bc file right. https://github.com/llvm/llvm-project/pull/196586 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] clang/AMDGPU: Pass BoundArch through device libs handling (PR #196586)
https://github.com/arsenm created
https://github.com/llvm/llvm-project/pull/196586
Pre-work to consolidate target identification for future target
option bug fixes. Also requires updating flang to match recent
clang changes.
Co-authored-by: Claude Sonnet 4
>From 89264ffcfcbae79d28a3ef8d5dc096e1c4012c37 Mon Sep 17 00:00:00 2001
From: Matt Arsenault
Date: Fri, 8 May 2026 11:19:48 +0100
Subject: [PATCH] clang/AMDGPU: Pass BoundArch through device libs handling
Pre-work to consolidate target identification for future target
option bug fixes. Also requires updating flang to match recent
clang changes.
Co-authored-by: Claude Sonnet 4
---
clang/include/clang/Driver/ToolChain.h | 2 +-
clang/lib/Driver/ToolChain.cpp | 2 +-
clang/lib/Driver/ToolChains/AMDGPU.cpp | 11 ++---
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp | 11 -
clang/lib/Driver/ToolChains/AMDGPUOpenMP.h | 2 +-
clang/lib/Driver/ToolChains/Flang.cpp| 24
clang/lib/Driver/ToolChains/Flang.h | 16 ++---
clang/lib/Driver/ToolChains/HIPAMD.cpp | 15
clang/lib/Driver/ToolChains/HIPAMD.h | 2 +-
clang/lib/Driver/ToolChains/HIPSPV.cpp | 4 ++--
clang/lib/Driver/ToolChains/HIPSPV.h | 2 +-
11 files changed, 57 insertions(+), 34 deletions(-)
diff --git a/clang/include/clang/Driver/ToolChain.h
b/clang/include/clang/Driver/ToolChain.h
index 117563ef5c950..e5daadba00e04 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -834,7 +834,7 @@ class ToolChain {
/// Get paths for device libraries.
virtual llvm::SmallVector
- getDeviceLibs(const llvm::opt::ArgList &Args,
+ getDeviceLibs(const llvm::opt::ArgList &Args, llvm::StringRef BoundArch,
const Action::OffloadKind DeviceOffloadingKind) const;
/// Add the system specific libraries for the active offload kinds.
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index a68d39deda915..f920c2014c4a4 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1799,7 +1799,7 @@ void ToolChain::addSYCLIncludeArgs(const ArgList
&DriverArgs,
ArgStringList &CC1Args) const {}
llvm::SmallVector
-ToolChain::getDeviceLibs(const ArgList &DriverArgs,
+ToolChain::getDeviceLibs(const ArgList &DriverArgs, StringRef BoundArch,
const Action::OffloadKind DeviceOffloadingKind) const
{
return {};
}
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 0f87043cf801e..06f9c6ac97047 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -982,9 +982,14 @@ void ROCMToolChain::addClangTargetOptions(
if (TT.getEnvironment() == llvm::Triple::LLVM)
return;
- // Get the device name and canonicalize it
- const StringRef GpuArch = getGPUArch(DriverArgs);
- auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch);
+ // Get the device name and canonicalize it. For offload compilation,
+ // BoundArch contains the full target ID. For non-offload (OpenCL),
+ // fall back to -mcpu.
+ StringRef GpuArch = BoundArch.empty() ? getGPUArch(DriverArgs) : BoundArch;
+
+ // Extract processor name for canonical arch lookup
+ StringRef Processor = getProcessorFromTargetID(getTriple(), GpuArch);
+ auto Kind = llvm::AMDGPU::parseArchAMDGCN(Processor);
const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind);
StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch);
auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion(
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 1f8b078dc4f44..c9965e8e6014b 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -43,7 +43,8 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
true))
return;
- for (auto BCFile : getDeviceLibs(DriverArgs, DeviceOffloadingKind)) {
+ for (auto BCFile :
+ getDeviceLibs(DriverArgs, BoundArch, DeviceOffloadingKind)) {
CC1Args.push_back(BCFile.ShouldInternalize ? "-mlink-builtin-bitcode"
: "-mlink-bitcode-file");
CC1Args.push_back(DriverArgs.MakeArgString(BCFile.Path));
@@ -126,17 +127,15 @@ AMDGPUOpenMPToolChain::computeMSVCVersion(const Driver *D,
llvm::SmallVector
AMDGPUOpenMPToolChain::getDeviceLibs(
-const llvm::opt::ArgList &Args,
+const llvm::opt::ArgList &Args, llvm::StringRef BoundArch,
const Action::OffloadKind DeviceOffloadingKind) const {
if (!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true))
return {};
- StringRef GpuArch = getProcessorFromTargetID(
- getTriple(), Args.getLastArgValue(options::OPT_march_EQ));
-
+ StringRef GpuArch = getProces
[llvm-branch-commits] [clang] clang/AMDGPU: Pass BoundArch through device libs handling (PR #196586)
llvmorg-github-actions[bot] wrote: @llvm/pr-subscribers-clang-driver Author: Matt Arsenault (arsenm) Changes Pre-work to consolidate target identification for future target option bug fixes. Also requires updating flang to match recent clang changes. Co-authored-by: Claude Sonnet 4--- Full diff: https://github.com/llvm/llvm-project/pull/196586.diff 11 Files Affected: - (modified) clang/include/clang/Driver/ToolChain.h (+1-1) - (modified) clang/lib/Driver/ToolChain.cpp (+1-1) - (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+8-3) - (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp (+5-6) - (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.h (+1-1) - (modified) clang/lib/Driver/ToolChains/Flang.cpp (+14-10) - (modified) clang/lib/Driver/ToolChains/Flang.h (+13-3) - (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+10-5) - (modified) clang/lib/Driver/ToolChains/HIPAMD.h (+1-1) - (modified) clang/lib/Driver/ToolChains/HIPSPV.cpp (+2-2) - (modified) clang/lib/Driver/ToolChains/HIPSPV.h (+1-1) ``diff diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 117563ef5c950..e5daadba00e04 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -834,7 +834,7 @@ class ToolChain { /// Get paths for device libraries. virtual llvm::SmallVector - getDeviceLibs(const llvm::opt::ArgList &Args, + getDeviceLibs(const llvm::opt::ArgList &Args, llvm::StringRef BoundArch, const Action::OffloadKind DeviceOffloadingKind) const; /// Add the system specific libraries for the active offload kinds. diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index a68d39deda915..f920c2014c4a4 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -1799,7 +1799,7 @@ void ToolChain::addSYCLIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const {} llvm::SmallVector -ToolChain::getDeviceLibs(const ArgList &DriverArgs, +ToolChain::getDeviceLibs(const ArgList &DriverArgs, StringRef BoundArch, const Action::OffloadKind DeviceOffloadingKind) const { return {}; } diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index 0f87043cf801e..06f9c6ac97047 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -982,9 +982,14 @@ void ROCMToolChain::addClangTargetOptions( if (TT.getEnvironment() == llvm::Triple::LLVM) return; - // Get the device name and canonicalize it - const StringRef GpuArch = getGPUArch(DriverArgs); - auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch); + // Get the device name and canonicalize it. For offload compilation, + // BoundArch contains the full target ID. For non-offload (OpenCL), + // fall back to -mcpu. + StringRef GpuArch = BoundArch.empty() ? getGPUArch(DriverArgs) : BoundArch; + + // Extract processor name for canonical arch lookup + StringRef Processor = getProcessorFromTargetID(getTriple(), GpuArch); + auto Kind = llvm::AMDGPU::parseArchAMDGCN(Processor); const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN(Kind); StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile(CanonArch); auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion( diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp index 1f8b078dc4f44..c9965e8e6014b 100644 --- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp @@ -43,7 +43,8 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions( true)) return; - for (auto BCFile : getDeviceLibs(DriverArgs, DeviceOffloadingKind)) { + for (auto BCFile : + getDeviceLibs(DriverArgs, BoundArch, DeviceOffloadingKind)) { CC1Args.push_back(BCFile.ShouldInternalize ? "-mlink-builtin-bitcode" : "-mlink-bitcode-file"); CC1Args.push_back(DriverArgs.MakeArgString(BCFile.Path)); @@ -126,17 +127,15 @@ AMDGPUOpenMPToolChain::computeMSVCVersion(const Driver *D, llvm::SmallVector AMDGPUOpenMPToolChain::getDeviceLibs( -const llvm::opt::ArgList &Args, +const llvm::opt::ArgList &Args, llvm::StringRef BoundArch, const Action::OffloadKind DeviceOffloadingKind) const { if (!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true)) return {}; - StringRef GpuArch = getProcessorFromTargetID( - getTriple(), Args.getLastArgValue(options::OPT_march_EQ)); - + StringRef GpuArch = getProcessorFromTargetID(getTriple(), BoundArch); SmallVector BCLibs; for (auto BCLib : - getCommonDeviceLibNames(Args, GpuArch.str(), DeviceOffloadingKind)) + getCommonDeviceLibNames(Args, GpuArch, DeviceOffloadingKind)) BCLibs.emplace_back(BCLib);
[llvm-branch-commits] [clang] clang/AMDGPU: Pass BoundArch through device libs handling (PR #196586)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/196586 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] clang/AMDGPU: Pass BoundArch through device libs handling (PR #196586)
arsenm wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.com/github/pr/llvm/llvm-project/196586?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#196586** https://app.graphite.com/github/pr/llvm/llvm-project/196586?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.com/github/pr/llvm/llvm-project/196586?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#196504** https://app.graphite.com/github/pr/llvm/llvm-project/196504?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/196586 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
