Skip to content

Commit ea9d379

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents 9fab5e1 + ff48612 commit ea9d379

File tree

30 files changed

+1038
-191
lines changed

30 files changed

+1038
-191
lines changed

clang/include/clang/Driver/Driver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class Driver {
7979

8080
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
8181

82+
bool DumpDeviceCode;
83+
8284
enum DriverMode {
8385
GCCMode,
8486
GXXMode,
@@ -420,6 +422,7 @@ class Driver {
420422
return Dir.c_str();
421423
}
422424
void setInstalledDir(StringRef Value) { InstalledDir = std::string(Value); }
425+
bool isDumpDeviceCodeEnabled() const { return DumpDeviceCode; }
423426

424427
bool isSaveTempsEnabled() const { return SaveTemps != SaveTempsNone; }
425428
bool isSaveTempsObj() const { return SaveTemps == SaveTempsObj; }

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5562,6 +5562,9 @@ def regcall4 : Flag<["-"], "regcall4">, Group<m_Group>,
55625562
Visibility<[ClangOption, CC1Option]>,
55635563
HelpText<"Set __regcall4 as a default calling convention to respect __regcall ABI v.4">,
55645564
MarshallingInfoFlag<LangOpts<"RegCall4">>;
5565+
def fsycl_dump_device_code_EQ : Joined<["-"], "fsycl-dump-device-code=">, Flags<[NoXarchOption]>,
5566+
Visibility<[ClangOption, CLOption]>,
5567+
HelpText<"Dump device code into the user provided directory.">;
55655568
def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[NoXarchOption]>,
55665569
Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
55675570
HelpText<"Save intermediate compilation results.">;

clang/lib/Driver/Compilation.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/Option/OptSpecifier.h"
2222
#include "llvm/Option/Option.h"
2323
#include "llvm/Support/FileSystem.h"
24+
#include "llvm/Support/Path.h"
2425
#include "llvm/Support/SimpleTable.h"
2526
#include "llvm/Support/raw_ostream.h"
2627
#include "llvm/TargetParser/Triple.h"
@@ -126,6 +127,20 @@ bool Compilation::CleanupFile(const char *File, bool IssueErrors) const {
126127
// Don't try to remove files which we don't have write access to (but may be
127128
// able to remove), or non-regular files. Underlying tools may have
128129
// intentionally not overwritten them.
130+
131+
// Save the device code files(spv files) only if -fsycl-dump-device-code
132+
// option is enabled.
133+
if (TheDriver.isDumpDeviceCodeEnabled()) {
134+
Arg *DumpDeviceCodeArg =
135+
getArgs().getLastArg(options::OPT_fsycl_dump_device_code_EQ);
136+
std::string ExpectedDir =
137+
DumpDeviceCodeArg ? DumpDeviceCodeArg->getValue() : "";
138+
std::string ActualFile(File);
139+
if (ActualFile.find(ExpectedDir) != std::string::npos &&
140+
llvm::sys::path::extension(ActualFile).equals(".spv"))
141+
return false;
142+
}
143+
129144
if (!llvm::sys::fs::can_write(File) || !llvm::sys::fs::is_regular_file(File))
130145
return true;
131146

@@ -145,7 +160,7 @@ bool Compilation::CleanupFile(const char *File, bool IssueErrors) const {
145160
bool Compilation::CleanupFileList(const TempFileList &Files,
146161
bool IssueErrors) const {
147162
bool Success = true;
148-
for (const auto &File: Files) {
163+
for (const auto &File : Files) {
149164
// Temporary file lists contain files that need to be cleaned. The
150165
// file containing the information is also removed
151166
if (File.second == types::TY_Tempfilelist ||
@@ -161,6 +176,7 @@ bool Compilation::CleanupFileList(const TempFileList &Files,
161176
Success = false;
162177
continue;
163178
}
179+
164180
std::vector<std::string> TmpFileNames;
165181
T->get()->linearize(TmpFileNames);
166182

@@ -172,7 +188,7 @@ bool Compilation::CleanupFileList(const TempFileList &Files,
172188
} else {
173189
std::ifstream ListFile(File.first);
174190
std::string TmpFileName;
175-
while (std::getline(ListFile, TmpFileName) && !TmpFileName.empty())
191+
while (std::getline(ListFile, TmpFileName))
176192
Success &= CleanupFile(TmpFileName.c_str(), IssueErrors);
177193
}
178194
}

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
199199
DiagnosticsEngine &Diags, std::string Title,
200200
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
201201
: Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode),
202-
SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone),
202+
SaveTemps(SaveTempsNone), DumpDeviceCode(false), BitcodeEmbed(EmbedNone),
203203
Offload(OffloadHostDevice), CXX20HeaderType(HeaderMode_None),
204204
ModulesModeCXX20(false), LTOMode(LTOK_None), OffloadLTOMode(LTOK_None),
205205
ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT),
@@ -1705,6 +1705,9 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
17051705
.Default(SaveTempsCwd);
17061706
}
17071707

1708+
if (Args.getLastArg(options::OPT_fsycl_dump_device_code_EQ))
1709+
DumpDeviceCode = true;
1710+
17081711
if (const Arg *A = Args.getLastArg(options::OPT_offload_host_only,
17091712
options::OPT_offload_device_only,
17101713
options::OPT_offload_host_device)) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10212,6 +10212,26 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
1021210212
TCArgs.MakeArgString("--out-file-list=" + OutputFileName));
1021310213
ForeachArgs.push_back(
1021410214
TCArgs.MakeArgString("--out-replace=" + OutputFileName));
10215+
// If fsycl-dump-device-code is passed, put the output files from llvm-spirv
10216+
// into the path provided in fsycl-dump-device-code.
10217+
if (C.getDriver().isDumpDeviceCodeEnabled()) {
10218+
SmallString<128> OutputDir;
10219+
10220+
Arg *DumpDeviceCodeArg =
10221+
C.getArgs().getLastArg(options::OPT_fsycl_dump_device_code_EQ);
10222+
10223+
OutputDir = (DumpDeviceCodeArg ? DumpDeviceCodeArg->getValue() : "");
10224+
10225+
// If the output directory path is empty, put the llvm-spirv output in the
10226+
// current directory.
10227+
if (OutputDir.empty())
10228+
llvm::sys::path::native(OutputDir = "./");
10229+
else
10230+
OutputDir.append(llvm::sys::path::get_separator());
10231+
ForeachArgs.push_back(
10232+
C.getArgs().MakeArgString("--out-dir=" + OutputDir));
10233+
}
10234+
1021510235
StringRef ParallelJobs =
1021610236
TCArgs.getLastArgValue(options::OPT_fsycl_max_parallel_jobs_EQ);
1021710237
if (!ParallelJobs.empty())

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
269269
{"libsycl-itt-user-wrappers", "internal"},
270270
{"libsycl-itt-compiler-wrappers", "internal"},
271271
{"libsycl-itt-stubs", "internal"}};
272+
#if !defined(_WIN32)
273+
const SYCLDeviceLibsList SYCLDeviceSanitizerLibs = {
274+
{"libsycl-sanitizer", "internal"}};
275+
#endif
272276

273277
auto addLibraries = [&](const SYCLDeviceLibsList &LibsList) {
274278
for (const DeviceLibOptInfo &Lib : LibsList) {
@@ -298,6 +302,17 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
298302
options::OPT_fno_sycl_instrument_device_code, true))
299303
addLibraries(SYCLDeviceAnnotationLibs);
300304

305+
#if !defined(_WIN32)
306+
if (Arg *A = Args.getLastArg(options::OPT_fsanitize_EQ,
307+
options::OPT_fno_sanitize_EQ)) {
308+
if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
309+
A->getValues().size() == 1) {
310+
std::string SanitizeVal = A->getValue();
311+
if (SanitizeVal == "address")
312+
addLibraries(SYCLDeviceSanitizerLibs);
313+
}
314+
}
315+
#endif
301316
return LibraryList;
302317
}
303318

