-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-sycl-linker] Generate SymbolTable for each image #161287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR adds extraction of kernel names for each image and stores them to the Image's StringData field.
|
@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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
This PR adds extraction of kernel names for each image and stores them to the Image's StringData field.
This PR adds extraction of kernel names for each image and stores them to the Image's StringData field.