Skip to content

Commit 577e562

Browse files
committed
Merge branch 'sycl' into llvmspirv_pulldown
Conflicts: sycl/test/check_device_code/vector/vector_bf16_builtins_preview.cpp sycl/test/check_device_code/vector/vector_convert_bfloat_preview.cpp sycl/test/check_device_code/vector/vector_math_ops_preview.cpp
2 parents e40b162 + 1e0c021 commit 577e562

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+863
-244
lines changed

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,13 +1278,25 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
12781278

12791279
CmdArgs.push_back("-mllvm");
12801280
CmdArgs.push_back("-msan-eager-checks=1");
1281+
} else if (Sanitizers.has(SanitizerKind::Thread)) {
1282+
CmdArgs.push_back("-fsanitize=thread");
1283+
// The tsan function entry/exit builtins are used to record stack
1284+
// position, we don't need them in device offloading.
1285+
CmdArgs.push_back("-mllvm");
1286+
CmdArgs.push_back("-tsan-instrument-func-entry-exit=0");
1287+
// In device offloading, user can't call memory instrinsics explicitly, so
1288+
// we can safely skip them.
1289+
CmdArgs.push_back("-mllvm");
1290+
CmdArgs.push_back("-tsan-instrument-memintrinsics=0");
12811291
}
12821292
#else // _WIN32
12831293
std::string SanitizeArg;
12841294
if (Sanitizers.has(SanitizerKind::Address))
12851295
SanitizeArg = "-fsanitize=address";
12861296
else if (Sanitizers.has(SanitizerKind::Memory))
12871297
SanitizeArg = "-fsanitize=memory";
1298+
else if (Sanitizers.has(SanitizerKind::Thread))
1299+
SanitizeArg = "-fsanitize=thread";
12881300

12891301
if (!SanitizeArg.empty())
12901302
TC.getDriver().Diag(diag::warn_drv_unsupported_option_for_target)

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
618618
// For DG2, we just use libsycl-msan as placeholder.
619619
{"libsycl-msan", "internal"},
620620
{"libsycl-msan-pvc", "internal"}};
621+
const SYCLDeviceLibsList SYCLDeviceTsanLibs = {{"libsycl-tsan", "internal"}};
621622
#endif
622623

623624
const SYCLDeviceLibsList SYCLNativeCpuDeviceLibs = {
@@ -758,8 +759,9 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
758759
SyclFEEQArgVals.end());
759760
ArgVals.insert(ArgVals.end(), ArchDeviceVals.begin(), ArchDeviceVals.end());
760761

761-
// Driver will report error if address sanitizer and memory sanitizer are
762-
// both enabled, so we only need to check first one here.
762+
// Driver will report error if more than one of address sanitizer, memory
763+
// sanitizer or thread sanitizer is enabled, so we only need to check first
764+
// one here.
763765
for (const std::string &Arg : ArgVals) {
764766
if (Arg.find("-fsanitize=address") != std::string::npos) {
765767
SanitizeVal = "address";
@@ -769,13 +771,19 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
769771
SanitizeVal = "memory";
770772
break;
771773
}
774+
if (Arg.find("-fsanitize=thread") != std::string::npos) {
775+
SanitizeVal = "thread";
776+
break;
777+
}
772778
}
773779
}
774780

775781
if (SanitizeVal == "address")
776782
addSingleLibrary(SYCLDeviceAsanLibs[sanitizer_lib_idx]);
777783
else if (SanitizeVal == "memory")
778784
addSingleLibrary(SYCLDeviceMsanLibs[sanitizer_lib_idx]);
785+
else if (SanitizeVal == "thread")
786+
addLibraries(SYCLDeviceTsanLibs);
779787
#endif
780788

