Author: Yaxun (Sam) Liu Date: 2021-05-27T12:06:42-04:00 New Revision: 6d2c0950205f50f926ba5e362e845faff22582b7
URL: https://github.com/llvm/llvm-project/commit/6d2c0950205f50f926ba5e362e845faff22582b7 DIFF: https://github.com/llvm/llvm-project/commit/6d2c0950205f50f926ba5e362e845faff22582b7.diff LOG: [HIP] Check compatibility of -fgpu-sanitize with offload arch -fgpu-sanitize is incompatible with offload arch containing xnack-. This patch checks that. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D102975 Added: Modified: clang/lib/Driver/ToolChains/AMDGPU.cpp clang/lib/Driver/ToolChains/AMDGPU.h clang/lib/Driver/ToolChains/HIP.cpp clang/lib/Driver/ToolChains/HIP.h clang/test/Driver/hip-sanitize-options.hip Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index 639f3598a1d9..09ee3b2abfb7 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -707,16 +707,26 @@ AMDGPUToolChain::getGPUArch(const llvm::opt::ArgList &DriverArgs) const { getTriple(), DriverArgs.getLastArgValue(options::OPT_mcpu_EQ)); } -void AMDGPUToolChain::checkTargetID( - const llvm::opt::ArgList &DriverArgs) const { +AMDGPUToolChain::ParsedTargetIDType +AMDGPUToolChain::getParsedTargetID(const llvm::opt::ArgList &DriverArgs) const { StringRef TargetID = DriverArgs.getLastArgValue(options::OPT_mcpu_EQ); if (TargetID.empty()) - return; + return {None, None, None}; llvm::StringMap<bool> FeatureMap; auto OptionalGpuArch = parseTargetID(getTriple(), TargetID, &FeatureMap); - if (!OptionalGpuArch) { - getDriver().Diag(clang::diag::err_drv_bad_target_id) << TargetID; + if (!OptionalGpuArch) + return {TargetID.str(), None, None}; + + return {TargetID.str(), OptionalGpuArch.getValue().str(), FeatureMap}; +} + +void AMDGPUToolChain::checkTargetID( + const llvm::opt::ArgList &DriverArgs) const { + auto PTID = getParsedTargetID(DriverArgs); + if (PTID.OptionalTargetID && !PTID.OptionalGPUArch) { + getDriver().Diag(clang::diag::err_drv_bad_target_id) + << PTID.OptionalTargetID.getValue(); } } diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h index cb95db6e66bc..50ed3b3ded9a 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.h +++ b/clang/lib/Driver/ToolChains/AMDGPU.h @@ -107,7 +107,19 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF { protected: /// Check and diagnose invalid target ID specified by -mcpu. - void checkTargetID(const llvm::opt::ArgList &DriverArgs) const; + virtual void checkTargetID(const llvm::opt::ArgList &DriverArgs) const; + + /// The struct type returned by getParsedTargetID. + struct ParsedTargetIDType { + Optional<std::string> OptionalTargetID; + Optional<std::string> OptionalGPUArch; + Optional<llvm::StringMap<bool>> OptionalFeatures; + }; + + /// Get target ID, GPU arch, and target ID features if the target ID is + /// specified and valid. + ParsedTargetIDType + getParsedTargetID(const llvm::opt::ArgList &DriverArgs) const; /// Get GPU arch from -mcpu without checking. StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const; diff --git a/clang/lib/Driver/ToolChains/HIP.cpp b/clang/lib/Driver/ToolChains/HIP.cpp index 80df2466a5da..28d4e5ddad10 100644 --- a/clang/lib/Driver/ToolChains/HIP.cpp +++ b/clang/lib/Driver/ToolChains/HIP.cpp @@ -459,3 +459,28 @@ HIPToolChain::getHIPDeviceLibs(const llvm::opt::ArgList &DriverArgs) const { return BCLibs; } + +void HIPToolChain::checkTargetID(const llvm::opt::ArgList &DriverArgs) const { + auto PTID = getParsedTargetID(DriverArgs); + if (PTID.OptionalTargetID && !PTID.OptionalGPUArch) { + getDriver().Diag(clang::diag::err_drv_bad_target_id) + << PTID.OptionalTargetID.getValue(); + return; + } + + assert(PTID.OptionalFeatures && "Invalid return from getParsedTargetID"); + auto &FeatureMap = PTID.OptionalFeatures.getValue(); + // Sanitizer is not supported with xnack-. + if (DriverArgs.hasFlag(options::OPT_fgpu_sanitize, + options::OPT_fno_gpu_sanitize, false)) { + auto Loc = FeatureMap.find("xnack"); + if (Loc != FeatureMap.end() && !Loc->second) { + auto &Diags = getDriver().getDiags(); + auto DiagID = Diags.getCustomDiagID( + DiagnosticsEngine::Error, + "'-fgpu-sanitize' is not compatible with offload arch '%0'. " + "Use an offload arch without 'xnack-' instead"); + Diags.Report(DiagID) << PTID.OptionalTargetID.getValue(); + } + } +} diff --git a/clang/lib/Driver/ToolChains/HIP.h b/clang/lib/Driver/ToolChains/HIP.h index a9e1ed9a4656..3cced0a320dc 100644 --- a/clang/lib/Driver/ToolChains/HIP.h +++ b/clang/lib/Driver/ToolChains/HIP.h @@ -95,6 +95,7 @@ class LLVM_LIBRARY_VISIBILITY HIPToolChain final : public ROCMToolChain { unsigned GetDefaultDwarfVersion() const override { return 4; } const ToolChain &HostTC; + void checkTargetID(const llvm::opt::ArgList &DriverArgs) const override; protected: Tool *buildLinker() const override; diff --git a/clang/test/Driver/hip-sanitize-options.hip b/clang/test/Driver/hip-sanitize-options.hip index 19b09868213d..3b0328b5abc2 100644 --- a/clang/test/Driver/hip-sanitize-options.hip +++ b/clang/test/Driver/hip-sanitize-options.hip @@ -25,6 +25,11 @@ // RUN: -nogpuinc --rocm-path=%S/Inputs/rocm-invalid \ // RUN: %s 2>&1 | FileCheck -check-prefixes=FAIL %s +// RUN: %clang -### -target x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack- \ +// RUN: -fsanitize=address -fgpu-sanitize \ +// RUN: -nogpuinc --rocm-path=%S/Inputs/rocm \ +// RUN: %s 2>&1 | FileCheck -check-prefix=XNACK %s + // CHECK-NOT: {{"[^"]*clang[^"]*".* "-fcuda-is-device".* "-fsanitize=address"}} // CHECK-NOT: {{"[^"]*lld(\.exe){0,1}".* ".*hip.bc"}} // CHECK: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* "-fsanitize=address"}} @@ -38,3 +43,5 @@ // RDC: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" ".*hip.bc"}} // FAIL: AMDGPU address sanitizer runtime library (asanrtl) is not found. Please install ROCm device library which supports address sanitizer + +// XNACK: error: '-fgpu-sanitize' is not compatible with offload arch 'gfx900:xnack-'. Use an offload arch without 'xnack-' instead _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits