-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][NATIVECPU] Enable source-based code coverage in Native CPU (#1…
…5073) Supports [clang's source-based code coverage](https://clang.llvm.org/docs/SourceBasedCodeCoverage.html) to enable code coverage testing of SYCL applications via the Native CPU SYCL target. Clang's `-fprofile-instr-generate -fcoverage-mapping` options can now be used with the `native_cpu` SYCL target to compile/instrument host and device code, enabling 'llvm-cov' to render a coverage report after running the SYCL application (see also updated documentation in this PR). Subsequent PRs will enable in NativeCPU more of the currently unsupported options for device compilation, also for performance profiling. **Details and explanations for the changes in this PR:** This PR tests coverage options on the existing NativeCPU vector-add test by adding an additional invocation with previously disabled options `-fprofile-instr-generate -fcoverage-mapping -mllvm -system-headers-coverage`. Enabling these options on device code caused an [assert in the upstream clang profiling code generation tools](https://github.com/intel/llvm/blob/b023d407862bd853ba5881c34985f99d039d856c/clang/lib/CodeGen/CoverageMappingGen.cpp#L960) due to the invalid source location on the AST for the implicitly generated kernel body, specifically the compound statement containing the kernel body. This PR honors this upstream clang assert by replacing the invalid source location in the compound statement with the source location of the kernel body. Using this now valid source location maintains the location (of the kernel caller function) currently tested by [non-upstream-llvm lit test `CodeGenSYCL/debug-info-srcpos-kernel.cpp`](https://github.com/intel/llvm/blob/sycl/clang/test/CodeGenSYCL/debug-info-srcpos-kernel.cpp), but exposed an issue that led to a change in behavior in [non-llvm-upstream lit test `SemaSYCL/kernel-arg-opt-report.cpp`](https://github.com/intel/llvm/blob/sycl/clang/test/SemaSYCL/kernel-arg-opt-report.cpp), which was due to the previously invalid source location causing the compiler to skip code to set the current location. To restore the original behavior of this test (checking for the location of the kernel functor, as opposed to the kernel caller function) this PR temporarily (and only for the purpose of generating the report) sets the current location to the location of the kernel argument using the upstream clang utility [clang::CodeGen::ApplyDebugLocation](https://github.com/intel/llvm/blob/b023d407862bd853ba5881c34985f99d039d856c/clang/lib/CodeGen/CGDebugInfo.h#L860). --------- Co-authored-by: Michael Toguchi <[email protected]>
- Loading branch information
1 parent
77abc08
commit 9b9e5de
Showing
7 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -ast-dump %s | FileCheck %s | ||
// | ||
// Checks that the compound statement of the implicitly generated kernel body | ||
// has a valid source location (containing "line"). Previously this location | ||
// was invalid containing "<<invalid sloc>>" which causes asserts in the | ||
// llvm profiling tools. | ||
|
||
#include "Inputs/sycl.hpp" | ||
|
||
struct Functor { | ||
void operator()() const {} | ||
}; | ||
|
||
// CHECK: FunctionDecl {{.*}} _ZTS7Functor 'void ()' | ||
// CHECK-NEXT: |-CompoundStmt {{.*}} <{{.*}}line{{.*}}> | ||
|
||
int main() { | ||
|
||
sycl::queue().submit([&](sycl::handler &cgh) { | ||
cgh.single_task(Functor{}); | ||
}); | ||
} |
This file contains 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
This file contains 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