Reapply "[AMDGPU] Use the AMDGPUToolChain when targeting C/C++ directly" (#125744)

Summary:
This reverts commit 740e6aeccd.

After discussions it was determined that the behavior for IR inputs
needs to be maintained at least for now. In the future we should put a
deprecation notice on this behavior. This patch keeps the old behavior
for OpenCL and IR inputs, while others will be standalone. This is good
enough for standard compile flows.
This commit is contained in:
Joseph Huber 2025-06-03 07:54:17 -05:00 committed by GitHub
parent 0555594195
commit dedef408d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 2 deletions

View file

@ -147,6 +147,7 @@ getNVIDIAOffloadTargetTriple(const Driver &D, const ArgList &Args,
D.Diag(diag::err_drv_invalid_or_unsupported_offload_target) << TT->str();
return std::nullopt;
}
static std::optional<llvm::Triple>
getHIPOffloadTargetTriple(const Driver &D, const ArgList &Args) {
if (!Args.hasArg(options::OPT_offload_EQ)) {
@ -168,6 +169,17 @@ getHIPOffloadTargetTriple(const Driver &D, const ArgList &Args) {
return std::nullopt;
}
template <typename F> static bool usesInput(const ArgList &Args, F &&Fn) {
return llvm::any_of(Args, [&](Arg *A) {
return (A->getOption().matches(options::OPT_x) &&
Fn(types::lookupTypeForTypeSpecifier(A->getValue()))) ||
(A->getOption().getKind() == Option::InputClass &&
StringRef(A->getValue()).rfind('.') != StringRef::npos &&
Fn(types::lookupTypeForExtension(
&A->getValue()[StringRef(A->getValue()).rfind('.') + 1])));
});
}
// static
std::string Driver::GetResourcesPath(StringRef BinaryPath) {
// Since the resource directory is embedded in the module hash, it's important
@ -6834,9 +6846,14 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
case llvm::Triple::CUDA:
TC = std::make_unique<toolchains::NVPTXToolChain>(*this, Target, Args);
break;
case llvm::Triple::AMDHSA:
TC = std::make_unique<toolchains::ROCMToolChain>(*this, Target, Args);
case llvm::Triple::AMDHSA: {
bool DL =
usesInput(Args, types::isOpenCL) || usesInput(Args, types::isLLVMIR);
TC = DL ? std::make_unique<toolchains::ROCMToolChain>(*this, Target, Args)
: std::make_unique<toolchains::AMDGPUToolChain>(*this, Target,
Args);
break;
}
case llvm::Triple::AMDPAL:
case llvm::Triple::Mesa3D:
TC = std::make_unique<toolchains::AMDGPUToolChain>(*this, Target, Args);

View file

@ -35,3 +35,8 @@
// RUN: %clang -### --target=amdgcn-amd-amdhsa-opencl -x cl -c -emit-llvm -mcpu=fiji -nogpulib %s 2>&1 | FileCheck -check-prefix=CHECK-WARN-ATOMIC %s
// CHECK-WARN-ATOMIC: "-cc1"{{.*}} "-Werror=atomic-alignment"
// RUN: %clang -### --target=amdgcn-amd-amdhsa -x cl -c -emit-llvm -mcpu=fiji %s 2>&1 \
// RUN: -mcode-object-version=5 --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode \
// RUN: | FileCheck -check-prefix=DEVICE-LIBS %s
// DEVICE-LIBS: "-mlink-builtin-bitcode" "[[ROCM_PATH:.+]]opencl.bc"

View file

@ -38,3 +38,11 @@
// RUN: %clang -target amdgcn-amd-amdhsa -march=gfx90a -stdlib -startfiles \
// RUN: -nogpulib -nogpuinc -### %s 2>&1 | FileCheck -check-prefix=STARTUP %s
// STARTUP: ld.lld{{.*}}"-lc" "-lm" "{{.*}}crt1.o"
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 %s 2>&1 | FileCheck -check-prefix=ROCM %s
// ROCM-NOT: -mlink-builtin-bitcode
// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=fiji -x ir %s \
// RUN: --rocm-device-lib-path=%S/Inputs/rocm/amdgcn/bitcode 2>&1 \
// RUN: | FileCheck -check-prefix=DEVICE-LIBS %s
// DEVICE-LIBS: "-mlink-builtin-bitcode" "[[ROCM_PATH:.+]]ockl.bc"