================
@@ -367,6 +370,67 @@ void 
SemaSYCL::CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD) {
 
 namespace {
 
+CompoundStmt *BuildSYCLKernelLaunchStmt(Sema &SemaRef, FunctionDecl *FD,
+                                        const std::string &KernelName) {
+  ASTContext &Ctx = SemaRef.getASTContext();
+  SmallVector<Stmt *> Stmts;
+
+  // Prepare a string literal that contains the kernel name in the ordinary
+  // literal encoding.
+  // FIXME: transcode the contents of KernelName from UTF-8 to the
+  // ordinary literal encoding.
+  QualType KernelNameCharTy = Ctx.CharTy.withConst();
+  llvm::APInt KernelNameSize(Ctx.getTypeSize(Ctx.getSizeType()),
+                             KernelName.size() + 1);
+  QualType KernelNameArrayTy = Ctx.getConstantArrayType(
+      KernelNameCharTy, KernelNameSize, nullptr, ArraySizeModifier::Normal, 0);
+  StringLiteral *KernelNameExpr = StringLiteral::Create(
+      Ctx, KernelName, StringLiteralKind::Ordinary,
+      /*Pascal*/ false, KernelNameArrayTy, SourceLocation());
+
+  // FIXME: An extern variable declaration with assignment to the kernel
+  // name expression is added to Stmts as a temporary measure to see results.
+  // reflected in tests. The kernel name expression will need to be passed as
+  // the first function argument in a call to sycl_enqueue_kernel_launch.
+  QualType ExternVarType = Ctx.getPointerType(Ctx.CharTy.withConst());
+  const IdentifierInfo *ExternVarName =
+      SemaRef.getPreprocessor().getIdentifierInfo("kernel_name");
+  VarDecl *ExternVarDecl = VarDecl::Create(
+      Ctx, FD, SourceLocation(), SourceLocation(), ExternVarName, 
ExternVarType,
+      /*TInfo*/ nullptr, SC_Extern);
+  DeclStmt *ExternVarDeclStmt = new (Ctx)
+      DeclStmt(DeclGroupRef(ExternVarDecl), SourceLocation(), 
SourceLocation());
+  Stmts.push_back(ExternVarDeclStmt);
+  DeclRefExpr *ExternVarDeclRef = new (Ctx) DeclRefExpr(
+      Ctx, ExternVarDecl, /*RefersToEnclosingVariableOrCapture*/ false,
+      ExternVarType, VK_LValue, SourceLocation());
+  ImplicitCastExpr *KernelNameArrayDecayExpr = new (Ctx) ImplicitCastExpr(
+      ImplicitCastExpr::OnStack, ExternVarType, CK_ArrayToPointerDecay,
+      KernelNameExpr, VK_PRValue, FPOptionsOverride());
+  BinaryOperator *AssignmentExpr = BinaryOperator::Create(
+      Ctx, ExternVarDeclRef, KernelNameArrayDecayExpr, BO_Assign, 
ExternVarType,
+      VK_LValue, OK_Ordinary, SourceLocation(), FPOptionsOverride());
+  Stmts.push_back(AssignmentExpr);
+
+  // Perform overload resolution for a call to an accessible (member) function
+  // template named 'sycl_enqueue_kernel_launch' from within the definition of
+  // FD where:
+  // - The kernel name type is passed as the first template argument.
+  // - Any remaining template parameters are deduced from the function 
arguments
+  //   or assigned by default template arguments.
+  // - 'this' is passed as the implicit function argument if 'FD' is a
+  //   non-static member function.
+  // - The name of the kernel, expressed as a string literal, is passed as the
+  //   first function argument.
+  // - The parameters of FD are forwarded as-if by 'std::forward()' as the
+  //   remaining explicit function arguments.
+  // - Any remaining function arguments are initialized by default arguments.
----------------
tahonermann wrote:

Resolving this comment. I think this PR at least provides a better diagnostic 
than Clang does for the CUDA case.
```
clang/test/SemaSYCL/sycl-kernel-launch.cpp:296:8: error: no matching function 
for call to 'sycl_kernel_launch'
  296 |   void skep(KT k, int i) {
      |        ^~~~
clang/test/SemaSYCL/sycl-kernel-launch.cpp:295:12: note: in implicit call to 
'sycl_kernel_launch' with template argument 'BADKN<5>' and function arguments 
(lvalue of type 'const char[21]', xvalue of type 'BADKT<5>', xvalue of type 
'int')
      required here
  295 |   [[clang::sycl_kernel_entry_point(KN)]]
      |            ^
clang/test/SemaSYCL/sycl-kernel-launch.cpp:300:17: note: in instantiation of 
function template specialization 'bad5::skep<BADKN<5>, BADKT<5>>' requested here
  300 |   template void skep<BADKN<5>>(BADKT<5>, int);
      |                 ^
clang/test/SemaSYCL/sycl-kernel-launch.cpp:291:8: note: candidate function 
template not viable: requires 2 arguments, but 3 were provided
  291 |   void sycl_kernel_launch(const char *, KT);
      |        ^                  ~~~~~~~~~~~~~~~~
```

https://github.com/llvm/llvm-project/pull/152403
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to