[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


================
@@ -14794,9 +14803,36 @@ void ASTContext::getFunctionFeatureMap(llvm::StringMap<bool> &FeatureMap,
   }
 }
 
-static SYCLKernelInfo BuildSYCLKernelInfo(CanQualType KernelNameType,
+static SYCLKernelInfo BuildSYCLKernelInfo(ASTContext &Context,
+                                          CanQualType KernelNameType,
                                           const FunctionDecl *FD) {
-  return {KernelNameType, FD};
+  // Host and device compilation may use different ABIs and different ABIs
+  // may allocate name mangling discriminators differently. A discriminator
+  // override is used to ensure consistent discriminator allocation across
+  // host and device compilation.
+  auto DeviceDiscriminatorOverrider =
+      [](ASTContext &Ctx, const NamedDecl *ND) -> std::optional<unsigned> {
+    if (const auto *RD = dyn_cast<CXXRecordDecl>(ND))
+      if (RD->isLambda())
+        return RD->getDeviceLambdaManglingNumber();
+    return std::nullopt;
+  };
+  std::unique_ptr<MangleContext> MC{ItaniumMangleContext::create(
+      Context, Context.getDiagnostics(), DeviceDiscriminatorOverrider)};
+
+  // Construct a mangled name for the SYCL kernel caller offload entry point.
+  // FIXME: The Itanium typeinfo mangling (_ZTS<type>) is currently used to
+  // FIXME: name the SYCL kernel caller offload entry point function. This
+  // FIXME: mangling does not suffice to clearly identify symbols that
+  // FIXME: correspond to SYCL kernel caller functions, nor is this mangling
+  // FIXME: natural for targets that use a non-Itanium ABI.
----------------
tahonermann wrote:

One of the next couple of PRs will address name mangling. I have changes ready to provide mangled names for both the Microsoft and Itanium ABIs. Those changes generate a name that matches that of a function template specialization that has a reserved name (e.g., `__sycl_kernel_caller`), a single template type argument corresponding to the SYCL kernel name, and no function parameters. A stable name mangling scheme is intended to be in place long before we make any claims about ABI stability.

https://github.com/llvm/llvm-project/pull/133030


More information about the cfe-commits mailing list