Skip to content

Commit 5dd1c82

Browse files
[NFC][AMDGPU][Driver] Move 'shouldSkipSanitizeOption' utility to AMDGPU. (#107997)
HIPAMDToolChain and AMDGPUOpenMPToolChain both depends on the "shouldSkipSanitizeOption" api to sanitize/not sanitize device code.
1 parent e610a0e commit 5dd1c82

File tree

3 files changed

+42
-37
lines changed

3 files changed

+42
-37
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,3 +1054,39 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
10541054
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
10551055
FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
10561056
}
1057+
1058+
bool AMDGPUToolChain::shouldSkipSanitizeOption(
1059+
const ToolChain &TC, const llvm::opt::ArgList &DriverArgs,
1060+
StringRef TargetID, const llvm::opt::Arg *A) const {
1061+
// For actions without targetID, do nothing.
1062+
if (TargetID.empty())
1063+
return false;
1064+
Option O = A->getOption();
1065+
if (!O.matches(options::OPT_fsanitize_EQ))
1066+
return false;
1067+
1068+
if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
1069+
options::OPT_fno_gpu_sanitize, true))
1070+
return true;
1071+
1072+
auto &Diags = TC.getDriver().getDiags();
1073+
1074+
// For simplicity, we only allow -fsanitize=address
1075+
SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
1076+
if (K != SanitizerKind::Address)
1077+
return true;
1078+
1079+
llvm::StringMap<bool> FeatureMap;
1080+
auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
1081+
1082+
assert(OptionalGpuArch && "Invalid Target ID");
1083+
(void)OptionalGpuArch;
1084+
auto Loc = FeatureMap.find("xnack");
1085+
if (Loc == FeatureMap.end() || !Loc->second) {
1086+
Diags.Report(
1087+
clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
1088+
<< A->getAsString(DriverArgs) << TargetID << "xnack+";
1089+
return true;
1090+
}
1091+
return false;
1092+
}

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
9797
/// Needed for translating LTO options.
9898
const char *getDefaultLinker() const override { return "ld.lld"; }
9999

100+
/// Should skip sanitize options.
101+
bool shouldSkipSanitizeOption(const ToolChain &TC,
102+
const llvm::opt::ArgList &DriverArgs,
103+
StringRef TargetID,
104+
const llvm::opt::Arg *A) const;
105+
100106
/// Uses amdgpu-arch tool to get arch of the system GPU. Will return error
101107
/// if unable to find one.
102108
virtual Expected<SmallVector<std::string>>

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,43 +36,6 @@ using namespace llvm::opt;
3636
#define NULL_FILE "/dev/null"
3737
#endif
3838

39-
static bool shouldSkipSanitizeOption(const ToolChain &TC,
40-
const llvm::opt::ArgList &DriverArgs,
41-
StringRef TargetID,
42-
const llvm::opt::Arg *A) {
43-
// For actions without targetID, do nothing.
44-
if (TargetID.empty())
45-
return false;
46-
Option O = A->getOption();
47-
if (!O.matches(options::OPT_fsanitize_EQ))
48-
return false;
49-
50-
if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
51-
options::OPT_fno_gpu_sanitize, true))
52-
return true;
53-
54-
auto &Diags = TC.getDriver().getDiags();
55-
56-
// For simplicity, we only allow -fsanitize=address
57-
SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
58-
if (K != SanitizerKind::Address)
59-
return true;
60-
61-
llvm::StringMap<bool> FeatureMap;
62-
auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
63-
64-
assert(OptionalGpuArch && "Invalid Target ID");
65-
(void)OptionalGpuArch;
66-
auto Loc = FeatureMap.find("xnack");
67-
if (Loc == FeatureMap.end() || !Loc->second) {
68-
Diags.Report(
69-
clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
70-
<< A->getAsString(DriverArgs) << TargetID << "xnack+";
71-
return true;
72-
}
73-
return false;
74-
}
75-
7639
void AMDGCN::Linker::constructLlvmLinkCommand(Compilation &C,
7740
const JobAction &JA,
7841
const InputInfoList &Inputs,

0 commit comments

Comments
 (0)