[clang-sycl-linker] Generate SymbolTable for each image#161287
Merged
Conversation
This PR adds extraction of kernel names for each image and stores them to the Image's StringData field.
Member
|
@llvm/pr-subscribers-clang Author: Yury Plyakhin (YuriPlyakhin) ChangesThis PR adds extraction of kernel names for each image and stores them to the Image's StringData field. Full diff: https://github.com/llvm/llvm-project/pull/161287.diff 1 Files Affected:
diff --git a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
index fde6b55165868..8b186e6e28618 100644
--- a/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
+++ b/clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp
@@ -466,6 +466,12 @@ static Error runAOTCompile(StringRef InputFile, StringRef OutputFile,
return createStringError(inconvertibleErrorCode(), "Unsupported arch");
}
+bool isKernel(const Function &F) {
+ const CallingConv::ID CC = F.getCallingConv();
+ return CC == CallingConv::SPIR_KERNEL || CC == CallingConv::AMDGPU_KERNEL ||
+ CC == CallingConv::PTX_Kernel;
+}
+
/// Performs the following steps:
/// 1. Link input device code (user code and SYCL device library code).
/// 2. Run SPIR-V code generation.
@@ -486,6 +492,22 @@ Error runSYCLLink(ArrayRef<std::string> Files, const ArgList &Args) {
SmallVector<std::string> SplitModules;
SplitModules.emplace_back(*LinkedFile);
+ // Generate symbol table.
+ SmallVector<std::string> SymbolTable;
+ for (size_t I = 0, E = SplitModules.size(); I != E; ++I) {
+ Expected<std::unique_ptr<Module>> ModOrErr =
+ getBitcodeModule(SplitModules[I], C);
+ if (!ModOrErr)
+ return ModOrErr.takeError();
+
+ SmallVector<StringRef> Symbols;
+ for (Function &F : **ModOrErr) {
+ if (isKernel(F))
+ Symbols.push_back(F.getName());
+ }
+ SymbolTable.emplace_back(llvm::join(Symbols.begin(), Symbols.end(), "\n"));
+ }
+
bool IsAOTCompileNeeded = IsIntelOffloadArch(
StringToOffloadArch(Args.getLastArgValue(OPT_arch_EQ)));
@@ -523,12 +545,13 @@ Error runSYCLLink(ArrayRef<std::string> Files, const ArgList &Args) {
return createFileError(File, EC);
}
OffloadingImage TheImage{};
- TheImage.TheImageKind = IMG_Object;
+ TheImage.TheImageKind = IMG_None;
TheImage.TheOffloadKind = OFK_SYCL;
TheImage.StringData["triple"] =
Args.MakeArgString(Args.getLastArgValue(OPT_triple_EQ));
TheImage.StringData["arch"] =
Args.MakeArgString(Args.getLastArgValue(OPT_arch_EQ));
+ TheImage.StringData["symbols"] = SymbolTable[I];
TheImage.Image = std::move(*FileOrErr);
llvm::SmallString<0> Buffer = OffloadBinary::write(TheImage);
|
jhuber6
reviewed
Sep 29, 2025
bader
reviewed
Sep 29, 2025
jhuber6
approved these changes
Sep 30, 2025
jhuber6
left a comment
Contributor
There was a problem hiding this comment.
Nothing too offensive, but I feel like part of this should be refactored in the future. You should use LLVM-IR metadata to identify globals of interest and try to avoid needing to create a new string.
sarnex
reviewed
Sep 30, 2025
bader
approved these changes
Sep 30, 2025
sarnex
approved these changes
Sep 30, 2025
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Oct 3, 2025
This PR adds extraction of kernel names for each image and stores them to the Image's StringData field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds extraction of kernel names for each image and stores them to the Image's StringData field.