[clang] [NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (PR #107997)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 10 03:39:28 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang
Author: Amit Kumar Pandey (ampandey-1995)
<details>
<summary>Changes</summary>
HIPAMDToolChain and AMDGPUToolChain both depends on the "shouldSkipSanitizeOption" api to sanitize/not sanitize device code.
---
Full diff: https://github.com/llvm/llvm-project/pull/107997.diff
3 Files Affected:
- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+36)
- (modified) clang/lib/Driver/ToolChains/AMDGPU.h (+6)
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (-37)
``````````diff
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,
``````````
</details>
https://github.com/llvm/llvm-project/pull/107997
More information about the cfe-commits
mailing list