Skip to content

Commit 44e28fd

Browse files
WIP
```c++ int main() { const char *src = R"""( // #include <stdio.h> namespace syclext = sycl::ext::oneapi; namespace syclexp = sycl::ext::oneapi::experimental; extern "C" SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::single_task_kernel)) void foo(int *p) { *p = 42; } )"""; jit_compiler::InMemoryFile SrcFile{"a.cpp", src}; std::vector<jit_compiler::InMemoryFile> IncludeFiles{ {"/fake_includes/assert.h", "#pragma once\n#define assert(...)\n"} }; std::vector<const char *> opts = { "--stdlib=libc++", "-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES" , "-include", "stdio.h" // "-Xclang", "-isystem-after", "-Xclang", "/sycl-jit-toolchain/lib/clang/22/include/libc" // , // "-isystem-after=/sycl-jit-toolchain/lib/clang/22/include/libc" }; { auto Res = jit_compiler::calculateHash(SrcFile, IncludeFiles, opts, jit_compiler::BinaryFormat::SPIRV); std::cerr << "Failed: " << std::boolalpha << Res.failed() << std::endl; } { auto Res = jit_compiler::compileSYCL(SrcFile, IncludeFiles, opts, {nullptr, 0}, false, jit_compiler::BinaryFormat::SPIRV); std::cerr << (int)Res.getErrorCode() << std::endl; std::cerr << Res.getBuildLog() << std::endl; } } ```
1 parent f976569 commit 44e28fd

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,9 @@ void SYCLToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
20832083
void SYCLToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &Args,
20842084
ArgStringList &CC1Args) const {
20852085
HostTC.AddClangCXXStdlibIncludeArgs(Args, CC1Args);
2086+
if (GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) {
2087+
addSystemInclude(Args, CC1Args, "/sycl-jit-toolchain/include/libc");
2088+
}
20862089
}
20872090

20882091
SanitizerMask SYCLToolChain::getSupportedSanitizers() const {

sycl-jit/jit-compiler/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ endforeach()
6565
if ("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
6666
list(APPEND SYCL_JIT_RUNTIME_RESOURCE_DEPS libc)
6767
list(APPEND SYCL_JIT_PREPARE_RUNTIME_RESOURCE_COMMANDS
68-
# COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins --target libc
69-
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins/libc/include ${SYCL_JIT_RESOURCE_INSTALL_DIR}
68+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/runtimes/runtimes-bins/libc/include ${SYCL_JIT_RESOURCE_INSTALL_DIR}/include/libc
7069
)
7170
endif()
7271

sycl-jit/jit-compiler/lib/rtc/DeviceCompilation.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
#include <memory>
6060
#include <sstream>
6161

62+
#include <iostream>
63+
6264
using namespace clang;
6365
using namespace clang::tooling;
6466
using namespace clang::driver;
@@ -216,6 +218,9 @@ class SYCLToolchain {
216218
FileManager *Files,
217219
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
218220
DiagnosticConsumer *DiagConsumer) override {
221+
for (auto &arg : Invocation->getCC1CommandLine())
222+
std::cerr << " " << arg;
223+
std::cerr << std::endl;
219224
// Create a compiler instance to handle the actual work.
220225
CompilerInstance Compiler(std::move(Invocation),
221226
std::move(PCHContainerOps));
@@ -278,6 +283,14 @@ class SYCLToolchain {
278283
CommandLine.emplace_back(ClangXXExe);
279284
transform(ASL, std::back_inserter(CommandLine),
280285
[](const char *AS) { return std::string{AS}; });
286+
287+
288+
// CommandLine.push_back("--stdlib=libc++");
289+
// CommandLine.push_back("-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES");
290+
// CommandLine.push_back("-include");
291+
// CommandLine.push_back("stdio.h");
292+
293+
281294
CommandLine.emplace_back(SourceFilePath);
282295
return CommandLine;
283296
}
@@ -543,9 +556,16 @@ class SYCLToolchain {
543556
std::vector<std::string> CommandLine =
544557
createCommandLine(UserArgList, Format, SourceFilePath);
545558

559+
#if 1
546560
auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
547561
llvm::vfs::getRealFileSystem());
548562
FS->pushOverlay(getToolchainFS());
563+
#else
564+
auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
565+
getToolchainFS());
566+
#endif
567+
568+
549569
if (FSOverlay)
550570
FS->pushOverlay(std::move(FSOverlay));
551571

@@ -704,10 +724,12 @@ Expected<std::string> jit_compiler::calculateHash(
704724
Opts.ShowCPP = 1;
705725
Opts.MinimizeWhitespace = 1;
706726
// Make cache key insensitive to virtual source file and header locations.
707-
Opts.ShowLineMarkers = 0;
727+
Opts.ShowLineMarkers = 1;
708728

709729
DoPrintPreprocessedInput(CI.getPreprocessor(), &PreprocessStream, Opts);
710730

731+
std::cout << PreprocessedSource << std::endl;
732+
711733
Hasher.update(PreprocessedSource);
712734
}
713735

sycl/include/sycl/ext/oneapi/properties/property.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ template <> struct is_property_key_of<foo, SYCL_OBJ> : std::true_type {};
119119

120120
#pragma once
121121

122-
#include <iosfwd> // for nullptr_t
122+
#include <cstddef> // for nullptr_t
123123
#include <stdint.h> // for uint32_t
124124
#include <type_traits> // for false_type
125125

0 commit comments

Comments
 (0)