clang/test/Driver/Inputs/SYCL/lib/libsycl-sanitizer.o

Whitespace-only changes.

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,29 @@
211211
// SYCL_LLVM_LINK_DEVICE_LIB_SPIRV_CPU_AOT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64_x86_64-unknown-unknown" "-input={{.*}}libsycl-itt-compiler-wrappers.o" "-output={{.*}}libsycl-itt-compiler-wrappers-{{.*}}.o" "-unbundle"
212212
// SYCL_LLVM_LINK_DEVICE_LIB_SPIRV_CPU_AOT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64_x86_64-unknown-unknown" "-input={{.*}}libsycl-itt-stubs.o" "-output={{.*}}libsycl-itt-stubs-{{.*}}.o" "-unbundle"
213213
// SYCL_LLVM_LINK_DEVICE_LIB_SPIRV_CPU_AOT-NEXT: llvm-link{{.*}} "-only-needed" "{{.*}}" "-o" "{{.*}}.bc" "--suppress-warnings"
214+
215+
/// ###########################################################################
216+
/// test behavior of libsycl-sanitizer.o linking when -fsanitize=address is available
217+
// RUN: %clangxx -fsycl %s --sysroot=%S/Inputs/SYCL -fsanitize=address -### 2>&1 \
218+
// RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_SANITIZER
219+
// SYCL_DEVICE_LIB_SANITIZER: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-crt.o" "-output={{.*}}libsycl-crt-{{.*}}.o" "-unbundle"
220+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-complex.o" "-output={{.*}}libsycl-complex-{{.*}}.o" "-unbundle"
221+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-complex-fp64.o" "-output={{.*}}libsycl-complex-fp64-{{.*}}.o" "-unbundle"
222+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-cmath.o" "-output={{.*}}libsycl-cmath-{{.*}}.o" "-unbundle"
223+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-cmath-fp64.o" "-output={{.*}}libsycl-cmath-fp64-{{.*}}.o" "-unbundle"
224+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-imf.o" "-output={{.*}}libsycl-imf-{{.*}}.o" "-unbundle"
225+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-imf-fp64.o" "-output={{.*}}libsycl-imf-fp64-{{.*}}.o" "-unbundle"
226+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-imf-bf16.o" "-output={{.*}}libsycl-imf-bf16-{{.*}}.o" "-unbundle"
227+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-fallback-cassert.o" "-output={{.*}}libsycl-fallback-cassert-{{.*}}.o" "-unbundle"
228+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-fallback-cstring.o" "-output={{.*}}libsycl-fallback-cstring-{{.*}}.o" "-unbundle"
229+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-fallback-complex.o" "-output={{.*}}libsycl-fallback-complex-{{.*}}.o" "-unbundle"
230+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-fallback-complex-fp64.o" "-output={{.*}}libsycl-fallback-complex-fp64-{{.*}}.o" "-unbundle"
231+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-fallback-cmath.o" "-output={{.*}}libsycl-fallback-cmath-{{.*}}.o" "-unbundle"
232+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-fallback-cmath-fp64.o" "-output={{.*}}libsycl-fallback-cmath-fp64-{{.*}}.o" "-unbundle"
233+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-fallback-imf.o" "-output={{.*}}libsycl-fallback-imf-{{.*}}.o" "-unbundle"
234+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-fallback-imf-fp64.o" "-output={{.*}}libsycl-fallback-imf-fp64-{{.*}}.o" "-unbundle"
235+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-fallback-imf-bf16.o" "-output={{.*}}libsycl-fallback-imf-bf16-{{.*}}.o" "-unbundle"
236+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-itt-user-wrappers.o" "-output={{.*}}libsycl-itt-user-wrappers-{{.*}}.o" "-unbundle"
237+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-itt-compiler-wrappers.o" "-output={{.*}}libsycl-itt-compiler-wrappers-{{.*}}.o" "-unbundle"
238+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-itt-stubs.o" "-output={{.*}}libsycl-itt-stubs-{{.*}}.o" "-unbundle"
239+
// SYCL_DEVICE_LIB_SANITIZER-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}libsycl-sanitizer.o" "-output={{.*}}libsycl-sanitizer-{{.*}}.o" "-unbundle"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SYCL offloading tests using -fsycl-dump-device-code
2+
3+
// Verify that -fsycl-dump-device-code puts the device code (.spv files)
4+
// in the user provided directory.
5+
6+
// Linux
7+
// clang -fsycl -target x86_64-unknown-linux-gnu
8+
// RUN: %clang -fsycl -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -target x86_64-unknown-linux-gnu -fsycl-dump-device-code=/user/input/path %s -### 2>&1 \
9+
// RUN: | FileCheck %s --check-prefixes=CHK-FSYCL-DUMP-DEVICE-CODE
10+
11+
// clang -fsycl -fsycl-targets=spir64-unknown-unknown
12+
// RUN: %clang -fsycl -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -fsycl-dump-device-code=/user/input/path %s -### 2>&1 \
13+
// RUN: | FileCheck %s --check-prefixes=CHK-FSYCL-DUMP-DEVICE-CODE
14+
15+
// clang --driver-mode=g++
16+
// RUN: %clangxx -fsycl -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -fsycl-dump-device-code=/user/input/path %s -### 2>&1 \
17+
// RUN: | FileCheck %s --check-prefixes=CHK-FSYCL-DUMP-DEVICE-CODE
18+
19+
// Windows
20+
// RUN: %clang_cl -fsycl -fsycl-dump-device-code=/user/input/path %s -### 2>&1 \
21+
// RUN: | FileCheck %s --check-prefixes=CHK-FSYCL-DUMP-DEVICE-CODE-WIN
22+
23+
// CHK-FSYCL-DUMP-DEVICE-CODE: llvm-foreach{{.*}} "--out-dir=/user/input/path{{(/|\\\\)}}" "--" "{{.*}}llvm-spirv"
24+
// CHK-FSYCL-DUMP-DEVICE-CODE-WIN: llvm-foreach{{.*}} "--out-dir=/user/input/path{{(/|\\\\)}}" "--" "{{.*}}llvm-spirv"
25+
26+
// Linux
27+
// RUN: %clang -fsycl -fsycl-targets=spir64-unknown-unknown -target x86_64-unknown-linux-gnu -fsycl-dump-device-code= %s -### 2>&1 \
28+
// RUN: | FileCheck %s --check-prefixes=CHK-FSYCL-DUMP-DEVICE-CODE-CWD
29+
30+
// Windows
31+
// RUN: %clang_cl -fsycl -fsycl-dump-device-code= %s -### 2>&1 \
32+
// RUN: | FileCheck %s --check-prefixes=CHK-FSYCL-DUMP-DEVICE-CODE-WIN-CWD
33+
34+
// CHK-FSYCL-DUMP-DEVICE-CODE-CWD: llvm-foreach{{.*}} "--out-dir=.{{(/|\\\\)}}" "--" "{{.*}}llvm-spirv"
35+
// CHK-FSYCL-DUMP-DEVICE-CODE-WIN-CWD: llvm-foreach{{.*}} "--out-dir=.{{(/|\\\\)}}" "--" "{{.*}}llvm-spirv"