781789
if (isNativeCPU)
@@ -898,6 +906,7 @@ static llvm::SmallVector<StringRef, 16> SYCLDeviceLibList{
898906
"msan",
899907
"msan-pvc",
900908
"msan-cpu",
909+
"tsan",
901910
#endif
902911
"imf",
903912
"imf-fp64",
@@ -1739,11 +1748,12 @@ SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple,
17391748
if (SupportedByNativeCPU(*this, Opt))
17401749
continue;
17411750
// All sanitizer options are not currently supported, except
1742-
// AddressSanitizer and MemorySanitizer
1751+
// AddressSanitizer and MemorySanitizer and ThreadSanitizer
17431752
if (A->getOption().getID() == options::OPT_fsanitize_EQ &&
17441753
A->getValues().size() == 1) {
17451754
std::string SanitizeVal = A->getValue();
1746-
if (SanitizeVal == "address" || SanitizeVal == "memory")
1755+
if (SanitizeVal == "address" || SanitizeVal == "memory" ||
1756+
SanitizeVal == "thread")
17471757
continue;
17481758
}
17491759
D.Diag(clang::diag::warn_drv_unsupported_option_for_target)
@@ -1784,7 +1794,8 @@ SYCLToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
17841794
if (Opt.getID() == options::OPT_fsanitize_EQ &&
17851795
A->getValues().size() == 1) {
17861796
std::string SanitizeVal = A->getValue();
1787-
if (SanitizeVal == "address" || SanitizeVal == "memory") {
1797+
if (SanitizeVal == "address" || SanitizeVal == "memory" ||
1798+
SanitizeVal == "thread") {
17881799
if (IsNewDAL)
17891800
DAL->append(A);
17901801
continue;
@@ -2202,5 +2213,5 @@ void SYCLToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
22022213
}
22032214

22042215
SanitizerMask SYCLToolChain::getSupportedSanitizers() const {
2205-
return SanitizerKind::Address | SanitizerKind::Memory;
2216+
return SanitizerKind::Address | SanitizerKind::Memory | SanitizerKind::Thread;
22062217
}

clang/test/Driver/Inputs/SYCL/lib/libsycl-tsan.bc

Whitespace-only changes.

clang/test/Driver/sycl-device-lib-old-model.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,40 @@
378378
// RUN: -Xarch_device -fsanitize=memory -### 2>&1 | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_MSAN_CPU
379379
// SYCL_DEVICE_LIB_MSAN_CPU: llvm-link{{.*}} "-only-needed" "{{.*}}libsycl-crt.bc"
380380
// SYCL_DEVICE_LIB_MSAN_CPU-SAME: "{{.*}}libsycl-msan-cpu.bc"
381+
382+
/// ###########################################################################
383+
/// test behavior of libsycl-tsan.bc linking when -fsanitize=thread is available
384+
// RUN: %clangxx -fsycl --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL -fsanitize=thread -### 2>&1 \
385+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
386+
// RUN: %clangxx -fsycl --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xsycl-target-frontend -fsanitize=thread -### 2>&1 \
387+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
388+
// RUN: %clangxx -fsycl --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xsycl-target-frontend=spir64 -fsanitize=thread -### 2>&1 \
389+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
390+
// RUN: %clangxx -fsycl --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xarch_device -fsanitize=thread -### 2>&1 \
391+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
392+
// RUN: %clangxx -fsycl --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xarch_device "-fsanitize=thread -DUSE_SYCL_DEVICE_TSAN" -### 2>&1 \
393+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
394+
// RUN: %clangxx -fsycl --no-offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xarch_device "-fsanitize=thread -DUSE_SYCL_DEVICE_TSAN" -### 2>&1 \
395+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_TSAN_MACRO
396+
// SYCL_DEVICE_LIB_TSAN: llvm-link{{.*}} "{{.*}}libsycl-crt.bc"
397+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-complex.bc"
398+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-complex-fp64.bc"
399+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-cmath.bc"
400+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-cmath-fp64.bc"
401+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-imf.bc"
402+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-imf-fp64.bc"
403+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-imf-bf16.bc"
404+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-fallback-cassert.bc"
405+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-fallback-cstring.bc"
406+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-fallback-complex.bc"
407+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-fallback-complex-fp64.bc"
408+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-fallback-cmath.bc"
409+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-fallback-cmath-fp64.bc"
410+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-fallback-imf.bc"
411+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-fallback-imf-fp64.bc"
412+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-fallback-imf-bf16.bc"
413+
// SYCL_DEVICE_LIB_TSAN-SAME: "{{.*}}libsycl-tsan.bc"
414+
// SYCL_DEVICE_TSAN_MACRO: "-cc1"
415+
// SYCL_DEVICE_TSAN_MACRO-SAME: "USE_SYCL_DEVICE_TSAN"
416+
// SYCL_DEVICE_TSAN_MACRO: llvm-link{{.*}} "-only-needed"
417+
// SYCL_DEVICE_TSAN_MACRO-SAME: "{{.*}}libsycl-tsan.bc"

clang/test/Driver/sycl-device-lib.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,39 @@
365365
// SYCL_DEVICE_LIB_MSAN_CPU: clang-linker-wrapper{{.*}} "-sycl-device-libraries
366366
// SYCL_DEVICE_LIB_MSAN_CPU-SAME: {{.*}}libsycl-msan-cpu.new.o
367367

368+
/// ###########################################################################
369+
/// test behavior of libsycl-tsan.o linking when -fsanitize=thread is available
370+
// RUN: %clangxx -fsycl --offload-new-driver %s --sysroot=%S/Inputs/SYCL -fsanitize=thread -### 2>&1 \
371+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
372+
// RUN: %clangxx -fsycl --offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xsycl-target-frontend -fsanitize=thread -### 2>&1 \
373+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
374+
// RUN: %clangxx -fsycl --offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xsycl-target-frontend=spir64 -fsanitize=thread -### 2>&1 \
375+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
376+
// RUN: %clangxx -fsycl --offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xarch_device -fsanitize=thread -### 2>&1 \
377+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
378+
// RUN: %clangxx -fsycl --offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xarch_device "-fsanitize=thread -DUSE_SYCL_DEVICE_TSAN" -### 2>&1 \
379+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_TSAN
380+
// RUN: %clangxx -fsycl --offload-new-driver %s --sysroot=%S/Inputs/SYCL -Xarch_device "-fsanitize=thread -DUSE_SYCL_DEVICE_TSAN" -### 2>&1 \
381+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_TSAN_MACRO
382+
// SYCL_DEVICE_LIB_TSAN: clang-linker-wrapper{{.*}} "-sycl-device-libraries
383+
// SYCL_DEVICE_LIB_TSAN: {{.*}}libsycl-crt.new.o
384+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-complex.
385+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-complex-fp64.
386+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-cmath.new.o
387+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-cmath-fp64.new.o
388+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-imf.new.o
389+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-imf-fp64.new.o
390+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-imf-bf16.new.o
391+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-fallback-cassert.new.o
392+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-fallback-cstring.new.o
393+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-fallback-complex.new.o
394+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-fallback-complex-fp64.new.o
395+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-fallback-cmath.new.o
396+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-fallback-cmath-fp64.new.o
397+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-fallback-imf.new.o
398+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-fallback-imf-fp64.new.o
399+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-fallback-imf-bf16.new.o
400+
// SYCL_DEVICE_LIB_TSAN-SAME: {{.*}}libsycl-tsan.new.o
401+
// SYCL_DEVICE_TSAN_MACRO: "-cc1"
402+
// SYCL_DEVICE_TSAN_MACRO-SAME: "USE_SYCL_DEVICE_TSAN"
403+
// SYCL_DEVICE_TSAN_MACRO: libsycl-tsan.new.o

clang/test/Driver/sycl-device-sanitizer-win.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@
2222
// RUN: | FileCheck --check-prefix=SYCL-MSAN %s
2323

2424
// SYCL-MSAN: ignoring '-fsanitize=memory' option as it is not currently supported for target 'spir64-unknown-unknown'
25+
26+
/// ###########################################################################
27+
28+
// We need to add "not" here since "error: unsupported option '-fsanitize=thread' for target 'x86_64-pc-windows-msvc'"
29+
// RUN: not %clangxx -fsycl -fsanitize=thread -c %s -### 2>&1 \
30+
// RUN: | FileCheck --check-prefix=SYCL-TSAN %s
31+
// RUN: %clangxx -fsycl -Xarch_device -fsanitize=thread -c %s -### 2>&1 \
32+
// RUN: | FileCheck --check-prefix=SYCL-TSAN %s
33+
34+
// SYCL-TSAN: ignoring '-fsanitize=thread' option as it is not currently supported for target 'spir64-unknown-unknown'

clang/test/Driver/sycl-device-sanitizer.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,17 @@
5252
// RUN: | FileCheck --check-prefix=SYCL-MSAN-XARCH-DEVICE %s
5353
// SYCL-MSAN-XARCH-DEVICE: clang{{.*}} "-fsycl-is-device"
5454
// SYCL-MSAN-XARCH-DEVICE-SAME: -fsanitize=memory
55+
56+
/// ###########################################################################
57+
58+
// RUN: %clangxx -fsycl -fsanitize=thread -c %s -### 2>&1 \
59+
// RUN: | FileCheck --check-prefix=SYCL-TSAN %s
60+
// SYCL-TSAN: clang{{.*}} "-fsycl-is-device"
61+
// SYCL-TSAN-SAME: -fsanitize=thread
62+
// SYCL-TSAN-SAME: "-mllvm" "-tsan-instrument-func-entry-exit=0"
63+
// SYCL-TSAN-SAME: "-mllvm" "-tsan-instrument-memintrinsics=0"
64+
65+
// RUN: %clangxx -fsycl -Xarch_device -fsanitize=thread -c %s -### 2>&1 \
66+
// RUN: | FileCheck --check-prefix=SYCL-TSAN-XARCH-DEVICE %s
67+
// SYCL-TSAN-XARCH-DEVICE: clang{{.*}} "-fsycl-is-device"
68+
// SYCL-TSAN-XARCH-DEVICE-SAME: -fsanitize=thread

libclc/libspirv/lib/generic/math/acosh.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __spirv_ocl_acosh, double)
118118

119119
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
120120

121-
_CLC_DEFINE_UNARY_BUILTIN_SCALARIZE(half, __spirv_ocl_acosh, __builtin_acosh, half)
121+
_CLC_DEFINE_UNARY_BUILTIN_SCALARIZE(half, __spirv_ocl_acosh, __builtin_acoshf, half)
122122

123123
#endif

libclc/libspirv/lib/generic/math/asinh.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,6 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __spirv_ocl_asinh, double)
366366

367367
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
368368

369-
_CLC_DEFINE_UNARY_BUILTIN_SCALARIZE(half, __spirv_ocl_asinh, __builtin_asinh, half)
369+
_CLC_DEFINE_UNARY_BUILTIN_SCALARIZE(half, __spirv_ocl_asinh, __builtin_asinhf, half)
370370

371371
#endif

libclc/libspirv/lib/generic/math/atan.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, __spirv_ocl_atan, double);
178178

179179
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
180180

181-
_CLC_DEFINE_UNARY_BUILTIN_SCALARIZE(half, __spirv_ocl_atan, __builtin_atan, half)
181+
_CLC_DEFINE_UNARY_BUILTIN_SCALARIZE(half, __spirv_ocl_atan, __builtin_atanf16, half)
182182

183183
#endif

0 commit comments

Comments
 (0)