[clang] [SYCL] AST support for SYCL kernel entry point functions. (PR #122379)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 9 14:08:30 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 03eb786f75e36e9e203e0092ec3c6c589fd53c4f d021c2ba6a5b3f501b2f87317cb9072781069d73 --extensions cpp,h -- clang/include/clang/AST/StmtSYCL.h clang/test/ASTSYCL/ast-dump-sycl-kernel-call-stmt.cpp clang/include/clang/AST/ASTNodeTraverser.h clang/include/clang/AST/Decl.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/AST/StmtVisitor.h clang/include/clang/Sema/SemaSYCL.h clang/include/clang/Sema/Template.h clang/include/clang/Serialization/ASTBitCodes.h clang/lib/AST/ASTStructuralEquivalence.cpp clang/lib/AST/Decl.cpp clang/lib/AST/DeclBase.cpp clang/lib/AST/Stmt.cpp clang/lib/AST/StmtPrinter.cpp clang/lib/AST/StmtProfile.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/Sema/JumpDiagnostics.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaExceptionSpec.cpp clang/lib/Sema/SemaSYCL.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTCommon.cpp clang/lib/Serialization/ASTReaderDecl.cpp clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterDecl.cpp clang/lib/Serialization/ASTWriterStmt.cpp clang/lib/StaticAnalyzer/Core/ExprEngine.cpp clang/test/ASTSYCL/ast-dump-sycl-kernel-entry-point.cpp clang/tools/libclang/CIndex.cpp clang/tools/libclang/CXCursor.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 901ec1e48c..4d86c29338 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4720,9 +4720,8 @@ public:
 
   static OutlinedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
                                       unsigned NumParams);
-  static OutlinedFunctionDecl *CreateDeserialized(ASTContext &C,
-                                                  GlobalDeclID ID,
-                                                  unsigned NumParams);
+  static OutlinedFunctionDecl *
+  CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
 
   Stmt *getBody() const override;
   void setBody(Stmt *B);
diff --git a/clang/include/clang/AST/StmtSYCL.h b/clang/include/clang/AST/StmtSYCL.h
index ac356cb0bf..468a580053 100644
--- a/clang/include/clang/AST/StmtSYCL.h
+++ b/clang/include/clang/AST/StmtSYCL.h
@@ -48,8 +48,7 @@ public:
       : Stmt(SYCLKernelCallStmtClass), OriginalStmt(OS), OFDecl(OFD) {}
 
   /// Construct an empty SYCL kernel call statement.
-  SYCLKernelCallStmt(EmptyShell Empty)
-      : Stmt(SYCLKernelCallStmtClass, Empty) {}
+  SYCLKernelCallStmt(EmptyShell Empty) : Stmt(SYCLKernelCallStmtClass, Empty) {}
 
   /// Retrieve the model statement.
   Stmt *getOriginalStmt() { return OriginalStmt; }
@@ -61,9 +60,7 @@ public:
   const OutlinedFunctionDecl *getOutlinedFunctionDecl() const { return OFDecl; }
 
   /// Set the outlined function declaration.
-  void setOutlinedFunctionDecl(OutlinedFunctionDecl *OFD) {
-    OFDecl = OFD;
-  }
+  void setOutlinedFunctionDecl(OutlinedFunctionDecl *OFD) { OFDecl = OFD; }
 
   SourceLocation getBeginLoc() const LLVM_READONLY {
     return getOriginalStmt()->getBeginLoc();
diff --git a/clang/include/clang/Sema/Template.h b/clang/include/clang/Sema/Template.h
index 4206bd50b1..070dba8a50 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -627,10 +627,10 @@ enum class TemplateSubstitutionKind : char {
 #define EMPTY(DERIVED, BASE)
 #define LIFETIMEEXTENDEDTEMPORARY(DERIVED, BASE)
 
-// Decls which never appear inside a template.
+  // Decls which never appear inside a template.
 #define OUTLINEDFUNCTION(DERIVED, BASE)
 
-// Decls which use special-case instantiation code.
+  // Decls which use special-case instantiation code.
 #define BLOCK(DERIVED, BASE)
 #define CAPTURED(DERIVED, BASE)
 #define IMPLICITPARAM(DERIVED, BASE)
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5bce2c37bf..a21ecb6b17 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -5440,30 +5440,34 @@ BlockDecl *BlockDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
   return new (C, ID) BlockDecl(nullptr, SourceLocation());
 }
 
-
 OutlinedFunctionDecl::OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams)
-    : Decl(OutlinedFunction, DC, SourceLocation()), DeclContext(OutlinedFunction),
-      NumParams(NumParams), BodyAndNothrow(nullptr, false) {}
+    : Decl(OutlinedFunction, DC, SourceLocation()),
+      DeclContext(OutlinedFunction), NumParams(NumParams),
+      BodyAndNothrow(nullptr, false) {}
 
