Skip to content

Commit d957299

Browse files
authored
[DevTSAN] Support thread sanitizer for device offloading in sycl-tool-chain (#17211)
This PR is going to support thread sanitizer for device offloading (sycl-tool-chain part) 1.defined a new helper function 'isModuleUsingTsan' 2.fix attribute for '__TsanKernelMetadata'
1 parent a9295c1 commit d957299

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

llvm/include/llvm/SYCLLowerIR/ComputeModuleRuntimeInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct GlobalBinImageProps {
3030
};
3131
bool isModuleUsingAsan(const Module &M);
3232
bool isModuleUsingMsan(const Module &M);
33+
bool isModuleUsingTsan(const Module &M);
3334
using PropSetRegTy = llvm::util::PropertySetRegistry;
3435
using EntryPointSet = SetVector<Function *>;
3536

llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ bool isModuleUsingMsan(const Module &M) {
5454
return M.getNamedGlobal("__MsanKernelMetadata");
5555
}
5656

57+
bool isModuleUsingTsan(const Module &M) {
58+
return M.getNamedGlobal("__TsanKernelMetadata");
59+
}
60+
5761
// This function traverses over reversed call graph by BFS algorithm.
5862
// It means that an edge links some function @func with functions
5963
// which contain call of function @func. It starts from
@@ -406,6 +410,8 @@ PropSetRegTy computeModuleProperties(const Module &M,
406410
PropSet.add(PropSetRegTy::SYCL_MISC_PROP, "sanUsed", "asan");
407411
else if (isModuleUsingMsan(M))
408412
PropSet.add(PropSetRegTy::SYCL_MISC_PROP, "sanUsed", "msan");
413+
else if (isModuleUsingTsan(M))
414+
PropSet.add(PropSetRegTy::SYCL_MISC_PROP, "sanUsed", "tsan");
409415
}
410416

411417
if (GlobProps.EmitDeviceGlobalPropSet) {

llvm/lib/SYCLLowerIR/SanitizerKernelMetadata.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ PreservedAnalyses SanitizerKernelMetadataPass::run(Module &M,
3232
if (!KernelMetadata)
3333
KernelMetadata = M.getNamedGlobal("__MsanKernelMetadata");
3434

35+
if (!KernelMetadata)
36+
KernelMetadata = M.getNamedGlobal("__TsanKernelMetadata");
37+
3538
if (!KernelMetadata)
3639
return PreservedAnalyses::all();
3740

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This test checks that the post-link tool properly generates "sanUsed=tsan"
2+
; in [SYCL/misc properties], and fixes the attributes and metadata of @__TsanKernelMetadata
3+
4+
; RUN: sycl-post-link -properties -split=kernel -symbols -S < %s -o %t.table
5+
6+
; RUN: FileCheck %s -input-file=%t_0.prop --check-prefix CHECK-PROP
7+
; CHECK-PROP: [SYCL/misc properties]
8+
; CHECK-PROP: sanUsed=2|gAAAAAAAAAAdzFmb
9+
10+
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefix CHECK-IR
11+
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"
12+
target triple = "spir64-unknown-unknown"
13+
14+
@__TsanKernelMetadata = addrspace(1) global [1 x { i64, i64 }] [{ i64, i64 } { i64 0, i64 58 }]
15+
; CHECK-IR: @__TsanKernelMetadata {{.*}} !spirv.Decorations

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,8 @@ processInputModule(std::unique_ptr<Module> M) {
800800
if (M->getTargetTriple().find("spir") != std::string::npos)
801801
Modified |= removeDeviceGlobalFromCompilerUsed(*M.get());
802802

803-
// MemorySanitizer specific passes
804-
if (isModuleUsingAsan(*M) || isModuleUsingMsan(*M)) {
803+
// Sanitizer specific passes
804+
if (isModuleUsingAsan(*M) || isModuleUsingMsan(*M) || isModuleUsingTsan(*M)) {
805805
// Fix attributes and metadata of KernelMetadata
806806
Modified |= runModulePass<SanitizerKernelMetadataPass>(*M);
807807
}

0 commit comments

Comments
 (0)