[clang] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (PR #107997)
Amit Kumar Pandey via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 10 03:40:20 PDT 2024
https://github.com/ampandey-1995 updated https://github.com/llvm/llvm-project/pull/107997
>From 4c6b015445e5820d8b09db0d3b4dba23f1413c77 Mon Sep 17 00:00:00 2001
From: Amit Pandey <pandey.kumaramit2023 at gmail.com>
Date: Tue, 10 Sep 2024 15:53:28 +0530
Subject: [PATCH] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility
to AMDGPU.
HIPAMDToolChain and AMDGPUOpenMPToolChain both depends on the
"shouldSkipSanitizeOption" api to sanitize/not sanitize device code.
---
clang/lib/Driver/ToolChains/AMDGPU.cpp | 36 +++++++++++++++++++++++++
clang/lib/Driver/ToolChains/AMDGPU.h | 6 +++++
clang/lib/Driver/ToolChains/HIPAMD.cpp | 37 --------------------------
3 files changed, 42 insertions(+), 37 deletions(-)
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index a788aba57546c8..74f70573c5feb8 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -1054,3 +1054,39 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
}
+
+bool AMDGPUToolChain::shouldSkipSanitizeOption(
+ const ToolChain &TC, const llvm::opt::ArgList &DriverArgs,
+ StringRef TargetID, const llvm::opt::Arg *A) const {
+ // For actions without targetID, do nothing.
+ if (TargetID.empty())
+ return false;
+ Option O = A->getOption();
+ if (!O.matches(options::OPT_fsanitize_EQ))
+ return false;
+
+ if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
+ options::OPT_fno_gpu_sanitize, true))
+ return true;
+
+ auto &Diags = TC.getDriver().getDiags();
+
+ // For simplicity, we only allow -fsanitize=address
+ SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
+ if (K != SanitizerKind::Address)
+ return true;
+
+ llvm::StringMap<bool> FeatureMap;
+ auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
+
+ assert(OptionalGpuArch && "Invalid Target ID");
+ (void)OptionalGpuArch;
+ auto Loc = FeatureMap.find("xnack");
+ if (Loc == FeatureMap.end() || !Loc->second) {
+ Diags.Report(
+ clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
+ << A->getAsString(DriverArgs) << TargetID << "xnack+";
+ return true;
+ }
+ return false;
+}
\ No newline at end of file
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h
index 7e70dae8ce152e..a9b4552a1f91a4 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -97,6 +97,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
/// Needed for translating LTO options.
const char *getDefaultLinker() const override { return "ld.lld"; }
+ /// Should skip sanitize options.
+ bool shouldSkipSanitizeOption(const ToolChain &TC,
+ const llvm::opt::ArgList &DriverArgs,
+ StringRef TargetID,
+ const llvm::opt::Arg *A) const;
+
/// Uses amdgpu-arch tool to get arch of the system GPU. Will return error
/// if unable to find one.
virtual Expected<SmallVector<std::string>>
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index cbb8fab69a316d..bae05cc0bb7353 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -36,43 +36,6 @@ using namespace llvm::opt;
#define NULL_FILE "/dev/null"
#endif
-static bool shouldSkipSanitizeOption(const ToolChain &TC,
- const llvm::opt::ArgList &DriverArgs,
- StringRef TargetID,
- const llvm::opt::Arg *A) {
- // For actions without targetID, do nothing.
- if (TargetID.empty())
- return false;
- Option O = A->getOption();
- if (!O.matches(options::OPT_fsanitize_EQ))
- return false;
-
- if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
- options::OPT_fno_gpu_sanitize, true))
- return true;
-
- auto &Diags = TC.getDriver().getDiags();
-
- // For simplicity, we only allow -fsanitize=address
- SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
- if (K != SanitizerKind::Address)
- return true;
-
- llvm::StringMap<bool> FeatureMap;
- auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
-
- assert(OptionalGpuArch && "Invalid Target ID");
- (void)OptionalGpuArch;
- auto Loc = FeatureMap.find("xnack");
- if (Loc == FeatureMap.end() || !Loc->second) {
- Diags.Report(
- clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
- << A->getAsString(DriverArgs) << TargetID << "xnack+";
- return true;
- }
- return false;
-}
-
void AMDGCN::Linker::constructLlvmLinkCommand(Compilation &C,
const JobAction &JA,
const InputInfoList &Inputs,
More information about the cfe-commits
mailing list