[clang] dc81d2a - [OpenMP] Fix using the target ID when using the new driver
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 7 17:17:35 PDT 2023
Author: Joseph Huber
Date: 2023-06-07T19:17:27-05:00
New Revision: dc81d2a4d5b38a82cdc76c41522e61f0de716904
URL: https://github.com/llvm/llvm-project/commit/dc81d2a4d5b38a82cdc76c41522e61f0de716904
DIFF: https://github.com/llvm/llvm-project/commit/dc81d2a4d5b38a82cdc76c41522e61f0de716904.diff
LOG: [OpenMP] Fix using the target ID when using the new driver
AMDGPU sometimes uses a novel formatting for their offloading
architecture called the target id. This merges the attributes and the
architecture name into a single string. Previously, we were passing this
as the canonical architecture name. This caused the linker wrapper to
fail to find relevant libraries and then pass an incalid CPU name. This
patch changes the handling in the offload packager to handle the
canonical architecture and then extract the features.
Reviewed By: yaxunl
Differential Revision: https://reviews.llvm.org/D150998
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/amdgpu-openmp-toolchain.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index ec6d1a633f1ef..ead59902b65c7 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8403,7 +8403,7 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
C.getArgsForToolChain(TC, OffloadAction->getOffloadingArch(),
OffloadAction->getOffloadingDeviceKind());
StringRef File = C.getArgs().MakeArgString(TC->getInputFilename(Input));
- StringRef Arch = (OffloadAction->getOffloadingArch())
+ StringRef Arch = OffloadAction->getOffloadingArch()
? OffloadAction->getOffloadingArch()
: TCArgs.getLastArgValue(options::OPT_march_EQ);
StringRef Kind =
@@ -8416,14 +8416,24 @@ void OffloadPackager::ConstructJob(Compilation &C, const JobAction &JA,
llvm::copy_if(Features, std::back_inserter(FeatureArgs),
[](StringRef Arg) { return !Arg.startswith("-target"); });
+ if (TC->getTriple().isAMDGPU()) {
+ for (StringRef Feature : llvm::split(Arch.split(':').second, ':')) {
+ FeatureArgs.emplace_back(
+ Args.MakeArgString(Feature.take_back() + Feature.drop_back()));
+ }
+ }
+
+ // TODO: We need to pass in the full target-id and handle it properly in the
+ // linker wrapper.
SmallVector<std::string> Parts{
"file=" + File.str(),
"triple=" + TC->getTripleString(),
- "arch=" + Arch.str(),
+ "arch=" + getProcessorFromTargetID(TC->getTriple(), Arch).str(),
"kind=" + Kind.str(),
};
- if (TC->getDriver().isUsingLTO(/* IsOffload */ true))
+ if (TC->getDriver().isUsingLTO(/* IsOffload */ true) ||
+ TC->getTriple().isAMDGPU())
for (StringRef Feature : FeatureArgs)
Parts.emplace_back("feature=" + Feature.str());
diff --git a/clang/test/Driver/amdgpu-openmp-toolchain.c b/clang/test/Driver/amdgpu-openmp-toolchain.c
index 3fcb3aa94bc0c..08ad3a011347d 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -62,3 +62,7 @@
// RUN: --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode -fopenmp-new-driver %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=CHECK-LIB-DEVICE-NOGPULIB
// CHECK-LIB-DEVICE-NOGPULIB-NOT: "-cc1" {{.*}}ocml.bc"{{.*}}ockl.bc"{{.*}}oclc_daz_opt_on.bc"{{.*}}oclc_unsafe_math_off.bc"{{.*}}oclc_finite_only_off.bc"{{.*}}oclc_correctly_rounded_sqrt_on.bc"{{.*}}oclc_wavefrontsize64_on.bc"{{.*}}oclc_isa_version_803.bc"
+
+// RUN: %clang -### -target x86_64-pc-linux-gnu -fopenmp --offload-arch=gfx90a:sramecc-:xnack+ \
+// RUN: -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-TARGET-ID
+// CHECK-TARGET-ID: clang-offload-packager{{.*}}arch=gfx90a,kind=openmp,feature=-sramecc,feature=+xnack
More information about the cfe-commits
mailing list