[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-13 Thread Erich Keane via cfe-commits

https://github.com/erichkeane closed 
https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-09 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.

LG

https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-09 Thread Erich Keane via cfe-commits


@@ -0,0 +1,142 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;

erichkeane wrote:

> The problem here, that if you're going to implement it in some other level of 
> abstraction, rather than here, you will need to migrate AssociatedStmt to the 
> same level to make children() correctly return list of child stmt/exprs. I 
> don't know what's your plan/design approach, so it is absolutely up to you 
> for now. I'm just bringing this to make you aware of possible issues here.

Thanks!  I'll keep it in mind... I presume there will be quite a few things 
that end up getting 'moved around' a bit as I get deeper into implementation, 
so this is good to know!

There are only two constructs with a directly associated expression (`cache` 
and `wait`) so those might need trailing storage (and there is `routine`, but 
that is an associated name which will turn into a decl), but neither of those 
have an associated stmt.  

https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-09 Thread Alexey Bataev via cfe-commits


@@ -0,0 +1,142 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;

alexey-bataev wrote:

The problem here, that if you're going to implement it in some other level of 
abstraction, rather than here, you will need to migrate AssociatedStmt to the 
same level to make children() correctly return list of child stmt/exprs. I 
don't know what's your plan/design approach, so it is absolutely up to you for 
now. I'm just bringing this to make you aware of possible issues here.

https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-09 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/81188

>From b7ca554663c4d0994ac255ee17ac016ef94f6778 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Thu, 8 Feb 2024 07:56:30 -0800
Subject: [PATCH 1/4] [OpenACC] Implement AST for OpenACC Compute Constructs

'serial', 'parallel', and 'kernel' constructs are all considered
'Compute' constructs. This patch creates the AST type, plus the required
infrastructure for such a type, plus some base types that will be useful
in the future for breaking this up.

The only difference between the three is the 'kind'( plus some minor
 clause legalization rules, but those can be differentiated easily
 enough), so rather than representing them as separate AST nodes, it seems
to make sense to make them the same.

Additionally, no clause AST functionality is being implemented yet, as
that fits better in a separate patch, and this is enough to get the
'naked' constructs implemented.

This is otherwise an 'NFC' patch, as it doesn't alter execution at all,
so there aren't any tests.  I did this to break up the review workload
and to get feedback on the layout.
---
 clang/include/clang-c/Index.h |   6 +-
 clang/include/clang/AST/RecursiveASTVisitor.h |  22 +++
 clang/include/clang/AST/StmtOpenACC.h | 141 ++
 clang/include/clang/AST/StmtVisitor.h |   1 +
 clang/include/clang/AST/TextNodeDumper.h  |   1 +
 clang/include/clang/Basic/OpenACCKinds.h  |  31 +++-
 clang/include/clang/Basic/StmtNodes.td|   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/lib/AST/ASTStructuralEquivalence.cpp|   1 +
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/Stmt.cpp|   1 +
 clang/lib/AST/StmtOpenACC.cpp |  33 
 clang/lib/AST/StmtPrinter.cpp |   9 ++
 clang/lib/AST/StmtProfile.cpp |   8 +
 clang/lib/AST/TextNodeDumper.cpp  |   5 +
 clang/lib/CodeGen/CGStmt.cpp  |   3 +
 clang/lib/CodeGen/CodeGenFunction.h   |  10 ++
 clang/lib/Sema/SemaExceptionSpec.cpp  |   1 +
 clang/lib/Sema/TreeTransform.h|  22 +++
 clang/lib/Serialization/ASTReaderStmt.cpp |  24 +++
 clang/lib/Serialization/ASTWriterStmt.cpp |  22 +++
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |   1 +
 clang/tools/libclang/CIndex.cpp   |   2 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 24 files changed, 352 insertions(+), 5 deletions(-)
 create mode 100644 clang/include/clang/AST/StmtOpenACC.h
 create mode 100644 clang/lib/AST/StmtOpenACC.cpp

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 6af41424ba89a1..8d939e8d21901b 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2145,7 +2145,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPScopeDirective = 306,
 
-  CXCursor_LastStmt = CXCursor_OMPScopeDirective,
+  /** OpenACC Compute Construct.
+   */
+  CXCursor_OpenACCComputeConstruct = 307,
+
+  CXCursor_LastStmt = CXCursor_OpenACCComputeConstruct,
 
   /**
* Cursor that represents the translation unit itself.
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 9da5206a21c34c..5080551ada4fc6 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -34,6 +34,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
+#include "clang/AST/StmtOpenACC.h"
 #include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
@@ -505,6 +506,9 @@ template  class RecursiveASTVisitor {
   bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
 
   bool PostVisitStmt(Stmt *S);
+  bool TraverseOpenACCConstructStmt(OpenACCConstructStmt *S);
+  bool
+  TraverseOpenACCAssociatedStmtConstruct(OpenACCAssociatedStmtConstruct *S);
 };
 
 template 
@@ -3910,6 +3914,24 @@ bool 
RecursiveASTVisitor::VisitOMPXBareClause(OMPXBareClause *C) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::TraverseOpenACCConstructStmt(
+OpenACCConstructStmt *) {
+  // TODO OpenACC: When we implement clauses, ensure we traverse them here.
+  return true;
+}
+
+template 
+bool RecursiveASTVisitor::TraverseOpenACCAssociatedStmtConstruct(
+OpenACCAssociatedStmtConstruct *S) {
+  TRY_TO(TraverseOpenACCConstructStmt(S));
+  TRY_TO(TraverseStmt(S->getAssociatedStmt()));
+  return true;
+}
+
+DEF_TRAVERSE_STMT(OpenACCComputeConstruct,
+  { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
+
 // FIXME: look at the following tricky-seeming exprs to see if we
 // need to recurse on anything.  These are ones that have methods
 // returning decls or qualtypes or nestednamespecifier -- though I'm
diff --git a/clang/include/clang/AST/StmtOpenACC.h 

[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-09 Thread Erich Keane via cfe-commits


@@ -2145,7 +2145,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPScopeDirective = 306,
 
-  CXCursor_LastStmt = CXCursor_OMPScopeDirective,
+  /** OpenACC Compute Construct.
+   */
+  CXCursor_OpenACCComputeConstruct = 307,

erichkeane wrote:

Thats a good idea, and I think 320 gives me plenty of room before we start 
getting into the 350 of 'translation unit'.  There are currently 20 'construct' 
types for OpenACC, though I am likely to merge a couple of them (as I am 
merging 3 different ones in this patch).  Patch incoming.

https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-09 Thread Erich Keane via cfe-commits


@@ -0,0 +1,142 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;

erichkeane wrote:

As far as I can tell, they do NOT have any.  Individual clauses have 
expressions (and some of the other nodes have expressions), but there is never 
more than 1 statement associated with it.

I considered the trailing storage, but since it is always 'required' and only 
on certain constructs  (which I'll select via giving them a different AST 
node), I think a member for the `ComputeConstruct`, and a few others makes the 
most sense?  But if you see a good reason to switch to trailing storage during 
future review, please let me know, and I'll switch it over!

https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-09 Thread Alexey Bataev via cfe-commits


@@ -0,0 +1,142 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;

alexey-bataev wrote:

I hhave a question about children stmts/exprs here. Does OpenACC nodes may have 
other children rather than AssociatedStmt? If it is possible, better to use 
tail allocation and store AssociatedStmt as part of the tail-allocated memory 
space

https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-09 Thread Alexey Bataev via cfe-commits


@@ -2145,7 +2145,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPScopeDirective = 306,
 
-  CXCursor_LastStmt = CXCursor_OMPScopeDirective,
+  /** OpenACC Compute Construct.
+   */
+  CXCursor_OpenACCComputeConstruct = 307,

alexey-bataev wrote:

I would suggest to save some constant number for future OpenMP nodes. How about 
start it from, say, 320 for OpenACC nodes? Just to avoid mixing of OpenMP and 
OpenACC nodes

https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-09 Thread Erich Keane via cfe-commits

https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/81188

>From b7ca554663c4d0994ac255ee17ac016ef94f6778 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Thu, 8 Feb 2024 07:56:30 -0800
Subject: [PATCH 1/3] [OpenACC] Implement AST for OpenACC Compute Constructs

'serial', 'parallel', and 'kernel' constructs are all considered
'Compute' constructs. This patch creates the AST type, plus the required
infrastructure for such a type, plus some base types that will be useful
in the future for breaking this up.

The only difference between the three is the 'kind'( plus some minor
 clause legalization rules, but those can be differentiated easily
 enough), so rather than representing them as separate AST nodes, it seems
to make sense to make them the same.

Additionally, no clause AST functionality is being implemented yet, as
that fits better in a separate patch, and this is enough to get the
'naked' constructs implemented.

This is otherwise an 'NFC' patch, as it doesn't alter execution at all,
so there aren't any tests.  I did this to break up the review workload
and to get feedback on the layout.
---
 clang/include/clang-c/Index.h |   6 +-
 clang/include/clang/AST/RecursiveASTVisitor.h |  22 +++
 clang/include/clang/AST/StmtOpenACC.h | 141 ++
 clang/include/clang/AST/StmtVisitor.h |   1 +
 clang/include/clang/AST/TextNodeDumper.h  |   1 +
 clang/include/clang/Basic/OpenACCKinds.h  |  31 +++-
 clang/include/clang/Basic/StmtNodes.td|   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/lib/AST/ASTStructuralEquivalence.cpp|   1 +
 clang/lib/AST/CMakeLists.txt  |   1 +
 clang/lib/AST/Stmt.cpp|   1 +
 clang/lib/AST/StmtOpenACC.cpp |  33 
 clang/lib/AST/StmtPrinter.cpp |   9 ++
 clang/lib/AST/StmtProfile.cpp |   8 +
 clang/lib/AST/TextNodeDumper.cpp  |   5 +
 clang/lib/CodeGen/CGStmt.cpp  |   3 +
 clang/lib/CodeGen/CodeGenFunction.h   |  10 ++
 clang/lib/Sema/SemaExceptionSpec.cpp  |   1 +
 clang/lib/Sema/TreeTransform.h|  22 +++
 clang/lib/Serialization/ASTReaderStmt.cpp |  24 +++
 clang/lib/Serialization/ASTWriterStmt.cpp |  22 +++
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |   1 +
 clang/tools/libclang/CIndex.cpp   |   2 +
 clang/tools/libclang/CXCursor.cpp |   3 +
 24 files changed, 352 insertions(+), 5 deletions(-)
 create mode 100644 clang/include/clang/AST/StmtOpenACC.h
 create mode 100644 clang/lib/AST/StmtOpenACC.cpp

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 6af41424ba89a..8d939e8d21901 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2145,7 +2145,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPScopeDirective = 306,
 
-  CXCursor_LastStmt = CXCursor_OMPScopeDirective,
+  /** OpenACC Compute Construct.
+   */
+  CXCursor_OpenACCComputeConstruct = 307,
+
+  CXCursor_LastStmt = CXCursor_OpenACCComputeConstruct,
 
   /**
* Cursor that represents the translation unit itself.
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 9da5206a21c34..5080551ada4fc 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -34,6 +34,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
+#include "clang/AST/StmtOpenACC.h"
 #include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
@@ -505,6 +506,9 @@ template  class RecursiveASTVisitor {
   bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
 
   bool PostVisitStmt(Stmt *S);
+  bool TraverseOpenACCConstructStmt(OpenACCConstructStmt *S);
+  bool
+  TraverseOpenACCAssociatedStmtConstruct(OpenACCAssociatedStmtConstruct *S);
 };
 
 template 
@@ -3910,6 +3914,24 @@ bool 
RecursiveASTVisitor::VisitOMPXBareClause(OMPXBareClause *C) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::TraverseOpenACCConstructStmt(
+OpenACCConstructStmt *) {
+  // TODO OpenACC: When we implement clauses, ensure we traverse them here.
+  return true;
+}
+
+template 
+bool RecursiveASTVisitor::TraverseOpenACCAssociatedStmtConstruct(
+OpenACCAssociatedStmtConstruct *S) {
+  TRY_TO(TraverseOpenACCConstructStmt(S));
+  TRY_TO(TraverseStmt(S->getAssociatedStmt()));
+  return true;
+}
+
+DEF_TRAVERSE_STMT(OpenACCComputeConstruct,
+  { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
+
 // FIXME: look at the following tricky-seeming exprs to see if we
 // need to recurse on anything.  These are ones that have methods
 // returning decls or qualtypes or nestednamespecifier -- though I'm
diff --git a/clang/include/clang/AST/StmtOpenACC.h 
b/clang/include/clang/AST/StmtOpenACC.h

[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread Erich Keane via cfe-commits


@@ -0,0 +1,140 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;
+
+protected:
+  OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K,
+ SourceLocation Start, SourceLocation End)
+  : OpenACCConstructStmt(SC, K, Start, End) {}
+
+  void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
+  Stmt *getAssociatedStmt() { return AssociatedStmt; }
+  const Stmt *getAssociatedStmt() const {
+return const_cast(this)
+->getAssociatedStmt();
+  }
+
+public:
+  child_range children() {
+if (getAssociatedStmt())
+  return child_range(,  + 1);
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+/// This class represents a compute construct, representing a 'Kind' of
+/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
+/// 'structured block', defined as:
+///
+///  in C or C++, an executable statement, possibly compound, with a single
+///  entry at the top and a single exit at the bottom
+///
+/// At the moment there is no real motivation to have a different AST node for
+/// those three, as they are semantically identical, and have only minor
+/// differences in the permitted list of clauses, which can be differentiated 
by
+/// the 'Kind'.
+class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  OpenACCComputeConstruct()
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{}) {}
+
+  OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start,
+  SourceLocation End)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
+   End) {
+assert((K == OpenACCDirectiveKind::Parallel ||
+K == OpenACCDirectiveKind::Serial ||
+K == OpenACCDirectiveKind::Kernels) &&
+   "Only parallel, serial, and kernels constructs should be "
+   "represented by this type");
+  }
+
+public:
+  static bool classof(const Stmt *T) {
+return T->getStmtClass() == OpenACCComputeConstructClass;
+  }
+
+  static OpenACCComputeConstruct *CreateEmpty(const ASTContext , 

[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread Alexey Bataev via cfe-commits


@@ -0,0 +1,140 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;
+
+protected:
+  OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K,
+ SourceLocation Start, SourceLocation End)
+  : OpenACCConstructStmt(SC, K, Start, End) {}
+
+  void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
+  Stmt *getAssociatedStmt() { return AssociatedStmt; }
+  const Stmt *getAssociatedStmt() const {
+return const_cast(this)
+->getAssociatedStmt();
+  }
+
+public:
+  child_range children() {
+if (getAssociatedStmt())
+  return child_range(,  + 1);
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+/// This class represents a compute construct, representing a 'Kind' of
+/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
+/// 'structured block', defined as:
+///
+///  in C or C++, an executable statement, possibly compound, with a single
+///  entry at the top and a single exit at the bottom
+///
+/// At the moment there is no real motivation to have a different AST node for
+/// those three, as they are semantically identical, and have only minor
+/// differences in the permitted list of clauses, which can be differentiated 
by
+/// the 'Kind'.
+class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  OpenACCComputeConstruct()
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{}) {}
+
+  OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start,
+  SourceLocation End)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
+   End) {
+assert((K == OpenACCDirectiveKind::Parallel ||
+K == OpenACCDirectiveKind::Serial ||
+K == OpenACCDirectiveKind::Kernels) &&
+   "Only parallel, serial, and kernels constructs should be "
+   "represented by this type");
+  }
+
+public:
+  static bool classof(const Stmt *T) {
+return T->getStmtClass() == OpenACCComputeConstructClass;
+  }
+
+  static OpenACCComputeConstruct *CreateEmpty(const ASTContext , 

[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread Erich Keane via cfe-commits


@@ -0,0 +1,140 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;
+
+protected:
+  OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K,
+ SourceLocation Start, SourceLocation End)
+  : OpenACCConstructStmt(SC, K, Start, End) {}
+
+  void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
+  Stmt *getAssociatedStmt() { return AssociatedStmt; }
+  const Stmt *getAssociatedStmt() const {
+return const_cast(this)
+->getAssociatedStmt();
+  }
+
+public:
+  child_range children() {
+if (getAssociatedStmt())
+  return child_range(,  + 1);
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+/// This class represents a compute construct, representing a 'Kind' of
+/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
+/// 'structured block', defined as:
+///
+///  in C or C++, an executable statement, possibly compound, with a single
+///  entry at the top and a single exit at the bottom
+///
+/// At the moment there is no real motivation to have a different AST node for
+/// those three, as they are semantically identical, and have only minor
+/// differences in the permitted list of clauses, which can be differentiated 
by
+/// the 'Kind'.
+class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  OpenACCComputeConstruct()
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{}) {}
+
+  OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start,
+  SourceLocation End)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
+   End) {
+assert((K == OpenACCDirectiveKind::Parallel ||
+K == OpenACCDirectiveKind::Serial ||
+K == OpenACCDirectiveKind::Kernels) &&
+   "Only parallel, serial, and kernels constructs should be "
+   "represented by this type");
+  }
+
+public:
+  static bool classof(const Stmt *T) {
+return T->getStmtClass() == OpenACCComputeConstructClass;
+  }
+
+  static OpenACCComputeConstruct *CreateEmpty(const ASTContext , 

[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread Alexey Bataev via cfe-commits


@@ -0,0 +1,140 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+/// \file
+/// This file defines OpenACC AST classes for statement-level contructs.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_AST_STMTOPENACC_H
+#define LLVM_CLANG_AST_STMTOPENACC_H
+
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/OpenACCKinds.h"
+#include "clang/Basic/SourceLocation.h"
+
+namespace clang {
+/// This is the base class for an OpenACC statement-level construct, other
+/// construct types are expected to inherit from this.
+class OpenACCConstructStmt : public Stmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  /// The directive kind. Each implementation of this interface should handle
+  /// specific kinds.
+  OpenACCDirectiveKind Kind = OpenACCDirectiveKind::Invalid;
+  /// The location of the directive statement, from the '#' to the last token 
of
+  /// the directive.
+  SourceRange Range;
+
+  // TODO OPENACC: Clauses should probably be collected in this class.
+
+protected:
+  OpenACCConstructStmt(StmtClass SC, OpenACCDirectiveKind K,
+   SourceLocation Start, SourceLocation End)
+  : Stmt(SC), Kind(K), Range(Start, End) {}
+
+public:
+  OpenACCDirectiveKind getDirectiveKind() const { return Kind; }
+
+  static bool classof(const Stmt *S) {
+return S->getStmtClass() >= firstOpenACCConstructStmtConstant &&
+   S->getStmtClass() <= lastOpenACCConstructStmtConstant;
+  }
+
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+
+/// This is a base class for any OpenACC statement-level constructs that have 
an
+/// associated statement. This class is not intended to be instantiated, but is
+/// a convenient place to hold the associated statement.
+class OpenACCAssociatedStmtConstruct : public OpenACCConstructStmt {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  template  friend class RecursiveASTVisitor;
+  Stmt *AssociatedStmt = nullptr;
+
+protected:
+  OpenACCAssociatedStmtConstruct(StmtClass SC, OpenACCDirectiveKind K,
+ SourceLocation Start, SourceLocation End)
+  : OpenACCConstructStmt(SC, K, Start, End) {}
+
+  void setAssociatedStmt(Stmt *S) { AssociatedStmt = S; }
+  Stmt *getAssociatedStmt() { return AssociatedStmt; }
+  const Stmt *getAssociatedStmt() const {
+return const_cast(this)
+->getAssociatedStmt();
+  }
+
+public:
+  child_range children() {
+if (getAssociatedStmt())
+  return child_range(,  + 1);
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_cast(this)->children();
+  }
+};
+/// This class represents a compute construct, representing a 'Kind' of
+/// `parallel', 'serial', or 'kernel'. These constructs are associated with a
+/// 'structured block', defined as:
+///
+///  in C or C++, an executable statement, possibly compound, with a single
+///  entry at the top and a single exit at the bottom
+///
+/// At the moment there is no real motivation to have a different AST node for
+/// those three, as they are semantically identical, and have only minor
+/// differences in the permitted list of clauses, which can be differentiated 
by
+/// the 'Kind'.
+class OpenACCComputeConstruct : public OpenACCAssociatedStmtConstruct {
+  friend class ASTStmtWriter;
+  friend class ASTStmtReader;
+  OpenACCComputeConstruct()
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass,
+   OpenACCDirectiveKind::Invalid,
+   SourceLocation{}, SourceLocation{}) {}
+
+  OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start,
+  SourceLocation End)
+  : OpenACCAssociatedStmtConstruct(OpenACCComputeConstructClass, K, Start,
+   End) {
+assert((K == OpenACCDirectiveKind::Parallel ||
+K == OpenACCDirectiveKind::Serial ||
+K == OpenACCDirectiveKind::Kernels) &&
+   "Only parallel, serial, and kernels constructs should be "
+   "represented by this type");
+  }
+
+public:
+  static bool classof(const Stmt *T) {
+return T->getStmtClass() == OpenACCComputeConstructClass;
+  }
+
+  static OpenACCComputeConstruct *CreateEmpty(const ASTContext , 

[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread Erich Keane via cfe-commits


@@ -2838,6 +2838,27 @@ void 
ASTStmtWriter::VisitOMPTargetParallelGenericLoopDirective(
   Code = serialization::STMT_OMP_TARGET_PARALLEL_GENERIC_LOOP_DIRECTIVE;
 }
 
+//===--===//
+// OpenACC Constructs/Directives.
+//===--===//
+void ASTStmtWriter::VisitOpenACCConstructStmt(OpenACCConstructStmt *S) {
+  Record.writeEnum(S->Kind);
+  Record.AddSourceRange(S->Range);
+  // TODO OpenACC: Serialize Clauses.

erichkeane wrote:

Note that I'm stealing 'TODO OpenACC:' as a comment prefix for things that need 
to happen 'really soon' for OpenACC.

https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Erich Keane (erichkeane)


Changes

'serial', 'parallel', and 'kernel' constructs are all considered
'Compute' constructs. This patch creates the AST type, plus the required
infrastructure for such a type, plus some base types that will be useful
in the future for breaking this up.

The only difference between the three is the 'kind'( plus some minor
 clause legalization rules, but those can be differentiated easily
 enough), so rather than representing them as separate AST nodes, it seems
to make sense to make them the same.

Additionally, no clause AST functionality is being implemented yet, as
that fits better in a separate patch, and this is enough to get the
'naked' constructs implemented.

This is otherwise an 'NFC' patch, as it doesn't alter execution at all,
so there aren't any tests.  I did this to break up the review workload
and to get feedback on the layout.

---

Patch is 26.95 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/81188.diff


24 Files Affected:

- (modified) clang/include/clang-c/Index.h (+5-1) 
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+22) 
- (added) clang/include/clang/AST/StmtOpenACC.h (+140) 
- (modified) clang/include/clang/AST/StmtVisitor.h (+2-1) 
- (modified) clang/include/clang/AST/TextNodeDumper.h (+1) 
- (modified) clang/include/clang/Basic/OpenACCKinds.h (+27-4) 
- (modified) clang/include/clang/Basic/StmtNodes.td (+6) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+3) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+1) 
- (modified) clang/lib/AST/CMakeLists.txt (+1) 
- (modified) clang/lib/AST/Stmt.cpp (+1) 
- (added) clang/lib/AST/StmtOpenACC.cpp (+33) 
- (modified) clang/lib/AST/StmtPrinter.cpp (+9) 
- (modified) clang/lib/AST/StmtProfile.cpp (+7) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+5) 
- (modified) clang/lib/CodeGen/CGStmt.cpp (+3) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+10) 
- (modified) clang/lib/Sema/SemaExceptionSpec.cpp (+1) 
- (modified) clang/lib/Sema/TreeTransform.h (+23) 
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+23) 
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+21) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+1) 
- (modified) clang/tools/libclang/CIndex.cpp (+2) 
- (modified) clang/tools/libclang/CXCursor.cpp (+3) 


``diff
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 6af41424ba89a1..8d939e8d21901b 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2145,7 +2145,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPScopeDirective = 306,
 
-  CXCursor_LastStmt = CXCursor_OMPScopeDirective,
+  /** OpenACC Compute Construct.
+   */
+  CXCursor_OpenACCComputeConstruct = 307,
+
+  CXCursor_LastStmt = CXCursor_OpenACCComputeConstruct,
 
   /**
* Cursor that represents the translation unit itself.
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 9da5206a21c34c..5080551ada4fc6 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -34,6 +34,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
+#include "clang/AST/StmtOpenACC.h"
 #include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
@@ -505,6 +506,9 @@ template  class RecursiveASTVisitor {
   bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
 
   bool PostVisitStmt(Stmt *S);
+  bool TraverseOpenACCConstructStmt(OpenACCConstructStmt *S);
+  bool
+  TraverseOpenACCAssociatedStmtConstruct(OpenACCAssociatedStmtConstruct *S);
 };
 
 template 
@@ -3910,6 +3914,24 @@ bool 
RecursiveASTVisitor::VisitOMPXBareClause(OMPXBareClause *C) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::TraverseOpenACCConstructStmt(
+OpenACCConstructStmt *) {
+  // TODO OpenACC: When we implement clauses, ensure we traverse them here.
+  return true;
+}
+
+template 
+bool RecursiveASTVisitor::TraverseOpenACCAssociatedStmtConstruct(
+OpenACCAssociatedStmtConstruct *S) {
+  TRY_TO(TraverseOpenACCConstructStmt(S));
+  TRY_TO(TraverseStmt(S->getAssociatedStmt()));
+  return true;
+}
+
+DEF_TRAVERSE_STMT(OpenACCComputeConstruct,
+  { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
+
 // FIXME: look at the following tricky-seeming exprs to see if we
 // need to recurse on anything.  These are ones that have methods
 // returning decls or qualtypes or nestednamespecifier -- though I'm
diff --git a/clang/include/clang/AST/StmtOpenACC.h 
b/clang/include/clang/AST/StmtOpenACC.h
new file mode 100644
index 00..67dd2b665a2189
--- /dev/null
+++ b/clang/include/clang/AST/StmtOpenACC.h
@@ -0,0 +1,140 @@
+//===- StmtOpenACC.h - Classes for 

[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Erich Keane (erichkeane)


Changes

'serial', 'parallel', and 'kernel' constructs are all considered
'Compute' constructs. This patch creates the AST type, plus the required
infrastructure for such a type, plus some base types that will be useful
in the future for breaking this up.

The only difference between the three is the 'kind'( plus some minor
 clause legalization rules, but those can be differentiated easily
 enough), so rather than representing them as separate AST nodes, it seems
to make sense to make them the same.

Additionally, no clause AST functionality is being implemented yet, as
that fits better in a separate patch, and this is enough to get the
'naked' constructs implemented.

This is otherwise an 'NFC' patch, as it doesn't alter execution at all,
so there aren't any tests.  I did this to break up the review workload
and to get feedback on the layout.

---

Patch is 26.95 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/81188.diff


24 Files Affected:

- (modified) clang/include/clang-c/Index.h (+5-1) 
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+22) 
- (added) clang/include/clang/AST/StmtOpenACC.h (+140) 
- (modified) clang/include/clang/AST/StmtVisitor.h (+2-1) 
- (modified) clang/include/clang/AST/TextNodeDumper.h (+1) 
- (modified) clang/include/clang/Basic/OpenACCKinds.h (+27-4) 
- (modified) clang/include/clang/Basic/StmtNodes.td (+6) 
- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+3) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+1) 
- (modified) clang/lib/AST/CMakeLists.txt (+1) 
- (modified) clang/lib/AST/Stmt.cpp (+1) 
- (added) clang/lib/AST/StmtOpenACC.cpp (+33) 
- (modified) clang/lib/AST/StmtPrinter.cpp (+9) 
- (modified) clang/lib/AST/StmtProfile.cpp (+7) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+5) 
- (modified) clang/lib/CodeGen/CGStmt.cpp (+3) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+10) 
- (modified) clang/lib/Sema/SemaExceptionSpec.cpp (+1) 
- (modified) clang/lib/Sema/TreeTransform.h (+23) 
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+23) 
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+21) 
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+1) 
- (modified) clang/tools/libclang/CIndex.cpp (+2) 
- (modified) clang/tools/libclang/CXCursor.cpp (+3) 


``diff
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 6af41424ba89a1..8d939e8d21901b 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -2145,7 +2145,11 @@ enum CXCursorKind {
*/
   CXCursor_OMPScopeDirective = 306,
 
-  CXCursor_LastStmt = CXCursor_OMPScopeDirective,
+  /** OpenACC Compute Construct.
+   */
+  CXCursor_OpenACCComputeConstruct = 307,
+
+  CXCursor_LastStmt = CXCursor_OpenACCComputeConstruct,
 
   /**
* Cursor that represents the translation unit itself.
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 9da5206a21c34c..5080551ada4fc6 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -34,6 +34,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
+#include "clang/AST/StmtOpenACC.h"
 #include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
@@ -505,6 +506,9 @@ template  class RecursiveASTVisitor {
   bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);
 
   bool PostVisitStmt(Stmt *S);
+  bool TraverseOpenACCConstructStmt(OpenACCConstructStmt *S);
+  bool
+  TraverseOpenACCAssociatedStmtConstruct(OpenACCAssociatedStmtConstruct *S);
 };
 
 template 
@@ -3910,6 +3914,24 @@ bool 
RecursiveASTVisitor::VisitOMPXBareClause(OMPXBareClause *C) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::TraverseOpenACCConstructStmt(
+OpenACCConstructStmt *) {
+  // TODO OpenACC: When we implement clauses, ensure we traverse them here.
+  return true;
+}
+
+template 
+bool RecursiveASTVisitor::TraverseOpenACCAssociatedStmtConstruct(
+OpenACCAssociatedStmtConstruct *S) {
+  TRY_TO(TraverseOpenACCConstructStmt(S));
+  TRY_TO(TraverseStmt(S->getAssociatedStmt()));
+  return true;
+}
+
+DEF_TRAVERSE_STMT(OpenACCComputeConstruct,
+  { TRY_TO(TraverseOpenACCAssociatedStmtConstruct(S)); })
+
 // FIXME: look at the following tricky-seeming exprs to see if we
 // need to recurse on anything.  These are ones that have methods
 // returning decls or qualtypes or nestednamespecifier -- though I'm
diff --git a/clang/include/clang/AST/StmtOpenACC.h 
b/clang/include/clang/AST/StmtOpenACC.h
new file mode 100644
index 00..67dd2b665a2189
--- /dev/null
+++ b/clang/include/clang/AST/StmtOpenACC.h
@@ -0,0 +1,140 @@
+//===- StmtOpenACC.h - Classes for OpenACC directives  --*- C++ 

[clang] [OpenACC] Implement AST for OpenACC Compute Constructs (PR #81188)

2024-02-08 Thread Erich Keane via cfe-commits

https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/81188
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits