Skip to content

Commit 22864f0

Browse files
authored
[Driver][SYCL] Do not pass coverage and profiling opts to device compile (#12056)
When building with profiling or code coverage options, do not enable these passes for the device compilation. When used, and additional diagnostic will be emitted stating how the options is not being used for the given target. Example: clang++ -fprofile-instr-generate -fsycl file.cpp clang++: warning: ignoring '-fprofile-instr-generate' option as it is not currently supported for target 'spir64-unknown-unknown' [-Woption-ignored]
1 parent 5ac2799 commit 22864f0

File tree

2 files changed

+88
-28
lines changed

2 files changed

+88
-28
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,35 @@ void SYCL::x86_64::BackendCompiler::ConstructJob(
10081008
C.addCommand(std::move(Cmd));
10091009
}
10101010

1011+
// Unsupported options for device compilation
1012+
// -fcf-protection, -fsanitize, -fprofile-generate, -fprofile-instr-generate
1013+
// -ftest-coverage, -fcoverage-mapping, -fcreate-profile, -fprofile-arcs
1014+
// -fcs-profile-generate -forder-file-instrumentation
1015+
static std::vector<OptSpecifier> getUnsupportedOpts(void) {
1016+
std::vector<OptSpecifier> UnsupportedOpts = {
1017+
options::OPT_fsanitize_EQ,
1018+
options::OPT_fcf_protection_EQ,
1019+
options::OPT_fprofile_generate,
1020+
options::OPT_fprofile_generate_EQ,
1021+
options::OPT_fno_profile_generate,
1022+
options::OPT_ftest_coverage,
1023+
options::OPT_fno_test_coverage,
1024+
options::OPT_fcoverage_mapping,
1025+
options::OPT_fno_coverage_mapping,
1026+
options::OPT_fprofile_instr_generate,
1027+
options::OPT_fprofile_instr_generate_EQ,
1028+
options::OPT_fprofile_arcs,
1029+
options::OPT_fno_profile_arcs,
1030+
options::OPT_fno_profile_instr_generate,
1031+
options::OPT_fcreate_profile,
1032+
options::OPT_fprofile_instr_use,
1033+
options::OPT_fprofile_instr_use_EQ,
1034+
options::OPT_forder_file_instrumentation,
1035+
options::OPT_fcs_profile_generate,
1036+
options::OPT_fcs_profile_generate_EQ};
1037+
return UnsupportedOpts;
1038+
}
1039+
10111040
SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
10121041
const ToolChain &HostTC, const ArgList &Args)
10131042
: ToolChain(D, Triple, Args), HostTC(HostTC),
@@ -1017,17 +1046,19 @@ SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
10171046
getProgramPaths().push_back(getDriver().Dir);
10181047

