Skip to content

[SYCL][Driver] Enable device code instrumentation by default #5094

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -2663,10 +2663,10 @@ def fsycl_device_code_split_EQ : Joined<["-"], "fsycl-device-code-split=">,
def fsycl_device_code_split : Flag<["-"], "fsycl-device-code-split">, Alias<fsycl_device_code_split_EQ>,
AliasArgs<["auto"]>, Flags<[CC1Option, CoreOption]>,
HelpText<"Perform SYCL device code split in the 'auto' mode, i.e. use heuristic to distribute device code across modules">;
def fsycl_instrument_device_code : Flag<["-"], "fsycl-instrument-device-code">,
Group<sycl_Group>, Flags<[CC1Option, CoreOption]>,
HelpText<"Add ITT instrumentation intrinsics calls">,
MarshallingInfoFlag<CodeGenOpts<"SPIRITTAnnotations">>;
defm sycl_instrument_device_code : BoolFOption<"sycl-instrument-device-code",
CodeGenOpts<"SPIRITTAnnotations">, DefaultFalse,
PosFlag<SetTrue, [], "Add">, NegFlag<SetFalse, [], "Do not add">,
BothFlags<[CC1Option, CoreOption], " ITT instrumentation intrinsics calls">>;
defm sycl_id_queries_fit_in_int: BoolFOption<"sycl-id-queries-fit-in-int",
LangOpts<"SYCLValueFitInMaxInt">, DefaultTrue,
PosFlag<SetTrue, [], "Assume">, NegFlag<SetFalse, [], "Do not assume">,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ void EmitAssemblyHelper::EmitAssemblyWithLegacyPassManager(
// Add SPIRITTAnnotations pass to the pass manager if
// -fsycl-instrument-device-code option was passed. This option can be
// used only with spir triple.
if (CodeGenOpts.SPIRITTAnnotations) {
if (LangOpts.SYCLIsDevice && CodeGenOpts.SPIRITTAnnotations) {
if (!llvm::Triple(TheModule->getTargetTriple()).isSPIR())
llvm::report_fatal_error(
"ITT annotations can only by added to a module with spir target");
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4471,7 +4471,8 @@ class OffloadingActionBuilder final {
addInputs(sycl_device_wrapper_libs);
if (isSpirvAOT)
addInputs(sycl_device_fallback_libs);
if (Args.hasArg(options::OPT_fsycl_instrument_device_code))
if (Args.hasFlag(options::OPT_fsycl_instrument_device_code,
options::OPT_fno_sycl_instrument_device_code, true))
addInputs(sycl_device_annotation_libs);
return NumOfDeviceLibLinked != 0;
}
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4765,12 +4765,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,

// Forward -fsycl-instrument-device-code option to cc1. This option will
// only be used for SPIR-V-based targets.
if (Arg *A =
Args.getLastArgNoClaim(options::OPT_fsycl_instrument_device_code))
if (Triple.isSPIR()) {
A->claim();
if (Triple.isSPIR())
if (Args.hasFlag(options::OPT_fsycl_instrument_device_code,
options::OPT_fno_sycl_instrument_device_code, true))
CmdArgs.push_back("-fsycl-instrument-device-code");
}

if (!SYCLStdArg) {
// The user had not pass SYCL version, thus we'll employ no-sycl-strict
Expand Down
16 changes: 9 additions & 7 deletions clang/test/Driver/sycl-instrumentation.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/// and if ITT device libraries are pulled in.
/// The following conditions must be fulfilled:
/// 1. A SPIR-V-based environment must be targetted
/// 2. The corresponding Driver option must be enabled explicitly
/// 2. The option must not be explicitly disabled in the Driver call

/// FIXME: Force linux targets to allow for the libraries to be found. Dummy
/// inputs for --sysroot should be updated to work better for Windows.
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fsycl-instrument-device-code --sysroot=%S/Inputs/SYCL -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl --sysroot=%S/Inputs/SYCL -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-SPIRV,CHECK-HOST %s
/// -fno-sycl-device-lib mustn't affect the linkage of ITT libraries
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fsycl-instrument-device-code --sysroot=%S/Inputs/SYCL -fno-sycl-device-lib=all -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl --sysroot=%S/Inputs/SYCL -fno-sycl-device-lib=all -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-SPIRV %s

// CHECK-SPIRV: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-instrument-device-code"
Expand All @@ -19,10 +19,12 @@
// CHECK-SPIRV: llvm-link{{.*}} "-only-needed" "{{.*}}" "-o" "{{.*}}.bc" "--suppress-warnings"
// CHECK-HOST-NOT: "-cc1"{{.*}} "-fsycl-is-host"{{.*}} "-fsycl-instrument-device-code"

// RUN: %clangxx -fsycl -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: %clangxx -fsycl -fno-sycl-instrument-device-code -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-NONPASSED %s
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-NONPASSED %s
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -fsycl-instrument-device-code -nocudalib -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-WARNING,CHECK-NONPASSED %s
// CHECK-NONPASSED-NOT: "-fsycl-instrument-device-code"
// CHECK-NONPASSED-NOT: "-inputs={{.*}}libsycl-itt-{{.*}}.{{o|obj}}"
// CHECK-WARNING: warning: argument unused during compilation: '-fsycl-instrument-device-code'
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -fno-sycl-instrument-device-code -nocudalib -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-NONPASSED %s
// CHECK-WARNING: warning: argument unused during compilation: '-fno-sycl-instrument-device-code'