libdevice/cmake/modules/SYCLLibdevice.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ set(cmath_obj_deps device_math.h device.h sycl-compiler)
108108
set(imf_obj_deps device_imf.hpp imf_half.hpp imf_bf16.hpp imf_rounding_op.hpp imf_impl_utils.hpp device.h sycl-compiler)
109109
set(itt_obj_deps device_itt.h spirv_vars.h device.h sycl-compiler)
110110
set(bfloat16_obj_deps sycl-headers sycl-compiler)
111+
if (NOT MSVC)
112+
set(sanitizer_obj_deps device.h sycl-compiler)
113+
endif()
111114

112115
add_devicelib_obj(libsycl-itt-stubs SRC itt_stubs.cpp DEP ${itt_obj_deps})
113116
add_devicelib_obj(libsycl-itt-compiler-wrappers SRC itt_compiler_wrappers.cpp DEP ${itt_obj_deps})
@@ -124,6 +127,8 @@ add_devicelib_obj(libsycl-imf-bf16 SRC imf_wrapper_bf16.cpp DEP ${imf_obj_deps})
124127
add_devicelib_obj(libsycl-bfloat16 SRC bfloat16_wrapper.cpp DEP ${cmath_obj_deps} )
125128
if(MSVC)
126129
add_devicelib_obj(libsycl-msvc-math SRC msvc_math.cpp DEP ${cmath_obj_deps})
130+
else()
131+
add_devicelib_obj(libsycl-sanitizer SRC sanitizer_utils.cpp DEP ${sanitizer_obj_deps})
127132
endif()
128133

129134
add_fallback_devicelib(libsycl-fallback-cassert SRC fallback-cassert.cpp DEP ${crt_obj_deps} EXTRA_ARGS -fno-sycl-instrument-device-code)

0 commit comments

Comments
 (0)