-OutlinedFunctionDecl *OutlinedFunctionDecl::Create(ASTContext &C, DeclContext *DC,
-                                   unsigned NumParams) {
+OutlinedFunctionDecl *OutlinedFunctionDecl::Create(ASTContext &C,
+                                                   DeclContext *DC,
+                                                   unsigned NumParams) {
   return new (C, DC, additionalSizeToAlloc<ImplicitParamDecl *>(NumParams))
       OutlinedFunctionDecl(DC, NumParams);
 }
 
-OutlinedFunctionDecl *OutlinedFunctionDecl::CreateDeserialized(ASTContext &C,
-                                                               GlobalDeclID ID,
-                                                               unsigned NumParams) {
+OutlinedFunctionDecl *
+OutlinedFunctionDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID,
+                                         unsigned NumParams) {
   return new (C, ID, additionalSizeToAlloc<ImplicitParamDecl *>(NumParams))
       OutlinedFunctionDecl(nullptr, NumParams);
 }
 
-Stmt *OutlinedFunctionDecl::getBody() const { return BodyAndNothrow.getPointer(); }
+Stmt *OutlinedFunctionDecl::getBody() const {
+  return BodyAndNothrow.getPointer();
+}
 void OutlinedFunctionDecl::setBody(Stmt *B) { BodyAndNothrow.setPointer(B); }
 
 bool OutlinedFunctionDecl::isNothrow() const { return BodyAndNothrow.getInt(); }
-void OutlinedFunctionDecl::setNothrow(bool Nothrow) { BodyAndNothrow.setInt(Nothrow); }
-
+void OutlinedFunctionDecl::setNothrow(bool Nothrow) {
+  BodyAndNothrow.setInt(Nothrow);
+}
 
 CapturedDecl::CapturedDecl(DeclContext *DC, unsigned NumParams)
     : Decl(Captured, DC, SourceLocation()), DeclContext(Captured),
diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp
index 7f2ccb36bf..f88e81d718 100644
--- a/clang/lib/Sema/SemaSYCL.cpp
+++ b/clang/lib/Sema/SemaSYCL.cpp
@@ -8,11 +8,11 @@
 // This implements Semantic Analysis for SYCL constructs.
 //===----------------------------------------------------------------------===//
 
-#include "TreeTransform.h"
 #include "clang/Sema/SemaSYCL.h"
+#include "TreeTransform.h"
 #include "clang/AST/Mangle.h"
-#include "clang/AST/StmtSYCL.h"
 #include "clang/AST/SYCLKernelInfo.h"
+#include "clang/AST/StmtSYCL.h"
 #include "clang/AST/TypeOrdering.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Sema/Attr.h"
@@ -375,16 +375,14 @@ namespace {
 class OutlinedFunctionDeclBodyInstantiator
     : public TreeTransform<OutlinedFunctionDeclBodyInstantiator> {
 public:
-  using ParmDeclMap = llvm::DenseMap<ParmVarDecl*, VarDecl*>;
+  using ParmDeclMap = llvm::DenseMap<ParmVarDecl *, VarDecl *>;
 
   OutlinedFunctionDeclBodyInstantiator(Sema &S, ParmDeclMap &M)
-      : TreeTransform<OutlinedFunctionDeclBodyInstantiator>(S),
-        SemaRef(S), MapRef(M) {}
+      : TreeTransform<OutlinedFunctionDeclBodyInstantiator>(S), SemaRef(S),
+        MapRef(M) {}
 
   // A new set of AST nodes is always required.
-  bool AlwaysRebuild() {
-    return true;
-  }
+  bool AlwaysRebuild() { return true; }
 
   // Transform ParmVarDecl references to the supplied replacement variables.
   ExprResult TransformDeclRefExpr(DeclRefExpr *DRE) {
@@ -427,7 +425,7 @@ StmtResult SemaSYCL::BuildSYCLKernelCallStmt(FunctionDecl *FD, Stmt *Body) {
   // Ensure that the kernel name was previously registered and that the
   // stored declaration matches.
   const SYCLKernelInfo &SKI =
-        getASTContext().getSYCLKernelInfo(SKEPAttr->getKernelName());
+      getASTContext().getSYCLKernelInfo(SKEPAttr->getKernelName());
   assert(declaresSameEntity(SKI.getKernelEntryPointDecl(), FD) &&
          "SYCL kernel name conflict");
 
@@ -439,10 +437,9 @@ StmtResult SemaSYCL::BuildSYCLKernelCallStmt(FunctionDecl *FD, Stmt *Body) {
       OutlinedFunctionDecl::Create(getASTContext(), FD, FD->getNumParams());
   unsigned i = 0;
   for (ParmVarDecl *PVD : FD->parameters()) {
-    ImplicitParamDecl *IPD =
-        ImplicitParamDecl::Create(getASTContext(), OFD, SourceLocation(),
-                                  PVD->getIdentifier(), PVD->getType(),
-                                  ImplicitParamKind::Other);
+    ImplicitParamDecl *IPD = ImplicitParamDecl::Create(
+        getASTContext(), OFD, SourceLocation(), PVD->getIdentifier(),
+        PVD->getType(), ImplicitParamKind::Other);
     OFD->setParam(i, IPD);
     ParmMap[PVD] = IPD;
     ++i;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index f1a40fbc97..07642beac2 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -17405,7 +17405,7 @@ TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
   return getSema().ActOnCapturedRegionEnd(Body.get());
 }
 
-template<typename Derived>
+template <typename Derived>
 StmtResult
 TreeTransform<Derived>::TransformSYCLKernelCallStmt(SYCLKernelCallStmt *S) {
   // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)

``````````

</details>


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


More information about the cfe-commits mailing list