10191048
// Diagnose unsupported options only once.
1020-
// All sanitizer options are not currently supported, except AddressSanitizer
1021-
for (auto *A : Args.filtered(options::OPT_fsanitize_EQ,
1022-
options::OPT_fcf_protection_EQ)) {
1023-
if (A->getOption().getID() == options::OPT_fsanitize_EQ &&
1024-
A->getValues().size() == 1) {
1025-
std::string SanitizeVal = A->getValue();
1026-
if (SanitizeVal == "address")
1027-
continue;
1049+
for (OptSpecifier Opt : getUnsupportedOpts()) {
1050+
if (const Arg *A = Args.getLastArg(Opt)) {
1051+
// All sanitizer options are not currently supported, except
1052+
// AddressSanitizer
1053+
if (A->getOption().getID() == options::OPT_fsanitize_EQ &&
1054+
A->getValues().size() == 1) {
1055+
std::string SanitizeVal = A->getValue();
1056+
if (SanitizeVal == "address")
1057+
continue;
1058+
}
1059+
D.Diag(clang::diag::warn_drv_unsupported_option_for_target)
1060+
<< A->getAsString(Args) << getTriple().str();
10281061
}
1029-
D.getDiags().Report(clang::diag::warn_drv_unsupported_option_for_target)
1030-
<< A->getAsString(Args) << getTriple().str();
10311062
}
10321063
}
10331064

@@ -1053,27 +1084,27 @@ SYCLToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
10531084
for (Arg *A : Args) {
10541085
// Filter out any options we do not want to pass along to the device
10551086
// compilation.
1056-
auto Opt(A->getOption().getID());
1057-
switch (Opt) {
1058-
case options::OPT_fsanitize_EQ:
1059-
if (A->getValues().size() == 1) {
1060-
std::string SanitizeVal = A->getValue();
1061-
if (SanitizeVal == "address") {
1062-
if (IsNewDAL)
1063-
DAL->append(A);
1064-
continue;
1087+
auto Opt(A->getOption());
1088+
bool Unsupported = false;
1089+
for (OptSpecifier UnsupportedOpt : getUnsupportedOpts()) {
1090+
if (Opt.matches(UnsupportedOpt)) {
1091+
if (A->getValues().size() == 1) {
1092+
std::string SanitizeVal = A->getValue();
1093+
if (SanitizeVal == "address") {
1094+
if (IsNewDAL)
1095+
DAL->append(A);
1096+
continue;
1097+
}
10651098
}
1099+
if (!IsNewDAL)
1100+
DAL->eraseArg(Opt.getID());
1101+
Unsupported = true;
10661102
}
1067-
[[fallthrough]];
1068-
case options::OPT_fcf_protection_EQ:
1069-
if (!IsNewDAL)
1070-
DAL->eraseArg(Opt);
1071-
break;
1072-
default:
1073-
if (IsNewDAL)
1074-
DAL->append(A);
1075-
break;
10761103
}
1104+
if (Unsupported)
1105+
continue;
1106+
if (IsNewDAL)
1107+
DAL->append(A);
10771108
}
10781109
// Strip out -O0 for FPGA Hardware device compilation.
10791110
if (getDriver().IsFPGAHWMode() &&

clang/test/Driver/sycl-unsupported.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,35 @@
1111
// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64 -fcf-protection -### %s 2>&1 \
1212
// RUN: | FileCheck %s -DARCH=spir64_x86_64 -DOPT=-fcf-protection
1313

14+
// RUN: %clangxx -fsycl -fprofile-instr-generate -### %s 2>&1 \
15+
// RUN: | FileCheck %s -DARCH=spir64 -DOPT=-fprofile-instr-generate \
16+
// RUN: -DOPT_CC1=-fprofile-instrument=clang \
17+
// RUN: -check-prefixes=UNSUPPORTED_OPT_DIAG,UNSUPPORTED_OPT
18+
// RUN: %clangxx -fsycl -fcoverage-mapping \
19+
// RUN: -fprofile-instr-generate -### %s 2>&1 \
20+
// RUN: | FileCheck %s -DARCH=spir64 -DOPT=-fcoverage-mapping
21+
// RUN: %clangxx -fsycl -ftest-coverage -### %s 2>&1 \
22+
// RUN: | FileCheck %s -DARCH=spir64 -DOPT=-ftest-coverage \
23+
// RUN: -DOPT_CC1=-coverage-notes-file \
24+
// RUN: -check-prefixes=UNSUPPORTED_OPT_DIAG,UNSUPPORTED_OPT
25+
// RUN: %clangxx -fsycl -fcreate-profile -### %s 2>&1 \
26+
// RUN: | FileCheck %s -DARCH=spir64 -DOPT=-fcreate-profile \
27+
// RUN: -check-prefix UNSUPPORTED_OPT_DIAG
28+
// RUN: %clangxx -fsycl -fprofile-arcs -### %s 2>&1 \
29+
// RUN: | FileCheck %s -DARCH=spir64 -DOPT=-fprofile-arcs \
30+
// RUN: -DOPT_CC1=-coverage-data-file \
31+
// RUN: -check-prefixes=UNSUPPORTED_OPT_DIAG,UNSUPPORTED_OPT
32+
// RUN: %clangxx -fsycl -fcs-profile-generate -### %s 2>&1 \
33+
// RUN: | FileCheck %s -DARCH=spir64 -DOPT=-fcs-profile-generate \
34+
// RUN: -DOPT_CC1=-fprofile-instrument=csllvm \
35+
// RUN: -check-prefixes=UNSUPPORTED_OPT_DIAG,UNSUPPORTED_OPT
36+
// RUN: %clangxx -fsycl -forder-file-instrumentation -### %s 2>&1 \
37+
// RUN: | FileCheck %s -DARCH=spir64 -DOPT=-forder-file-instrumentation
38+
1439
// CHECK: ignoring '[[OPT]]' option as it is not currently supported for target '[[ARCH]]{{.*}}' [-Woption-ignored]
1540
// CHECK-NOT: clang{{.*}} "-fsycl-is-device"{{.*}} "[[OPT]]{{.*}}"
1641
// CHECK: clang{{.*}} "-fsycl-is-host"{{.*}} "[[OPT]]{{.*}}"
42+
43+
// UNSUPPORTED_OPT_DIAG: ignoring '[[OPT]]' option as it is not currently supported for target '[[ARCH]]{{.*}}' [-Woption-ignored]
44+
// UNSUPPORTED_OPT-NOT: clang{{.*}} "-fsycl-is-device"{{.*}} "[[OPT_CC1]]{{.*}}"
45+
// UNSUPPORTED_OPT: clang{{.*}} "-fsycl-is-host"{{.*}} "[[OPT_CC1]]{{.*}}"

0 commit comments

Comments
 (0)