[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
https://github.com/erichkeane closed https://github.com/llvm/llvm-project/pull/81874 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
https://github.com/erichkeane updated https://github.com/llvm/llvm-project/pull/81874 >From 35700522a658571e2abad279f327f4160fdb6c9d Mon Sep 17 00:00:00 2001 From: erichkeane Date: Thu, 15 Feb 2024 08:41:58 -0800 Subject: [PATCH 1/3] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure This patch is split off from #81659, and contains just the Sema infrastructure that we can later use to implement semantic analysis of OpenACC constructs. --- clang/include/clang/Parse/Parser.h | 16 +- clang/include/clang/Sema/Sema.h| 41 ++ clang/lib/Parse/ParseOpenACC.cpp | 47 +- clang/lib/Sema/CMakeLists.txt | 1 + clang/lib/Sema/SemaOpenACC.cpp | 47 ++ 5 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 clang/lib/Sema/SemaOpenACC.cpp diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index da18cf88edcc92..69b9e837fe8bef 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -3572,7 +3572,21 @@ class Parser : public CodeCompletionHandler { StmtResult ParseOpenACCDirectiveStmt(); private: - void ParseOpenACCDirective(); + /// A struct to hold the information that got parsed by ParseOpenACCDirective, + /// so that the callers of it can use that to construct the appropriate AST + /// nodes. + struct OpenACCDirectiveParseInfo { +OpenACCDirectiveKind DirKind; +SourceLocation StartLoc; +SourceLocation EndLoc; +// TODO OpenACC: Add Clause list here once we have a type for that. +// TODO OpenACC: As we implement support for the Atomic, Routine, Cache, and +// Wait constructs, we likely want to put that information in here as well. + }; + + /// Parses the OpenACC directive (the entire pragma) including the clause + /// list, but does not produce the main AST node. + OpenACCDirectiveParseInfo ParseOpenACCDirective(); /// Helper that parses an ID Expression based on the language options. ExprResult ParseOpenACCIDExpression(); /// Parses the variable list for the `cache` construct. diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index ed933f27f8df6b..ec4c451c584612 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -41,6 +41,7 @@ #include "clang/Basic/DarwinSDKInfo.h" #include "clang/Basic/ExpressionTraits.h" #include "clang/Basic/Module.h" +#include "clang/Basic/OpenACCKinds.h" #include "clang/Basic/OpenCLOptions.h" #include "clang/Basic/OpenMPKinds.h" #include "clang/Basic/PragmaKinds.h" @@ -12704,6 +12705,46 @@ class Sema final { OMPClause *ActOnOpenMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc); + //======// + // OpenACC directives and clauses. + + /// Called after parsing an OpenACC Clause so that it can be checked. + bool ActOnOpenACCClause(OpenACCClauseKind ClauseKind, + SourceLocation StartLoc); + + /// Called after the construct has been parsed, but clauses haven't been + /// parsed. This allows us to diagnose not-implemented, as well as set up any + /// state required for parsing the clauses. + void ActOnOpenACCConstruct(OpenACCDirectiveKind K, SourceLocation StartLoc); + + /// Called after the directive, including its clauses, have been parsed and + /// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES + /// happen before any associated declarations or statements have been parsed. + /// This function is only called when we are parsing a 'statement' context. + bool ActOnStartOpenACCStmtDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc); + + /// Called after the directive, including its clauses, have been parsed and + /// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES + /// happen before any associated declarations or statements have been parsed. + /// This function is only called when we are parsing a 'Decl' context. + bool ActOnStartOpenACCDeclDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc); + /// Called when we encounter an associated statement for our construct, this + /// should check legality of the statement as it appertains to this Construct. + StmtResult ActOnOpenACCAssociatedStmt(OpenACCDirectiveKind K, +StmtResult AssocStmt); + + /// Called after the directive has been completely parsed, including the + /// declaration group or associated statement. + StmtResult ActOnEndOpenACCStmtDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc, + SourceLocation EndLoc, + StmtResult AssocStmt); + /// Called after the
[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 46122082a61ef5bb2871d2d9158739133ad0e113 2b4b7d8cbc02d44eb1c0302f9d92e42ef8d9aff4 -- clang/lib/Sema/SemaOpenACC.cpp clang/include/clang/Parse/Parser.h clang/include/clang/Sema/Sema.h clang/lib/Parse/ParseOpenACC.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp index a122880aa1..8157656246 100644 --- a/clang/lib/Parse/ParseOpenACC.cpp +++ b/clang/lib/Parse/ParseOpenACC.cpp @@ -1231,4 +1231,3 @@ StmtResult Parser::ParseOpenACCDirectiveStmt() { return getActions().ActOnEndOpenACCStmtDirective( DirInfo.DirKind, DirInfo.StartLoc, DirInfo.EndLoc, AssocStmt); } - `` https://github.com/llvm/llvm-project/pull/81874 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
https://github.com/erichkeane updated https://github.com/llvm/llvm-project/pull/81874 >From 35700522a658571e2abad279f327f4160fdb6c9d Mon Sep 17 00:00:00 2001 From: erichkeane Date: Thu, 15 Feb 2024 08:41:58 -0800 Subject: [PATCH 1/2] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure This patch is split off from #81659, and contains just the Sema infrastructure that we can later use to implement semantic analysis of OpenACC constructs. --- clang/include/clang/Parse/Parser.h | 16 +- clang/include/clang/Sema/Sema.h| 41 ++ clang/lib/Parse/ParseOpenACC.cpp | 47 +- clang/lib/Sema/CMakeLists.txt | 1 + clang/lib/Sema/SemaOpenACC.cpp | 47 ++ 5 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 clang/lib/Sema/SemaOpenACC.cpp diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index da18cf88edcc92..69b9e837fe8bef 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -3572,7 +3572,21 @@ class Parser : public CodeCompletionHandler { StmtResult ParseOpenACCDirectiveStmt(); private: - void ParseOpenACCDirective(); + /// A struct to hold the information that got parsed by ParseOpenACCDirective, + /// so that the callers of it can use that to construct the appropriate AST + /// nodes. + struct OpenACCDirectiveParseInfo { +OpenACCDirectiveKind DirKind; +SourceLocation StartLoc; +SourceLocation EndLoc; +// TODO OpenACC: Add Clause list here once we have a type for that. +// TODO OpenACC: As we implement support for the Atomic, Routine, Cache, and +// Wait constructs, we likely want to put that information in here as well. + }; + + /// Parses the OpenACC directive (the entire pragma) including the clause + /// list, but does not produce the main AST node. + OpenACCDirectiveParseInfo ParseOpenACCDirective(); /// Helper that parses an ID Expression based on the language options. ExprResult ParseOpenACCIDExpression(); /// Parses the variable list for the `cache` construct. diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index ed933f27f8df6b..ec4c451c584612 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -41,6 +41,7 @@ #include "clang/Basic/DarwinSDKInfo.h" #include "clang/Basic/ExpressionTraits.h" #include "clang/Basic/Module.h" +#include "clang/Basic/OpenACCKinds.h" #include "clang/Basic/OpenCLOptions.h" #include "clang/Basic/OpenMPKinds.h" #include "clang/Basic/PragmaKinds.h" @@ -12704,6 +12705,46 @@ class Sema final { OMPClause *ActOnOpenMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc); + //======// + // OpenACC directives and clauses. + + /// Called after parsing an OpenACC Clause so that it can be checked. + bool ActOnOpenACCClause(OpenACCClauseKind ClauseKind, + SourceLocation StartLoc); + + /// Called after the construct has been parsed, but clauses haven't been + /// parsed. This allows us to diagnose not-implemented, as well as set up any + /// state required for parsing the clauses. + void ActOnOpenACCConstruct(OpenACCDirectiveKind K, SourceLocation StartLoc); + + /// Called after the directive, including its clauses, have been parsed and + /// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES + /// happen before any associated declarations or statements have been parsed. + /// This function is only called when we are parsing a 'statement' context. + bool ActOnStartOpenACCStmtDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc); + + /// Called after the directive, including its clauses, have been parsed and + /// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES + /// happen before any associated declarations or statements have been parsed. + /// This function is only called when we are parsing a 'Decl' context. + bool ActOnStartOpenACCDeclDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc); + /// Called when we encounter an associated statement for our construct, this + /// should check legality of the statement as it appertains to this Construct. + StmtResult ActOnOpenACCAssociatedStmt(OpenACCDirectiveKind K, +StmtResult AssocStmt); + + /// Called after the directive has been completely parsed, including the + /// declaration group or associated statement. + StmtResult ActOnEndOpenACCStmtDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc, + SourceLocation EndLoc, + StmtResult AssocStmt); + /// Called after the
[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
https://github.com/alexey-bataev approved this pull request. LG https://github.com/llvm/llvm-project/pull/81874 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
@@ -1197,7 +1215,20 @@ StmtResult Parser::ParseOpenACCDirectiveStmt() { ParsingOpenACCDirectiveRAII DirScope(*this); ConsumeAnnotationToken(); - ParseOpenACCDirective(); + OpenACCDirectiveParseInfo DirInfo = ParseOpenACCDirective(); + if (getActions().ActOnStartOpenACCDeclDirective(DirInfo.DirKind, + DirInfo.StartLoc)) +return StmtError(); + + StmtResult AssocStmt; + + if (doesDirectiveHaveAssociatedStmt(DirInfo.DirKind)) { erichkeane wrote: This section ends up being slightly worse without being able to check the AST kind here, so we need a separate function to check whether we need to parse one. However, this removes the ASTContext function that was troublesome. https://github.com/llvm/llvm-project/pull/81874 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
https://github.com/erichkeane edited https://github.com/llvm/llvm-project/pull/81874 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
https://github.com/erichkeane commented: @alexey-bataev : as requested, I've split off the infrastructure bits. Once this is committed, I'll move the 'warning's as a Review-after-commit so that the other patch can be easier to review. https://github.com/llvm/llvm-project/pull/81874 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Erich Keane (erichkeane) Changes This patch is split off from #81659, and contains just the Sema infrastructure that we can later use to implement semantic analysis of OpenACC constructs. --- Full diff: https://github.com/llvm/llvm-project/pull/81874.diff 5 Files Affected: - (modified) clang/include/clang/Parse/Parser.h (+15-1) - (modified) clang/include/clang/Sema/Sema.h (+41) - (modified) clang/lib/Parse/ParseOpenACC.cpp (+39-8) - (modified) clang/lib/Sema/CMakeLists.txt (+1) - (added) clang/lib/Sema/SemaOpenACC.cpp (+47) ``diff diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index da18cf88edcc92..69b9e837fe8bef 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -3572,7 +3572,21 @@ class Parser : public CodeCompletionHandler { StmtResult ParseOpenACCDirectiveStmt(); private: - void ParseOpenACCDirective(); + /// A struct to hold the information that got parsed by ParseOpenACCDirective, + /// so that the callers of it can use that to construct the appropriate AST + /// nodes. + struct OpenACCDirectiveParseInfo { +OpenACCDirectiveKind DirKind; +SourceLocation StartLoc; +SourceLocation EndLoc; +// TODO OpenACC: Add Clause list here once we have a type for that. +// TODO OpenACC: As we implement support for the Atomic, Routine, Cache, and +// Wait constructs, we likely want to put that information in here as well. + }; + + /// Parses the OpenACC directive (the entire pragma) including the clause + /// list, but does not produce the main AST node. + OpenACCDirectiveParseInfo ParseOpenACCDirective(); /// Helper that parses an ID Expression based on the language options. ExprResult ParseOpenACCIDExpression(); /// Parses the variable list for the `cache` construct. diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index ed933f27f8df6b..ec4c451c584612 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -41,6 +41,7 @@ #include "clang/Basic/DarwinSDKInfo.h" #include "clang/Basic/ExpressionTraits.h" #include "clang/Basic/Module.h" +#include "clang/Basic/OpenACCKinds.h" #include "clang/Basic/OpenCLOptions.h" #include "clang/Basic/OpenMPKinds.h" #include "clang/Basic/PragmaKinds.h" @@ -12704,6 +12705,46 @@ class Sema final { OMPClause *ActOnOpenMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc); + //======// + // OpenACC directives and clauses. + + /// Called after parsing an OpenACC Clause so that it can be checked. + bool ActOnOpenACCClause(OpenACCClauseKind ClauseKind, + SourceLocation StartLoc); + + /// Called after the construct has been parsed, but clauses haven't been + /// parsed. This allows us to diagnose not-implemented, as well as set up any + /// state required for parsing the clauses. + void ActOnOpenACCConstruct(OpenACCDirectiveKind K, SourceLocation StartLoc); + + /// Called after the directive, including its clauses, have been parsed and + /// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES + /// happen before any associated declarations or statements have been parsed. + /// This function is only called when we are parsing a 'statement' context. + bool ActOnStartOpenACCStmtDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc); + + /// Called after the directive, including its clauses, have been parsed and + /// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES + /// happen before any associated declarations or statements have been parsed. + /// This function is only called when we are parsing a 'Decl' context. + bool ActOnStartOpenACCDeclDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc); + /// Called when we encounter an associated statement for our construct, this + /// should check legality of the statement as it appertains to this Construct. + StmtResult ActOnOpenACCAssociatedStmt(OpenACCDirectiveKind K, +StmtResult AssocStmt); + + /// Called after the directive has been completely parsed, including the + /// declaration group or associated statement. + StmtResult ActOnEndOpenACCStmtDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc, + SourceLocation EndLoc, + StmtResult AssocStmt); + /// Called after the directive has been completely parsed, including the + /// declaration group or associated statement. + DeclGroupRef ActOnEndOpenACCDeclDirective(); + /// The kind of conversion being performed. enum CheckedConversionKind { /// An implicit
[clang] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure (PR #81874)
https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/81874 This patch is split off from #81659, and contains just the Sema infrastructure that we can later use to implement semantic analysis of OpenACC constructs. >From 35700522a658571e2abad279f327f4160fdb6c9d Mon Sep 17 00:00:00 2001 From: erichkeane Date: Thu, 15 Feb 2024 08:41:58 -0800 Subject: [PATCH] [OpenACC][NFC] Implement basic OpenACC Sema infrastructure This patch is split off from #81659, and contains just the Sema infrastructure that we can later use to implement semantic analysis of OpenACC constructs. --- clang/include/clang/Parse/Parser.h | 16 +- clang/include/clang/Sema/Sema.h| 41 ++ clang/lib/Parse/ParseOpenACC.cpp | 47 +- clang/lib/Sema/CMakeLists.txt | 1 + clang/lib/Sema/SemaOpenACC.cpp | 47 ++ 5 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 clang/lib/Sema/SemaOpenACC.cpp diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index da18cf88edcc92..69b9e837fe8bef 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -3572,7 +3572,21 @@ class Parser : public CodeCompletionHandler { StmtResult ParseOpenACCDirectiveStmt(); private: - void ParseOpenACCDirective(); + /// A struct to hold the information that got parsed by ParseOpenACCDirective, + /// so that the callers of it can use that to construct the appropriate AST + /// nodes. + struct OpenACCDirectiveParseInfo { +OpenACCDirectiveKind DirKind; +SourceLocation StartLoc; +SourceLocation EndLoc; +// TODO OpenACC: Add Clause list here once we have a type for that. +// TODO OpenACC: As we implement support for the Atomic, Routine, Cache, and +// Wait constructs, we likely want to put that information in here as well. + }; + + /// Parses the OpenACC directive (the entire pragma) including the clause + /// list, but does not produce the main AST node. + OpenACCDirectiveParseInfo ParseOpenACCDirective(); /// Helper that parses an ID Expression based on the language options. ExprResult ParseOpenACCIDExpression(); /// Parses the variable list for the `cache` construct. diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index ed933f27f8df6b..ec4c451c584612 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -41,6 +41,7 @@ #include "clang/Basic/DarwinSDKInfo.h" #include "clang/Basic/ExpressionTraits.h" #include "clang/Basic/Module.h" +#include "clang/Basic/OpenACCKinds.h" #include "clang/Basic/OpenCLOptions.h" #include "clang/Basic/OpenMPKinds.h" #include "clang/Basic/PragmaKinds.h" @@ -12704,6 +12705,46 @@ class Sema final { OMPClause *ActOnOpenMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc); + //======// + // OpenACC directives and clauses. + + /// Called after parsing an OpenACC Clause so that it can be checked. + bool ActOnOpenACCClause(OpenACCClauseKind ClauseKind, + SourceLocation StartLoc); + + /// Called after the construct has been parsed, but clauses haven't been + /// parsed. This allows us to diagnose not-implemented, as well as set up any + /// state required for parsing the clauses. + void ActOnOpenACCConstruct(OpenACCDirectiveKind K, SourceLocation StartLoc); + + /// Called after the directive, including its clauses, have been parsed and + /// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES + /// happen before any associated declarations or statements have been parsed. + /// This function is only called when we are parsing a 'statement' context. + bool ActOnStartOpenACCStmtDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc); + + /// Called after the directive, including its clauses, have been parsed and + /// parsing has consumed the 'annot_pragma_openacc_end' token. This DOES + /// happen before any associated declarations or statements have been parsed. + /// This function is only called when we are parsing a 'Decl' context. + bool ActOnStartOpenACCDeclDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc); + /// Called when we encounter an associated statement for our construct, this + /// should check legality of the statement as it appertains to this Construct. + StmtResult ActOnOpenACCAssociatedStmt(OpenACCDirectiveKind K, +StmtResult AssocStmt); + + /// Called after the directive has been completely parsed, including the + /// declaration group or associated statement. + StmtResult ActOnEndOpenACCStmtDirective(OpenACCDirectiveKind K, + SourceLocation StartLoc, +