[clang] [SYCL] Basic code generation for SYCL kernel caller offload entry point functions. (PR #133030)
Tom Honermann via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 7 11:09:29 PDT 2025
================
@@ -3303,6 +3303,27 @@ void CodeGenModule::EmitDeferred() {
CurDeclsToEmit.swap(DeferredDeclsToEmit);
for (GlobalDecl &D : CurDeclsToEmit) {
+ // Functions declared with the sycl_kernel_entry_point attribute are
+ // emitted normally during host compilation. During device compilation,
+ // a SYCL kernel caller offload entry point function is generated and
+ // emitted in place of each of these functions.
+ if (const auto *FD = D.getDecl()->getAsFunction()) {
+ if (LangOpts.SYCLIsDevice && FD->hasAttr<SYCLKernelEntryPointAttr>() &&
+ FD->isDefined()) {
+ // Functions with an invalid sycl_kernel_entry_point attribute are
+ // ignored during device compilation.
+ if (!FD->getAttr<SYCLKernelEntryPointAttr>()->isInvalidAttr()) {
+ // Generate and emit the SYCL kernel caller function.
+ EmitSYCLKernelCaller(FD, getContext());
+ // Recurse to emit any symbols directly or indirectly referenced
+ // by the SYCL kernel caller function.
+ EmitDeferred();
----------------
tahonermann wrote:
This is following what is normally done per the following comment near the end of the function:
```
3271 void CodeGenModule::EmitDeferred() {
....
3359 // If we found out that we need to emit more decls, do that recursively.
3360 // This has the advantage that the decls are emitted in a DFS and related
3361 // ones are close together, which is convenient for testing.
3362 if (!DeferredVTables.empty() || !DeferredDeclsToEmit.empty()) {
3363 EmitDeferred();
3364 assert(DeferredVTables.empty() && DeferredDeclsToEmit.empty());
3365 }
3366 }
3367 }
```
https://github.com/llvm/llvm-project/pull/133030
More information about the cfe-commits
mailing list