@@ -466,6 +466,13 @@ static Error runAOTCompile(StringRef InputFile, StringRef OutputFile,
466
466
return createStringError (inconvertibleErrorCode (), " Unsupported arch" );
467
467
}
468
468
469
+ // TODO: Consider using LLVM-IR metadata to identify globals of interest
470
+ bool isKernel (const Function &F) {
471
+ const CallingConv::ID CC = F.getCallingConv ();
472
+ return CC == CallingConv::SPIR_KERNEL || CC == CallingConv::AMDGPU_KERNEL ||
473
+ CC == CallingConv::PTX_Kernel;
474
+ }
475
+
469
476
// / Performs the following steps:
470
477
// / 1. Link input device code (user code and SYCL device library code).
471
478
// / 2. Run SPIR-V code generation.
@@ -486,6 +493,22 @@ Error runSYCLLink(ArrayRef<std::string> Files, const ArgList &Args) {
486
493
SmallVector<std::string> SplitModules;
487
494
SplitModules.emplace_back (*LinkedFile);
488
495
496
+ // Generate symbol table.
497
+ SmallVector<std::string> SymbolTable;
498
+ for (size_t I = 0 , E = SplitModules.size (); I != E; ++I) {
499
+ Expected<std::unique_ptr<Module>> ModOrErr =
500
+ getBitcodeModule (SplitModules[I], C);
501
+ if (!ModOrErr)
502
+ return ModOrErr.takeError ();
503
+
504
+ SmallVector<StringRef> Symbols;
505
+ for (Function &F : **ModOrErr) {
506
+ if (isKernel (F))
507
+ Symbols.push_back (F.getName ());
508
+ }
509
+ SymbolTable.emplace_back (llvm::join (Symbols.begin (), Symbols.end (), " \n " ));
510
+ }
511
+
489
512
bool IsAOTCompileNeeded = IsIntelOffloadArch (
490
513
StringToOffloadArch (Args.getLastArgValue (OPT_arch_EQ)));
491
514
@@ -523,12 +546,19 @@ Error runSYCLLink(ArrayRef<std::string> Files, const ArgList &Args) {
523
546
return createFileError (File, EC);
524
547
}
525
548
OffloadingImage TheImage{};
526
- TheImage.TheImageKind = IMG_Object;
549
+ // TODO: TheImageKind should be
550
+ // `IsAOTCompileNeeded ? IMG_Object : IMG_SPIRV;`
551
+ // For that we need to update SYCL Runtime to align with the ImageKind enum.
552
+ // Temporarily it is initalized to IMG_None, because in that case, SYCL
553
+ // Runtime has a heuristic to understand what the Image Kind is, so at least
554
+ // it works.
555
+ TheImage.TheImageKind = IMG_None;
527
556
TheImage.TheOffloadKind = OFK_SYCL;
528
557
TheImage.StringData [" triple" ] =
529
558
Args.MakeArgString (Args.getLastArgValue (OPT_triple_EQ));
530
559
TheImage.StringData [" arch" ] =
531
560
Args.MakeArgString (Args.getLastArgValue (OPT_arch_EQ));
561
+ TheImage.StringData [" symbols" ] = SymbolTable[I];
532
562
TheImage.Image = std::move (*FileOrErr);
533
563
534
564
llvm::SmallString<0 > Buffer = OffloadBinary::write (TheImage);
0 commit comments