Skip to content

[SYCL] Fix device code instrumentation #4615

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
merged 14 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ CODEGENOPT(PassByValueIsNoAlias, 1, 0)
CODEGENOPT(AAPCSBitfieldWidth, 1, 1)

// Whether to instrument SPIR device code with ITT annotations
CODEGENOPT(SPIRITTAnnotations, 1, 0)
CODEGENOPT(SPIRITTAnnotations, 1, 1)

/// Sets the IEEE bit in the expected default floating point mode register.
/// Floating point opcodes that support exception flag gathering quiet and
Expand Down
12 changes: 3 additions & 9 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4660,6 +4660,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-fsycl-allow-func-ptr");
}

if (Triple.isSPIR())
CmdArgs.push_back("-fsycl-instrument-device-code");

if (!SYCLStdArg) {
// The user had not pass SYCL version, thus we'll employ no-sycl-strict
// to allow address-space unqualified pointers in function params/return
Expand Down Expand Up @@ -6404,15 +6407,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Forward -cl options to -cc1
RenderOpenCLOptions(Args, CmdArgs, InputType);

// Forward -fsycl-instrument-device-code option to cc1. This option can only
// be used with spir triple.
if (Arg *A = Args.getLastArg(options::OPT_fsycl_instrument_device_code)) {
if (!Triple.isSPIR())
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< A->getAsString(Args) << TripleStr;
CmdArgs.push_back("-fsycl-instrument-device-code");
}

if (IsHIP) {
if (Args.hasFlag(options::OPT_fhip_new_launch_api,
options::OPT_fno_hip_new_launch_api, true))
Expand Down
22 changes: 8 additions & 14 deletions clang/test/Driver/sycl-instrumentation.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/// Check that SPIR ITT instrumentation is disabled by default:
// RUN: %clang -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-DEFAULT %s
// CHECK-DEFAULT-NOT: "-fsycl-instrument-device-code"

/// Check if "fsycl_instrument_device_code" is passed to -cc1:
// RUN: %clang -### -fsycl-instrument-device-code %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-ENABLED %s
// CHECK-ENABLED: "-cc1"{{.*}} "-fsycl-instrument-device-code"

/// Check if "fsycl_instrument_device_code" usage with a non-spirv target
/// results in an error.
// RUN: %clang -### -fsycl-instrument-device-code --target=x86 %s 2>&1
// expected-error{{unsupported option '-fsycl-instrument-device-code' for target 'x86_64-unknown-linux-gnu'}}
/// Check if -fsycl-instrument-device-code is passed to device-side -cc1:
// RUN: %clangxx -fsycl -fsycl-targets=spir64 -### %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK-SPIRV,CHECK-HOST %s
// RUN: %clangxx -fsycl -fsycl-targets=nvptx-nvidia-cuda -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-NONSPIRV %s
// CHECK-SPIRV: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-fsycl-instrument-device-code"
// CHECK-HOST-NOT: "-cc1"{{.*}} "-fsycl-is-host"{{.*}} "-fsycl-instrument-device-code"
// CHECK-NONSPIRV-NOT: "-fsycl-instrument-device-code"