-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. #107997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-backend-amdgpu @llvm/pr-subscribers-clang Author: Amit Kumar Pandey (ampandey-1995) ChangesHIPAMDToolChain 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:
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,
|
4a9c7b7
to
4c6b015
Compare
HIPAMDToolChain and AMDGPUOpenMPToolChain both depends on the "shouldSkipSanitizeOption" api to sanitize/not sanitize device code.
4c6b015
to
01e86b9
Compare
yxsamliu
approved these changes
Sep 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
backend:AMDGPU
clang:driver
'clang' and 'clang++' user-facing binaries. Not 'clang-cl'
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
HIPAMDToolChain and AMDGPUOpenMPToolChain both depends on the "shouldSkipSanitizeOption" api to sanitize/not sanitize device code.