forked from OSchip/llvm-project
Diagnose invalid target ID for AMDGPU toolchain for assembler
AMDGPU toolchain currently only diagnose invalid target ID for OpenCL source compilation. Invalid target ID is not diagnosed for assembler. This patch fixes that. Differential Revision: https://reviews.llvm.org/D88377
This commit is contained in:
parent
c56bb45e83
commit
2cd75f738e
|
@ -426,6 +426,8 @@ AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
|
||||||
DAL->append(A);
|
DAL->append(A);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkTargetID(*DAL);
|
||||||
|
|
||||||
if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
|
if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
|
||||||
return DAL;
|
return DAL;
|
||||||
|
|
||||||
|
@ -518,8 +520,6 @@ void AMDGPUToolChain::addClangTargetOptions(
|
||||||
const llvm::opt::ArgList &DriverArgs,
|
const llvm::opt::ArgList &DriverArgs,
|
||||||
llvm::opt::ArgStringList &CC1Args,
|
llvm::opt::ArgStringList &CC1Args,
|
||||||
Action::OffloadKind DeviceOffloadingKind) const {
|
Action::OffloadKind DeviceOffloadingKind) const {
|
||||||
// Allow using target ID in -mcpu.
|
|
||||||
translateTargetID(DriverArgs, CC1Args);
|
|
||||||
// Default to "hidden" visibility, as object level linking will not be
|
// Default to "hidden" visibility, as object level linking will not be
|
||||||
// supported for the foreseeable future.
|
// supported for the foreseeable future.
|
||||||
if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
|
if (!DriverArgs.hasArg(options::OPT_fvisibility_EQ,
|
||||||
|
@ -536,21 +536,17 @@ AMDGPUToolChain::getGPUArch(const llvm::opt::ArgList &DriverArgs) const {
|
||||||
getTriple(), DriverArgs.getLastArgValue(options::OPT_mcpu_EQ));
|
getTriple(), DriverArgs.getLastArgValue(options::OPT_mcpu_EQ));
|
||||||
}
|
}
|
||||||
|
|
||||||
StringRef
|
void AMDGPUToolChain::checkTargetID(
|
||||||
AMDGPUToolChain::translateTargetID(const llvm::opt::ArgList &DriverArgs,
|
const llvm::opt::ArgList &DriverArgs) const {
|
||||||
llvm::opt::ArgStringList &CC1Args) const {
|
|
||||||
StringRef TargetID = DriverArgs.getLastArgValue(options::OPT_mcpu_EQ);
|
StringRef TargetID = DriverArgs.getLastArgValue(options::OPT_mcpu_EQ);
|
||||||
if (TargetID.empty())
|
if (TargetID.empty())
|
||||||
return StringRef();
|
return;
|
||||||
|
|
||||||
llvm::StringMap<bool> FeatureMap;
|
llvm::StringMap<bool> FeatureMap;
|
||||||
auto OptionalGpuArch = parseTargetID(getTriple(), TargetID, &FeatureMap);
|
auto OptionalGpuArch = parseTargetID(getTriple(), TargetID, &FeatureMap);
|
||||||
if (!OptionalGpuArch) {
|
if (!OptionalGpuArch) {
|
||||||
getDriver().Diag(clang::diag::err_drv_bad_target_id) << TargetID;
|
getDriver().Diag(clang::diag::err_drv_bad_target_id) << TargetID;
|
||||||
return StringRef();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return OptionalGpuArch.getValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ROCMToolChain::addClangTargetOptions(
|
void ROCMToolChain::addClangTargetOptions(
|
||||||
|
|
|
@ -94,11 +94,10 @@ public:
|
||||||
bool shouldSkipArgument(const llvm::opt::Arg *Arg) const;
|
bool shouldSkipArgument(const llvm::opt::Arg *Arg) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Translate -mcpu option containing target ID to cc1 options.
|
/// Check and diagnose invalid target ID specified by -mcpu.
|
||||||
/// Returns the GPU name.
|
void checkTargetID(const llvm::opt::ArgList &DriverArgs) const;
|
||||||
StringRef translateTargetID(const llvm::opt::ArgList &DriverArgs,
|
|
||||||
llvm::opt::ArgStringList &CC1Args) const;
|
|
||||||
|
|
||||||
|
/// Get GPU arch from -mcpu without checking.
|
||||||
StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const;
|
StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -240,8 +240,7 @@ void HIPToolChain::addClangTargetOptions(
|
||||||
Action::OffloadKind DeviceOffloadingKind) const {
|
Action::OffloadKind DeviceOffloadingKind) const {
|
||||||
HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
|
HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind);
|
||||||
|
|
||||||
// Allow using target ID in --offload-arch.
|
StringRef GpuArch = getGPUArch(DriverArgs);
|
||||||
StringRef GpuArch = translateTargetID(DriverArgs, CC1Args);
|
|
||||||
assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
|
assert(!GpuArch.empty() && "Must have an explicit GPU arch.");
|
||||||
(void) GpuArch;
|
(void) GpuArch;
|
||||||
assert(DeviceOffloadingKind == Action::OFK_HIP &&
|
assert(DeviceOffloadingKind == Action::OFK_HIP &&
|
||||||
|
@ -353,6 +352,7 @@ HIPToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
|
||||||
if (!BoundArch.empty()) {
|
if (!BoundArch.empty()) {
|
||||||
DAL->eraseArg(options::OPT_mcpu_EQ);
|
DAL->eraseArg(options::OPT_mcpu_EQ);
|
||||||
DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mcpu_EQ), BoundArch);
|
DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mcpu_EQ), BoundArch);
|
||||||
|
checkTargetID(*DAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DAL;
|
return DAL;
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
// REQUIRES: clang-driver
|
||||||
|
// REQUIRES: x86-registered-target
|
||||||
|
// REQUIRES: amdgpu-registered-target
|
||||||
|
|
||||||
|
// RUN: not %clang -target amdgcn-amd-amdhsa \
|
||||||
|
// RUN: -mcpu=gfx908xnack -nostdlib \
|
||||||
|
// RUN: %s 2>&1 | FileCheck -check-prefix=NOPLUS %s
|
||||||
|
|
||||||
|
// NOPLUS: error: Invalid target ID: gfx908xnack
|
||||||
|
|
||||||
|
// RUN: not %clang -target amdgcn-amd-amdpal \
|
||||||
|
// RUN: -mcpu=gfx908:xnack+:xnack+ -nostdlib \
|
||||||
|
// RUN: %s 2>&1 | FileCheck -check-prefix=ORDER %s
|
||||||
|
|
||||||
|
// ORDER: error: Invalid target ID: gfx908:xnack+:xnack+
|
||||||
|
|
||||||
|
// RUN: not %clang -target amdgcn--mesa3d \
|
||||||
|
// RUN: -mcpu=gfx908:unknown+ -nostdlib \
|
||||||
|
// RUN: %s 2>&1 | FileCheck -check-prefix=UNK %s
|
||||||
|
|
||||||
|
// UNK: error: Invalid target ID: gfx908:unknown+
|
||||||
|
|
||||||
|
// RUN: not %clang -target amdgcn-amd-amdhsa \
|
||||||
|
// RUN: -mcpu=gfx908:sram-ecc+:unknown+ -nostdlib \
|
||||||
|
// RUN: %s 2>&1 | FileCheck -check-prefix=MIXED %s
|
||||||
|
|
||||||
|
// MIXED: error: Invalid target ID: gfx908:sram-ecc+:unknown+
|
||||||
|
|
||||||
|
// RUN: not %clang -target amdgcn-amd-amdhsa \
|
||||||
|
// RUN: -mcpu=gfx900:sram-ecc+ -nostdlib \
|
||||||
|
// RUN: %s 2>&1 | FileCheck -check-prefix=UNSUP %s
|
||||||
|
|
||||||
|
// UNSUP: error: Invalid target ID: gfx900:sram-ecc+
|
||||||
|
|
||||||
|
// RUN: not %clang -target amdgcn-amd-amdhsa \
|
||||||
|
// RUN: -mcpu=gfx900:xnack -nostdlib \
|
||||||
|
// RUN: %s 2>&1 | FileCheck -check-prefix=NOSIGN %s
|
||||||
|
|
||||||
|
// NOSIGN: error: Invalid target ID: gfx900:xnack
|
||||||
|
|
||||||
|
// RUN: not %clang -target amdgcn-amd-amdhsa \
|
||||||
|
// RUN: -mcpu=gfx900+xnack -nostdlib \
|
||||||
|
// RUN: %s 2>&1 | FileCheck -check-prefix=NOCOLON %s
|
||||||
|
|
||||||
|
// NOCOLON: error: Invalid target ID: gfx900+xnack
|
Loading…
Reference in New Issue