aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorTom Honermann <tom.honermann@intel.com>2025-04-17 06:14:45 -0700
committerGitHub <noreply@github.com>2025-04-17 09:14:45 -0400
commit0348ff515854438cab8a48b79e8839cb99d48701 (patch)
tree43c39d33ad5fddc7f5002a659bff17c3c1a2f322 /clang/lib/CodeGen/CodeGenModule.cpp
parentfb00fa56b51b191d026eec104905e416bf34bbda (diff)
downloadllvm-0348ff515854438cab8a48b79e8839cb99d48701.zip
llvm-0348ff515854438cab8a48b79e8839cb99d48701.tar.gz
llvm-0348ff515854438cab8a48b79e8839cb99d48701.tar.bz2
[SYCL] Basic code generation for SYCL kernel caller offload entry point functions. (#133030)
A function declared with the `sycl_kernel_entry_point` attribute, sometimes called a SYCL kernel entry point function, specifies a pattern from which the parameters and body of an offload entry point function, sometimes called a SYCL kernel caller function, are derived. SYCL kernel caller functions are emitted during SYCL device compilation. Their parameters and body are derived from the `SYCLKernelCallStmt` statement and `OutlinedFunctionDecl` declaration associated with their corresponding SYCL kernel entry point function. A distinct SYCL kernel caller function is generated for each SYCL kernel entry point function defined as a non-inline function or ODR-used in the translation unit. The name of each SYCL kernel caller function is parameterized by the SYCL kernel name type specified by the `sycl_kernel_entry_point` attribute attached to the corresponding SYCL kernel entry point function. For the moment, the Itanium ABI mangled name for typeinfo data (`_ZTS<type>`) is used to name these functions; a future change will switch to a more appropriate naming scheme. The calling convention used for a SYCL kernel caller function is target dependent. Support for AMDGCN, NVPTX, and SPIR targets is currently provided. These functions are required to observe the language restrictions for SYCL devices as specified by the SYCL 2020 specification; this includes a forward progress guarantee and prohibits recursion. Only SYCL kernel caller functions, functions declared as `SYCL_EXTERNAL`, and functions directly or indirectly referenced from those functions should be emitted during device compilation. Pruning of other declarations has not yet been implemented. --------- Co-authored-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 26e09fe..83d8d4f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3309,6 +3309,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();
+ }
+ // Do not emit the sycl_kernel_entry_point attributed function.
+ continue;
+ }
+ }
+
// We should call GetAddrOfGlobal with IsForDefinition set to true in order
// to get GlobalValue with exactly the type we need, not something that
// might had been created for another decl with the same mangled name but
@@ -3644,6 +3665,10 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl *Global) {
// Defer until all versions have been semantically checked.
if (FD->hasAttr<TargetVersionAttr>() && !FD->isMultiVersion())
return false;
+ // Defer emission of SYCL kernel entry point functions during device
+ // compilation.
+ if (LangOpts.SYCLIsDevice && FD->hasAttr<SYCLKernelEntryPointAttr>())
+ return false;
}
if (const auto *VD = dyn_cast<VarDecl>(Global)) {
if (Context.getInlineVariableDefinitionKind(VD) ==