99#include " DeviceCompilation.h"
1010#include " ESIMD.h"
1111#include " JITBinaryInfo.h"
12+ #include " Resource.h"
1213#include " translation/Translation.h"
1314
1415#include < clang/Basic/DiagnosticDriver.h>
@@ -178,7 +179,12 @@ class HashPreprocessedAction : public PreprocessorFrontendAction {
178179};
179180
180181class SYCLToolchain {
181- SYCLToolchain () {}
182+ SYCLToolchain () {
183+ for (size_t i = 0 ; i < NumToolchainFiles; ++i) {
184+ auto [Path, Content] = ToolchainFiles[i];
185+ ToolchainFS->addFile (Path, 0 , llvm::MemoryBuffer::getMemBuffer (Content));
186+ }
187+ }
182188
183189 // Similar to FrontendActionFactory, but we don't take ownership of
184190 // `FrontendAction`, nor do we create copies of it as we only perform a single
@@ -231,6 +237,7 @@ class SYCLToolchain {
231237 DiagnosticConsumer *DiagConsumer = nullptr ) {
232238 auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
233239 llvm::vfs::getRealFileSystem ());
240+ FS->pushOverlay (ToolchainFS);
234241 if (FSOverlay)
235242 FS->pushOverlay (FSOverlay);
236243
@@ -245,8 +252,14 @@ class SYCLToolchain {
245252 return TI.run ();
246253 }
247254
255+ std::string_view getClangXXExe () const { return ClangXXExe; }
256+
248257private:
249258 clang::IgnoringDiagConsumer IgnoreDiag;
259+ std::string ClangXXExe =
260+ (jit_compiler::ToolchainPrefix + " /bin/clang++" ).str();
261+ llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> ToolchainFS =
262+ llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
250263};
251264
252265class ClangDiagnosticWrapper {
@@ -296,14 +309,11 @@ class LLVMDiagnosticWrapper : public llvm::DiagnosticHandler {
296309} // anonymous namespace
297310
298311static std::vector<std::string>
299- createCommandLine (const InputArgList &UserArgList, std::string_view DPCPPRoot ,
300- BinaryFormat Format, std::string_view SourceFilePath) {
312+ createCommandLine (const InputArgList &UserArgList, BinaryFormat Format ,
313+ std::string_view SourceFilePath) {
301314 DerivedArgList DAL{UserArgList};
302315 const auto &OptTable = getDriverOptTable ();
303316 DAL.AddFlagArg (nullptr , OptTable.getOption (OPT_fsycl_device_only));
304- DAL.AddJoinedArg (
305- nullptr , OptTable.getOption (OPT_resource_dir_EQ),
306- (DPCPPRoot + " /lib/clang/" + Twine (CLANG_VERSION_MAJOR)).str ());
307317 // User args may contain options not intended for the frontend, but we can't
308318 // claim them here to tell the driver they're used later. Hence, suppress the
309319 // unused argument warning.
@@ -327,7 +337,7 @@ createCommandLine(const InputArgList &UserArgList, std::string_view DPCPPRoot,
327337
328338 std::vector<std::string> CommandLine;
329339 CommandLine.reserve (ASL.size () + 2 );
330- CommandLine.emplace_back ((DPCPPRoot + " /bin/clang++ " ). str ());
340+ CommandLine.emplace_back (SYCLToolchain::instance (). getClangXXExe ());
331341 transform (ASL, std::back_inserter (CommandLine),
332342 [](const char *AS) { return std::string{AS}; });
333343 CommandLine.emplace_back (SourceFilePath);
@@ -355,13 +365,8 @@ Expected<std::string> jit_compiler::calculateHash(
355365 const InputArgList &UserArgList, BinaryFormat Format) {
356366 TimeTraceScope TTS{" calculateHash" };
357367
358- const std::string &DPCPPRoot = getDPCPPRoot ();
359- if (DPCPPRoot == InvalidDPCPPRoot) {
360- return createStringError (" Could not locate DPCPP root directory" );
361- }
362-
363368 std::vector<std::string> CommandLine =
364- createCommandLine (UserArgList, DPCPPRoot, Format, SourceFile.Path );
369+ createCommandLine (UserArgList, Format, SourceFile.Path );
365370
366371 HashPreprocessedAction HashAction;
367372
@@ -372,8 +377,7 @@ Expected<std::string> jit_compiler::calculateHash(
372377 // unique for each query, so drop it:
373378 CommandLine.pop_back ();
374379
375- // The command line contains the DPCPP root and clang major version in
376- // "-resource-dir=<...>" argument.
380+ // TODO: Include hash of the current libsycl-jit.so/.dll somehow...
377381 BLAKE3Result<> CommandLineHash =
378382 BLAKE3::hash (arrayRefFromStringRef (join (CommandLine, " ," )));
379383
@@ -394,18 +398,13 @@ Expected<ModuleUPtr> jit_compiler::compileDeviceCode(
394398 LLVMContext &Context, BinaryFormat Format) {
395399 TimeTraceScope TTS{" compileDeviceCode" };
396400
397- const std::string &DPCPPRoot = getDPCPPRoot ();
398- if (DPCPPRoot == InvalidDPCPPRoot) {
399- return createStringError (" Could not locate DPCPP root directory" );
400- }
401-
402401 EmitLLVMOnlyAction ELOA{&Context};
403402 DiagnosticOptions DiagOpts;
404403 ClangDiagnosticWrapper Wrapper (BuildLog, &DiagOpts);
405404
406405 if (SYCLToolchain::instance ().run (
407- createCommandLine (UserArgList, DPCPPRoot, Format, SourceFile.Path ),
408- ELOA, getInMemoryFS (SourceFile, IncludeFiles), Wrapper.consumer ())) {
406+ createCommandLine (UserArgList, Format, SourceFile.Path ), ELOA ,
407+ getInMemoryFS (SourceFile, IncludeFiles), Wrapper.consumer ())) {
409408 return ELOA.takeModule ();
410409 } else {
411410 return createStringError (BuildLog);
0 commit comments