Skip to content
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

[DevTSAN] Support thread sanitizer for device offloading in sycl-tool-chain #17211

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions llvm/include/llvm/SYCLLowerIR/ComputeModuleRuntimeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct GlobalBinImageProps {
};
bool isModuleUsingAsan(const Module &M);
bool isModuleUsingMsan(const Module &M);
bool isModuleUsingTsan(const Module &M);
using PropSetRegTy = llvm::util::PropertySetRegistry;
using EntryPointSet = SetVector<Function *>;

Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ bool isModuleUsingMsan(const Module &M) {
return M.getNamedGlobal("__MsanKernelMetadata");
}

bool isModuleUsingTsan(const Module &M) {
return M.getNamedGlobal("__TsanKernelMetadata");
}

// This function traverses over reversed call graph by BFS algorithm.
// It means that an edge links some function @func with functions
// which contain call of function @func. It starts from
Expand Down Expand Up @@ -406,6 +410,8 @@ PropSetRegTy computeModuleProperties(const Module &M,
PropSet.add(PropSetRegTy::SYCL_MISC_PROP, "sanUsed", "asan");
else if (isModuleUsingMsan(M))
PropSet.add(PropSetRegTy::SYCL_MISC_PROP, "sanUsed", "msan");
else if (isModuleUsingTsan(M))
PropSet.add(PropSetRegTy::SYCL_MISC_PROP, "sanUsed", "tsan");
}

if (GlobProps.EmitDeviceGlobalPropSet) {
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/SYCLLowerIR/SanitizerKernelMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ PreservedAnalyses SanitizerKernelMetadataPass::run(Module &M,
if (!KernelMetadata)
KernelMetadata = M.getNamedGlobal("__MsanKernelMetadata");

if (!KernelMetadata)
KernelMetadata = M.getNamedGlobal("__TsanKernelMetadata");

if (!KernelMetadata)
return PreservedAnalyses::all();

Expand Down
15 changes: 15 additions & 0 deletions llvm/test/tools/sycl-post-link/device-sanitizer/tsan.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This test checks that the post-link tool properly generates "sanUsed=tsan"
; in [SYCL/misc properties], and fixes the attributes and metadata of @__TsanKernelMetadata

; RUN: sycl-post-link -properties -split=kernel -symbols -S < %s -o %t.table

; RUN: FileCheck %s -input-file=%t_0.prop --check-prefix CHECK-PROP
; CHECK-PROP: [SYCL/misc properties]
; CHECK-PROP: sanUsed=2|gAAAAAAAAAAdzFmb

; RUN: FileCheck %s -input-file=%t_0.ll --check-prefix CHECK-IR
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
target triple = "spir64-unknown-unknown"

@__TsanKernelMetadata = addrspace(1) global [1 x { i64, i64 }] [{ i64, i64 } { i64 0, i64 58 }]
; CHECK-IR: @__TsanKernelMetadata {{.*}} !spirv.Decorations
4 changes: 2 additions & 2 deletions llvm/tools/sycl-post-link/sycl-post-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,8 @@ processInputModule(std::unique_ptr<Module> M) {
if (M->getTargetTriple().find("spir") != std::string::npos)
Modified |= removeDeviceGlobalFromCompilerUsed(*M.get());

// MemorySanitizer specific passes
if (isModuleUsingAsan(*M) || isModuleUsingMsan(*M)) {
// Sanitizer specific passes
if (isModuleUsingAsan(*M) || isModuleUsingMsan(*M) || isModuleUsingTsan(*M)) {
// Fix attributes and metadata of KernelMetadata
Modified |= runModulePass<SanitizerKernelMetadataPass>(*M);
}
Expand Down
Loading