[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/87821 Now that we have AST nodes for OpenACC Clauses, this patch adds their creation to Sema and makes the Parser call all the required functions. This also redoes TreeTransform to work with the clauses/make sure they are transformed. Much of this is NFC, since there is no clause we can test this behavior with. However, there IS one noticable change; we are now no longer diagnosing that a clause is 'not implemented' unless it there was no errors parsing its parameters. This is because it cleans up how we create and diagnose clauses. >From ca5f957bb002d79997e630cdf1aaad5703ea2ba4 Mon Sep 17 00:00:00 2001 From: erichkeane Date: Fri, 5 Apr 2024 10:53:47 -0700 Subject: [PATCH] [OpenACC] Implement Sema work for OpenACC Clauses Now that we have AST nodes for OpenACC Clauses, this patch adds their creation to Sema and makes the Parser call all the required functions. This also redoes TreeTransform to work with the clauses/make sure they are transformed. Much of this is NFC, since there is no clause we can test this behavior with. However, there IS one noticable change; we are now no longer diagnosing that a clause is 'not implemented' unless it there was no errors parsing its parameters. This is because it cleans up how we create and diagnose clauses. --- .../clang/Basic/DiagnosticSemaKinds.td| 2 + clang/include/clang/Parse/Parser.h| 34 +- clang/include/clang/Sema/SemaOpenACC.h| 39 +- clang/lib/Parse/ParseOpenACC.cpp | 142 +++-- clang/lib/Sema/SemaOpenACC.cpp| 69 ++- clang/lib/Sema/TreeTransform.h| 79 ++- clang/test/ParserOpenACC/parse-clauses.c | 573 +++--- clang/test/ParserOpenACC/parse-clauses.cpp| 9 +- clang/test/ParserOpenACC/parse-wait-clause.c | 102 ++-- 9 files changed, 540 insertions(+), 509 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index df57f5e6ce11ba..238931770da3a2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12252,6 +12252,8 @@ def warn_acc_clause_unimplemented def err_acc_construct_appertainment : Error<"OpenACC construct '%0' cannot be used here; it can only " "be used in a statement context">; +def err_acc_clause_appertainment +: Error<"OpenACC '%1' clause not valid on '%0' directive">; def err_acc_branch_in_out_compute_construct : Error<"invalid %select{branch|return|throw}0 %select{out of|into}1 " "OpenACC Compute Construct">; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 580bf2a5d79df5..8bc929b1dfe4bb 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -41,6 +41,7 @@ namespace clang { class InMessageExpressionRAIIObject; class PoisonSEHIdentifiersRAIIObject; class OMPClause; + class OpenACCClause; class ObjCTypeParamList; struct OMPTraitProperty; struct OMPTraitSelector; @@ -3594,11 +3595,26 @@ class Parser : public CodeCompletionHandler { OpenACCDirectiveKind DirKind; SourceLocation StartLoc; SourceLocation EndLoc; -// TODO OpenACC: Add Clause list here once we have a type for that. +SmallVector Clauses; // 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. }; + /// Represents the 'error' state of parsing an OpenACC Clause, and stores + /// whether we can continue parsing, or should give up on the directive. + enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 }; + + /// A type to represent the state of parsing an OpenACC Clause. Situations + /// that result in an OpenACCClause pointer are a success and can continue + /// parsing, however some other situations can also continue. + /// FIXME: This is better represented as a std::expected when we get C++23. + using OpenACCClauseParseResult = + llvm::PointerIntPair; + + OpenACCClauseParseResult OpenACCCanContinue(); + OpenACCClauseParseResult OpenACCCannotContinue(); + OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause); + /// Parses the OpenACC directive (the entire pragma) including the clause /// list, but does not produce the main AST node. OpenACCDirectiveParseInfo ParseOpenACCDirective(); @@ -3613,12 +3629,18 @@ class Parser : public CodeCompletionHandler { bool ParseOpenACCClauseVarList(OpenACCClauseKind Kind); /// Parses any parameters for an OpenACC Clause, including required/optional /// parens. - bool ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind, -OpenACCClauseKind Kind); - /// Parses a single clause in a clause-list for OpenACC. - bool ParseOpenACCClause(OpenACCDirectiveKind DirKind); + OpenACCC
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Erich Keane (erichkeane) Changes Now that we have AST nodes for OpenACC Clauses, this patch adds their creation to Sema and makes the Parser call all the required functions. This also redoes TreeTransform to work with the clauses/make sure they are transformed. Much of this is NFC, since there is no clause we can test this behavior with. However, there IS one noticable change; we are now no longer diagnosing that a clause is 'not implemented' unless it there was no errors parsing its parameters. This is because it cleans up how we create and diagnose clauses. --- Patch is 86.31 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/87821.diff 9 Files Affected: - (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) - (modified) clang/include/clang/Parse/Parser.h (+28-6) - (modified) clang/include/clang/Sema/SemaOpenACC.h (+37-2) - (modified) clang/lib/Parse/ParseOpenACC.cpp (+89-53) - (modified) clang/lib/Sema/SemaOpenACC.cpp (+53-16) - (modified) clang/lib/Sema/TreeTransform.h (+64-15) - (modified) clang/test/ParserOpenACC/parse-clauses.c (+223-350) - (modified) clang/test/ParserOpenACC/parse-clauses.cpp (+3-6) - (modified) clang/test/ParserOpenACC/parse-wait-clause.c (+41-61) ``diff diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index df57f5e6ce11ba..238931770da3a2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12252,6 +12252,8 @@ def warn_acc_clause_unimplemented def err_acc_construct_appertainment : Error<"OpenACC construct '%0' cannot be used here; it can only " "be used in a statement context">; +def err_acc_clause_appertainment +: Error<"OpenACC '%1' clause not valid on '%0' directive">; def err_acc_branch_in_out_compute_construct : Error<"invalid %select{branch|return|throw}0 %select{out of|into}1 " "OpenACC Compute Construct">; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 580bf2a5d79df5..8bc929b1dfe4bb 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -41,6 +41,7 @@ namespace clang { class InMessageExpressionRAIIObject; class PoisonSEHIdentifiersRAIIObject; class OMPClause; + class OpenACCClause; class ObjCTypeParamList; struct OMPTraitProperty; struct OMPTraitSelector; @@ -3594,11 +3595,26 @@ class Parser : public CodeCompletionHandler { OpenACCDirectiveKind DirKind; SourceLocation StartLoc; SourceLocation EndLoc; -// TODO OpenACC: Add Clause list here once we have a type for that. +SmallVector Clauses; // 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. }; + /// Represents the 'error' state of parsing an OpenACC Clause, and stores + /// whether we can continue parsing, or should give up on the directive. + enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 }; + + /// A type to represent the state of parsing an OpenACC Clause. Situations + /// that result in an OpenACCClause pointer are a success and can continue + /// parsing, however some other situations can also continue. + /// FIXME: This is better represented as a std::expected when we get C++23. + using OpenACCClauseParseResult = + llvm::PointerIntPair; + + OpenACCClauseParseResult OpenACCCanContinue(); + OpenACCClauseParseResult OpenACCCannotContinue(); + OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause); + /// Parses the OpenACC directive (the entire pragma) including the clause /// list, but does not produce the main AST node. OpenACCDirectiveParseInfo ParseOpenACCDirective(); @@ -3613,12 +3629,18 @@ class Parser : public CodeCompletionHandler { bool ParseOpenACCClauseVarList(OpenACCClauseKind Kind); /// Parses any parameters for an OpenACC Clause, including required/optional /// parens. - bool ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind, -OpenACCClauseKind Kind); - /// Parses a single clause in a clause-list for OpenACC. - bool ParseOpenACCClause(OpenACCDirectiveKind DirKind); + OpenACCClauseParseResult + ParseOpenACCClauseParams(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind, OpenACCClauseKind Kind, + SourceLocation ClauseLoc); + /// Parses a single clause in a clause-list for OpenACC. Returns nullptr on + /// error. + OpenACCClauseParseResult + ParseOpenACCClause(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind); /// Parses the clause-list for an OpenACC directive. - void ParseOpenACCClauseList(OpenACCDirectiveKind DirKind); + SmallVector + ParseOpenACCClauseList(OpenACCDirecti
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/Endilll edited https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/Endilll commented: I hope #87634 will be merged soon, so you can get rid of `SemaRef.Diag()` here. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -12252,6 +12252,8 @@ def warn_acc_clause_unimplemented def err_acc_construct_appertainment : Error<"OpenACC construct '%0' cannot be used here; it can only " "be used in a statement context">; +def err_acc_clause_appertainment +: Error<"OpenACC '%1' clause not valid on '%0' directive">; Endilll wrote: ```suggestion : Error<"OpenACC '%1' clause is not valid on '%0' directive">; ``` https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -3594,11 +3595,26 @@ class Parser : public CodeCompletionHandler { OpenACCDirectiveKind DirKind; SourceLocation StartLoc; SourceLocation EndLoc; -// TODO OpenACC: Add Clause list here once we have a type for that. +SmallVector Clauses; // 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. }; + /// Represents the 'error' state of parsing an OpenACC Clause, and stores + /// whether we can continue parsing, or should give up on the directive. + enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 }; + + /// A type to represent the state of parsing an OpenACC Clause. Situations + /// that result in an OpenACCClause pointer are a success and can continue + /// parsing, however some other situations can also continue. + /// FIXME: This is better represented as a std::expected when we get C++23. Endilll wrote: C++23 is not even on the horizon for us. Have you considered using `llvm::Expected` today? https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -3594,11 +3595,26 @@ class Parser : public CodeCompletionHandler { OpenACCDirectiveKind DirKind; SourceLocation StartLoc; SourceLocation EndLoc; -// TODO OpenACC: Add Clause list here once we have a type for that. +SmallVector Clauses; // 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. }; + /// Represents the 'error' state of parsing an OpenACC Clause, and stores + /// whether we can continue parsing, or should give up on the directive. + enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 }; + + /// A type to represent the state of parsing an OpenACC Clause. Situations + /// that result in an OpenACCClause pointer are a success and can continue + /// parsing, however some other situations can also continue. + /// FIXME: This is better represented as a std::expected when we get C++23. erichkeane wrote: I DID, but llvm::Expected doesn't support arbitrary 'error' types, just `llvm::Error`. My attempt using that ended up being pretty awkward thanks to it. Additionally, this ends up being a little better 'space' wise, since we know we only have 2 values (and thus can use a `PointerIntPair`) with what IMO looks like a nicer interface. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/erichkeane updated https://github.com/llvm/llvm-project/pull/87821 >From ca5f957bb002d79997e630cdf1aaad5703ea2ba4 Mon Sep 17 00:00:00 2001 From: erichkeane Date: Fri, 5 Apr 2024 10:53:47 -0700 Subject: [PATCH 1/2] [OpenACC] Implement Sema work for OpenACC Clauses Now that we have AST nodes for OpenACC Clauses, this patch adds their creation to Sema and makes the Parser call all the required functions. This also redoes TreeTransform to work with the clauses/make sure they are transformed. Much of this is NFC, since there is no clause we can test this behavior with. However, there IS one noticable change; we are now no longer diagnosing that a clause is 'not implemented' unless it there was no errors parsing its parameters. This is because it cleans up how we create and diagnose clauses. --- .../clang/Basic/DiagnosticSemaKinds.td| 2 + clang/include/clang/Parse/Parser.h| 34 +- clang/include/clang/Sema/SemaOpenACC.h| 39 +- clang/lib/Parse/ParseOpenACC.cpp | 142 +++-- clang/lib/Sema/SemaOpenACC.cpp| 69 ++- clang/lib/Sema/TreeTransform.h| 79 ++- clang/test/ParserOpenACC/parse-clauses.c | 573 +++--- clang/test/ParserOpenACC/parse-clauses.cpp| 9 +- clang/test/ParserOpenACC/parse-wait-clause.c | 102 ++-- 9 files changed, 540 insertions(+), 509 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index df57f5e6ce11ba..238931770da3a2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12252,6 +12252,8 @@ def warn_acc_clause_unimplemented def err_acc_construct_appertainment : Error<"OpenACC construct '%0' cannot be used here; it can only " "be used in a statement context">; +def err_acc_clause_appertainment +: Error<"OpenACC '%1' clause not valid on '%0' directive">; def err_acc_branch_in_out_compute_construct : Error<"invalid %select{branch|return|throw}0 %select{out of|into}1 " "OpenACC Compute Construct">; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 580bf2a5d79df5..8bc929b1dfe4bb 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -41,6 +41,7 @@ namespace clang { class InMessageExpressionRAIIObject; class PoisonSEHIdentifiersRAIIObject; class OMPClause; + class OpenACCClause; class ObjCTypeParamList; struct OMPTraitProperty; struct OMPTraitSelector; @@ -3594,11 +3595,26 @@ class Parser : public CodeCompletionHandler { OpenACCDirectiveKind DirKind; SourceLocation StartLoc; SourceLocation EndLoc; -// TODO OpenACC: Add Clause list here once we have a type for that. +SmallVector Clauses; // 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. }; + /// Represents the 'error' state of parsing an OpenACC Clause, and stores + /// whether we can continue parsing, or should give up on the directive. + enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 }; + + /// A type to represent the state of parsing an OpenACC Clause. Situations + /// that result in an OpenACCClause pointer are a success and can continue + /// parsing, however some other situations can also continue. + /// FIXME: This is better represented as a std::expected when we get C++23. + using OpenACCClauseParseResult = + llvm::PointerIntPair; + + OpenACCClauseParseResult OpenACCCanContinue(); + OpenACCClauseParseResult OpenACCCannotContinue(); + OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause); + /// Parses the OpenACC directive (the entire pragma) including the clause /// list, but does not produce the main AST node. OpenACCDirectiveParseInfo ParseOpenACCDirective(); @@ -3613,12 +3629,18 @@ class Parser : public CodeCompletionHandler { bool ParseOpenACCClauseVarList(OpenACCClauseKind Kind); /// Parses any parameters for an OpenACC Clause, including required/optional /// parens. - bool ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind, -OpenACCClauseKind Kind); - /// Parses a single clause in a clause-list for OpenACC. - bool ParseOpenACCClause(OpenACCDirectiveKind DirKind); + OpenACCClauseParseResult + ParseOpenACCClauseParams(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind, OpenACCClauseKind Kind, + SourceLocation ClauseLoc); + /// Parses a single clause in a clause-list for OpenACC. Returns nullptr on + /// error. + OpenACCClauseParseResult + ParseOpenACCClause(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind); /// Parses the clause-list for an OpenACC directive. - void ParseOpenACCClauseList(OpenACCDirectiveKind
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/erichkeane updated https://github.com/llvm/llvm-project/pull/87821 >From ca5f957bb002d79997e630cdf1aaad5703ea2ba4 Mon Sep 17 00:00:00 2001 From: erichkeane Date: Fri, 5 Apr 2024 10:53:47 -0700 Subject: [PATCH 1/2] [OpenACC] Implement Sema work for OpenACC Clauses Now that we have AST nodes for OpenACC Clauses, this patch adds their creation to Sema and makes the Parser call all the required functions. This also redoes TreeTransform to work with the clauses/make sure they are transformed. Much of this is NFC, since there is no clause we can test this behavior with. However, there IS one noticable change; we are now no longer diagnosing that a clause is 'not implemented' unless it there was no errors parsing its parameters. This is because it cleans up how we create and diagnose clauses. --- .../clang/Basic/DiagnosticSemaKinds.td| 2 + clang/include/clang/Parse/Parser.h| 34 +- clang/include/clang/Sema/SemaOpenACC.h| 39 +- clang/lib/Parse/ParseOpenACC.cpp | 142 +++-- clang/lib/Sema/SemaOpenACC.cpp| 69 ++- clang/lib/Sema/TreeTransform.h| 79 ++- clang/test/ParserOpenACC/parse-clauses.c | 573 +++--- clang/test/ParserOpenACC/parse-clauses.cpp| 9 +- clang/test/ParserOpenACC/parse-wait-clause.c | 102 ++-- 9 files changed, 540 insertions(+), 509 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index df57f5e6ce11ba..238931770da3a2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12252,6 +12252,8 @@ def warn_acc_clause_unimplemented def err_acc_construct_appertainment : Error<"OpenACC construct '%0' cannot be used here; it can only " "be used in a statement context">; +def err_acc_clause_appertainment +: Error<"OpenACC '%1' clause not valid on '%0' directive">; def err_acc_branch_in_out_compute_construct : Error<"invalid %select{branch|return|throw}0 %select{out of|into}1 " "OpenACC Compute Construct">; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 580bf2a5d79df5..8bc929b1dfe4bb 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -41,6 +41,7 @@ namespace clang { class InMessageExpressionRAIIObject; class PoisonSEHIdentifiersRAIIObject; class OMPClause; + class OpenACCClause; class ObjCTypeParamList; struct OMPTraitProperty; struct OMPTraitSelector; @@ -3594,11 +3595,26 @@ class Parser : public CodeCompletionHandler { OpenACCDirectiveKind DirKind; SourceLocation StartLoc; SourceLocation EndLoc; -// TODO OpenACC: Add Clause list here once we have a type for that. +SmallVector Clauses; // 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. }; + /// Represents the 'error' state of parsing an OpenACC Clause, and stores + /// whether we can continue parsing, or should give up on the directive. + enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 }; + + /// A type to represent the state of parsing an OpenACC Clause. Situations + /// that result in an OpenACCClause pointer are a success and can continue + /// parsing, however some other situations can also continue. + /// FIXME: This is better represented as a std::expected when we get C++23. + using OpenACCClauseParseResult = + llvm::PointerIntPair; + + OpenACCClauseParseResult OpenACCCanContinue(); + OpenACCClauseParseResult OpenACCCannotContinue(); + OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause); + /// Parses the OpenACC directive (the entire pragma) including the clause /// list, but does not produce the main AST node. OpenACCDirectiveParseInfo ParseOpenACCDirective(); @@ -3613,12 +3629,18 @@ class Parser : public CodeCompletionHandler { bool ParseOpenACCClauseVarList(OpenACCClauseKind Kind); /// Parses any parameters for an OpenACC Clause, including required/optional /// parens. - bool ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind, -OpenACCClauseKind Kind); - /// Parses a single clause in a clause-list for OpenACC. - bool ParseOpenACCClause(OpenACCDirectiveKind DirKind); + OpenACCClauseParseResult + ParseOpenACCClauseParams(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind, OpenACCClauseKind Kind, + SourceLocation ClauseLoc); + /// Parses a single clause in a clause-list for OpenACC. Returns nullptr on + /// error. + OpenACCClauseParseResult + ParseOpenACCClause(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind); /// Parses the clause-list for an OpenACC directive. - void ParseOpenACCClauseList(OpenACCDirectiveKind
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
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 f6357bb4283e72d1248b9c7eb67d98bea71d5f50 27da3822961873340af021a5cbf136a155b5f110 -- clang/include/clang/Parse/Parser.h clang/include/clang/Sema/SemaOpenACC.h clang/lib/Parse/ParseOpenACC.cpp clang/lib/Sema/SemaOpenACC.cpp clang/lib/Sema/TreeTransform.h clang/test/ParserOpenACC/parse-clauses.c clang/test/ParserOpenACC/parse-clauses.cpp clang/test/ParserOpenACC/parse-wait-clause.c `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/Sema/SemaOpenACC.h b/clang/include/clang/Sema/SemaOpenACC.h index bd27418e4c..f6db366572 100644 --- a/clang/include/clang/Sema/SemaOpenACC.h +++ b/clang/include/clang/Sema/SemaOpenACC.h @@ -21,7 +21,7 @@ #include "clang/Sema/SemaBase.h" namespace clang { - class OpenACCClause; +class OpenACCClause; class SemaOpenACC : public SemaBase { public: `` https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -37,6 +37,32 @@ bool diagnoseConstructAppertainment(SemaOpenACC &S, OpenACCDirectiveKind K, } return false; } + +bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind, +OpenACCClauseKind ClauseKind) { + switch (ClauseKind) { +// FIXME: For each clause as we implement them, we can add the +// 'legalization' list here. + default: +// Do nothing so we can go to the 'unimplemented' diagnostic instead. +return true; + } + llvm_unreachable("Invalid clause kind"); +} + +/// Destruct and deallocate any clauses that aren't going to be used because +/// they don't have a Construct to attach to. +void DestroyUnusedClauses(ASTContext &Ctx, alexey-bataev wrote: Why do you need to delete unused clauses? Maybe just keep them unused and just ignore? https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -82,22 +119,22 @@ bool SemaOpenACC::ActOnStartStmtDirective(OpenACCDirectiveKind K, return diagnoseConstructAppertainment(*this, K, StartLoc, /*IsStmt=*/true); } -StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K, - SourceLocation StartLoc, - SourceLocation EndLoc, - StmtResult AssocStmt) { +StmtResult SemaOpenACC::ActOnEndStmtDirective( +OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation EndLoc, +MutableArrayRef Clauses, StmtResult AssocStmt) { alexey-bataev wrote: ```suggestion ArrayRef Clauses, StmtResult AssocStmt) { ``` https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -4003,20 +4003,11 @@ class TreeTransform { return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type); } - StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K, -SourceLocation BeginLoc, -SourceLocation EndLoc, -StmtResult StrBlock) { -getSema().OpenACC().ActOnConstruct(K, BeginLoc); - -// TODO OpenACC: Include clauses. -if (getSema().OpenACC().ActOnStartStmtDirective(K, BeginLoc)) - return StmtError(); - -StrBlock = getSema().OpenACC().ActOnAssociatedStmt(K, StrBlock); - + StmtResult RebuildOpenACCComputeConstruct( + OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation EndLoc, + MutableArrayRef Clauses, StmtResult StrBlock) { alexey-bataev wrote: ```suggestion ArrayRef Clauses, StmtResult StrBlock) { ``` https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -11077,16 +11077,65 @@ OMPClause *TreeTransform::TransformOMPXBareClause(OMPXBareClause *C) { //===--===// // OpenACC transformation //===--===// +template +OpenACCClause *TreeTransform::TransformOpenACCClause( +ArrayRef ExistingClauses, +OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) { + + SemaOpenACC::OpenACCParsedClause ParsedClause( + DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc()); + ParsedClause.setEndLoc(OldClause->getEndLoc()); + + if (const auto *WithParms = dyn_cast(OldClause)) +ParsedClause.setLParenLoc(WithParms->getLParenLoc()); + + switch (OldClause->getClauseKind()) { +// TODO OpenACC: Transform individual clauses, and set their info in +// ParsedClause. + default: +assert(false && "Unhandled OpenACC clause in TreeTransform"); +return nullptr; + } + + return getSema().OpenACC().ActOnClause(ExistingClauses, ParsedClause); +} + +template +llvm::SmallVector +TreeTransform::TransformOpenACCClauseList( +OpenACCDirectiveKind DirKind, ArrayRef OldClauses) { alexey-bataev wrote: Do you have the test for this? https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -11077,16 +11077,65 @@ OMPClause *TreeTransform::TransformOMPXBareClause(OMPXBareClause *C) { //===--===// // OpenACC transformation //===--===// +template +OpenACCClause *TreeTransform::TransformOpenACCClause( +ArrayRef ExistingClauses, +OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) { + + SemaOpenACC::OpenACCParsedClause ParsedClause( + DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc()); + ParsedClause.setEndLoc(OldClause->getEndLoc()); + + if (const auto *WithParms = dyn_cast(OldClause)) +ParsedClause.setLParenLoc(WithParms->getLParenLoc()); + + switch (OldClause->getClauseKind()) { +// TODO OpenACC: Transform individual clauses, and set their info in +// ParsedClause. + default: +assert(false && "Unhandled OpenACC clause in TreeTransform"); +return nullptr; + } + + return getSema().OpenACC().ActOnClause(ExistingClauses, ParsedClause); +} + +template +llvm::SmallVector +TreeTransform::TransformOpenACCClauseList( +OpenACCDirectiveKind DirKind, ArrayRef OldClauses) { erichkeane wrote: In this patch, no. The next patch (that actually adds a clause) does, but I wanted to split the patch up to make it easier for you to review. This one is already unfortunately large, despite it effectively being 'NFC'. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -82,22 +119,22 @@ bool SemaOpenACC::ActOnStartStmtDirective(OpenACCDirectiveKind K, return diagnoseConstructAppertainment(*this, K, StartLoc, /*IsStmt=*/true); } -StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K, - SourceLocation StartLoc, - SourceLocation EndLoc, - StmtResult AssocStmt) { +StmtResult SemaOpenACC::ActOnEndStmtDirective( +OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation EndLoc, +MutableArrayRef Clauses, StmtResult AssocStmt) { erichkeane wrote: The result of these changes is that the 'DestroyUnusedClauses' can no longer set the values to `nullptr`, and also 'deleting' stuff that were passed by an ArrayRef. This is actually ALSO causing me to think we should be passing this as an llvm::SmallVector (and moving it into here!) to make it clear that this function is stealing the 'ownership' of these things. WDYT? https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -37,6 +37,32 @@ bool diagnoseConstructAppertainment(SemaOpenACC &S, OpenACCDirectiveKind K, } return false; } + +bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind, +OpenACCClauseKind ClauseKind) { + switch (ClauseKind) { +// FIXME: For each clause as we implement them, we can add the +// 'legalization' list here. + default: +// Do nothing so we can go to the 'unimplemented' diagnostic instead. +return true; + } + llvm_unreachable("Invalid clause kind"); +} + +/// Destruct and deallocate any clauses that aren't going to be used because +/// they don't have a Construct to attach to. +void DestroyUnusedClauses(ASTContext &Ctx, erichkeane wrote: It just seemed like a bad idea to 'leak' clauses that aren't added to the AST. Depending on how many 'bad' constructs there end up being, this could presumably be an unfortunate amount of memory. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/erichkeane updated https://github.com/llvm/llvm-project/pull/87821 >From ca5f957bb002d79997e630cdf1aaad5703ea2ba4 Mon Sep 17 00:00:00 2001 From: erichkeane Date: Fri, 5 Apr 2024 10:53:47 -0700 Subject: [PATCH 1/3] [OpenACC] Implement Sema work for OpenACC Clauses Now that we have AST nodes for OpenACC Clauses, this patch adds their creation to Sema and makes the Parser call all the required functions. This also redoes TreeTransform to work with the clauses/make sure they are transformed. Much of this is NFC, since there is no clause we can test this behavior with. However, there IS one noticable change; we are now no longer diagnosing that a clause is 'not implemented' unless it there was no errors parsing its parameters. This is because it cleans up how we create and diagnose clauses. --- .../clang/Basic/DiagnosticSemaKinds.td| 2 + clang/include/clang/Parse/Parser.h| 34 +- clang/include/clang/Sema/SemaOpenACC.h| 39 +- clang/lib/Parse/ParseOpenACC.cpp | 142 +++-- clang/lib/Sema/SemaOpenACC.cpp| 69 ++- clang/lib/Sema/TreeTransform.h| 79 ++- clang/test/ParserOpenACC/parse-clauses.c | 573 +++--- clang/test/ParserOpenACC/parse-clauses.cpp| 9 +- clang/test/ParserOpenACC/parse-wait-clause.c | 102 ++-- 9 files changed, 540 insertions(+), 509 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index df57f5e6ce11ba..238931770da3a2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12252,6 +12252,8 @@ def warn_acc_clause_unimplemented def err_acc_construct_appertainment : Error<"OpenACC construct '%0' cannot be used here; it can only " "be used in a statement context">; +def err_acc_clause_appertainment +: Error<"OpenACC '%1' clause not valid on '%0' directive">; def err_acc_branch_in_out_compute_construct : Error<"invalid %select{branch|return|throw}0 %select{out of|into}1 " "OpenACC Compute Construct">; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 580bf2a5d79df5..8bc929b1dfe4bb 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -41,6 +41,7 @@ namespace clang { class InMessageExpressionRAIIObject; class PoisonSEHIdentifiersRAIIObject; class OMPClause; + class OpenACCClause; class ObjCTypeParamList; struct OMPTraitProperty; struct OMPTraitSelector; @@ -3594,11 +3595,26 @@ class Parser : public CodeCompletionHandler { OpenACCDirectiveKind DirKind; SourceLocation StartLoc; SourceLocation EndLoc; -// TODO OpenACC: Add Clause list here once we have a type for that. +SmallVector Clauses; // 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. }; + /// Represents the 'error' state of parsing an OpenACC Clause, and stores + /// whether we can continue parsing, or should give up on the directive. + enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 }; + + /// A type to represent the state of parsing an OpenACC Clause. Situations + /// that result in an OpenACCClause pointer are a success and can continue + /// parsing, however some other situations can also continue. + /// FIXME: This is better represented as a std::expected when we get C++23. + using OpenACCClauseParseResult = + llvm::PointerIntPair; + + OpenACCClauseParseResult OpenACCCanContinue(); + OpenACCClauseParseResult OpenACCCannotContinue(); + OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause); + /// Parses the OpenACC directive (the entire pragma) including the clause /// list, but does not produce the main AST node. OpenACCDirectiveParseInfo ParseOpenACCDirective(); @@ -3613,12 +3629,18 @@ class Parser : public CodeCompletionHandler { bool ParseOpenACCClauseVarList(OpenACCClauseKind Kind); /// Parses any parameters for an OpenACC Clause, including required/optional /// parens. - bool ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind, -OpenACCClauseKind Kind); - /// Parses a single clause in a clause-list for OpenACC. - bool ParseOpenACCClause(OpenACCDirectiveKind DirKind); + OpenACCClauseParseResult + ParseOpenACCClauseParams(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind, OpenACCClauseKind Kind, + SourceLocation ClauseLoc); + /// Parses a single clause in a clause-list for OpenACC. Returns nullptr on + /// error. + OpenACCClauseParseResult + ParseOpenACCClause(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind); /// Parses the clause-list for an OpenACC directive. - void ParseOpenACCClauseList(OpenACCDirectiveKind
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -37,6 +37,32 @@ bool diagnoseConstructAppertainment(SemaOpenACC &S, OpenACCDirectiveKind K, } return false; } + +bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind, +OpenACCClauseKind ClauseKind) { + switch (ClauseKind) { +// FIXME: For each clause as we implement them, we can add the +// 'legalization' list here. + default: +// Do nothing so we can go to the 'unimplemented' diagnostic instead. +return true; + } + llvm_unreachable("Invalid clause kind"); +} + +/// Destruct and deallocate any clauses that aren't going to be used because +/// they don't have a Construct to attach to. +void DestroyUnusedClauses(ASTContext &Ctx, alexey-bataev wrote: Not sure this is a real issue. I think it is enough just to report the error (or warning) and just ignore the clauses in the codegen. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -11077,16 +11077,65 @@ OMPClause *TreeTransform::TransformOMPXBareClause(OMPXBareClause *C) { //===--===// // OpenACC transformation //===--===// +template +OpenACCClause *TreeTransform::TransformOpenACCClause( +ArrayRef ExistingClauses, +OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) { + + SemaOpenACC::OpenACCParsedClause ParsedClause( + DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc()); + ParsedClause.setEndLoc(OldClause->getEndLoc()); + + if (const auto *WithParms = dyn_cast(OldClause)) +ParsedClause.setLParenLoc(WithParms->getLParenLoc()); + + switch (OldClause->getClauseKind()) { +// TODO OpenACC: Transform individual clauses, and set their info in +// ParsedClause. + default: +assert(false && "Unhandled OpenACC clause in TreeTransform"); +return nullptr; + } + + return getSema().OpenACC().ActOnClause(ExistingClauses, ParsedClause); +} + +template +llvm::SmallVector +TreeTransform::TransformOpenACCClauseList( +OpenACCDirectiveKind DirKind, ArrayRef OldClauses) { alexey-bataev wrote: Better to move it to another patch, I think https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -37,6 +37,32 @@ bool diagnoseConstructAppertainment(SemaOpenACC &S, OpenACCDirectiveKind K, } return false; } + +bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind, +OpenACCClauseKind ClauseKind) { + switch (ClauseKind) { +// FIXME: For each clause as we implement them, we can add the +// 'legalization' list here. + default: +// Do nothing so we can go to the 'unimplemented' diagnostic instead. +return true; + } + llvm_unreachable("Invalid clause kind"); +} + +/// Destruct and deallocate any clauses that aren't going to be used because +/// they don't have a Construct to attach to. +void DestroyUnusedClauses(ASTContext &Ctx, erichkeane wrote: Well, there WOULD be no 'ignoring' in codegen, as these clauses won't be added to the AST at all. They'd be created, then just 'forgotten' if we don't add them to a construct. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -11077,16 +11077,65 @@ OMPClause *TreeTransform::TransformOMPXBareClause(OMPXBareClause *C) { //===--===// // OpenACC transformation //===--===// +template +OpenACCClause *TreeTransform::TransformOpenACCClause( +ArrayRef ExistingClauses, +OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) { + + SemaOpenACC::OpenACCParsedClause ParsedClause( + DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc()); + ParsedClause.setEndLoc(OldClause->getEndLoc()); + + if (const auto *WithParms = dyn_cast(OldClause)) +ParsedClause.setLParenLoc(WithParms->getLParenLoc()); + + switch (OldClause->getClauseKind()) { +// TODO OpenACC: Transform individual clauses, and set their info in +// ParsedClause. + default: +assert(false && "Unhandled OpenACC clause in TreeTransform"); +return nullptr; + } + + return getSema().OpenACC().ActOnClause(ExistingClauses, ParsedClause); +} + +template +llvm::SmallVector +TreeTransform::TransformOpenACCClauseList( +OpenACCDirectiveKind DirKind, ArrayRef OldClauses) { erichkeane wrote: The transforming of clauses? I can, it just makes the next patch 'larger'. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -82,22 +119,22 @@ bool SemaOpenACC::ActOnStartStmtDirective(OpenACCDirectiveKind K, return diagnoseConstructAppertainment(*this, K, StartLoc, /*IsStmt=*/true); } -StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K, - SourceLocation StartLoc, - SourceLocation EndLoc, - StmtResult AssocStmt) { +StmtResult SemaOpenACC::ActOnEndStmtDirective( +OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation EndLoc, +MutableArrayRef Clauses, StmtResult AssocStmt) { alexey-bataev wrote: Better to use OwningArrayRef, if changes do not require resizing, I assume https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -82,22 +119,22 @@ bool SemaOpenACC::ActOnStartStmtDirective(OpenACCDirectiveKind K, return diagnoseConstructAppertainment(*this, K, StartLoc, /*IsStmt=*/true); } -StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K, - SourceLocation StartLoc, - SourceLocation EndLoc, - StmtResult AssocStmt) { +StmtResult SemaOpenACC::ActOnEndStmtDirective( +OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation EndLoc, +MutableArrayRef Clauses, StmtResult AssocStmt) { erichkeane wrote: It doesn't seem that `OwningArrayRef` is what I want, is it? That is an array-ref that copies the elements into a newly allocated 'thing'. My thought is that we want the call to `ActOnEndStmtDirective` to 'take' ownership of an existing allocation. A part of me thinks I should perhaps be storing these as a `SmallVector>` instead, then taking that by value here, so it is clear that it 'owns' it. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -37,6 +37,32 @@ bool diagnoseConstructAppertainment(SemaOpenACC &S, OpenACCDirectiveKind K, } return false; } + +bool doesClauseApplyToDirective(OpenACCDirectiveKind DirectiveKind, +OpenACCClauseKind ClauseKind) { + switch (ClauseKind) { +// FIXME: For each clause as we implement them, we can add the +// 'legalization' list here. + default: +// Do nothing so we can go to the 'unimplemented' diagnostic instead. +return true; + } + llvm_unreachable("Invalid clause kind"); +} + +/// Destruct and deallocate any clauses that aren't going to be used because +/// they don't have a Construct to attach to. +void DestroyUnusedClauses(ASTContext &Ctx, erichkeane wrote: I discussed this with Aaron who confirmed that because we're allocating in the ASTContext::Allocate pool that we're fine to skip destruction, so I'm just going to do that. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -11077,16 +11077,65 @@ OMPClause *TreeTransform::TransformOMPXBareClause(OMPXBareClause *C) { //===--===// // OpenACC transformation //===--===// +template +OpenACCClause *TreeTransform::TransformOpenACCClause( +ArrayRef ExistingClauses, +OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) { + + SemaOpenACC::OpenACCParsedClause ParsedClause( + DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc()); + ParsedClause.setEndLoc(OldClause->getEndLoc()); + + if (const auto *WithParms = dyn_cast(OldClause)) +ParsedClause.setLParenLoc(WithParms->getLParenLoc()); + + switch (OldClause->getClauseKind()) { +// TODO OpenACC: Transform individual clauses, and set their info in +// ParsedClause. + default: +assert(false && "Unhandled OpenACC clause in TreeTransform"); +return nullptr; + } + + return getSema().OpenACC().ActOnClause(ExistingClauses, ParsedClause); +} + +template +llvm::SmallVector +TreeTransform::TransformOpenACCClauseList( +OpenACCDirectiveKind DirKind, ArrayRef OldClauses) { erichkeane wrote: I'll remove the body of this from the next revision of this, just validating now. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -82,22 +119,22 @@ bool SemaOpenACC::ActOnStartStmtDirective(OpenACCDirectiveKind K, return diagnoseConstructAppertainment(*this, K, StartLoc, /*IsStmt=*/true); } -StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K, - SourceLocation StartLoc, - SourceLocation EndLoc, - StmtResult AssocStmt) { +StmtResult SemaOpenACC::ActOnEndStmtDirective( +OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation EndLoc, +MutableArrayRef Clauses, StmtResult AssocStmt) { erichkeane wrote: I think I'm trying too much to gild a lily here, I think your suggestion of removing the 'destroy' function + just being ArrayRef is acceptable, so the next patch will do that. https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/erichkeane updated https://github.com/llvm/llvm-project/pull/87821 >From ca5f957bb002d79997e630cdf1aaad5703ea2ba4 Mon Sep 17 00:00:00 2001 From: erichkeane Date: Fri, 5 Apr 2024 10:53:47 -0700 Subject: [PATCH 1/5] [OpenACC] Implement Sema work for OpenACC Clauses Now that we have AST nodes for OpenACC Clauses, this patch adds their creation to Sema and makes the Parser call all the required functions. This also redoes TreeTransform to work with the clauses/make sure they are transformed. Much of this is NFC, since there is no clause we can test this behavior with. However, there IS one noticable change; we are now no longer diagnosing that a clause is 'not implemented' unless it there was no errors parsing its parameters. This is because it cleans up how we create and diagnose clauses. --- .../clang/Basic/DiagnosticSemaKinds.td| 2 + clang/include/clang/Parse/Parser.h| 34 +- clang/include/clang/Sema/SemaOpenACC.h| 39 +- clang/lib/Parse/ParseOpenACC.cpp | 142 +++-- clang/lib/Sema/SemaOpenACC.cpp| 69 ++- clang/lib/Sema/TreeTransform.h| 79 ++- clang/test/ParserOpenACC/parse-clauses.c | 573 +++--- clang/test/ParserOpenACC/parse-clauses.cpp| 9 +- clang/test/ParserOpenACC/parse-wait-clause.c | 102 ++-- 9 files changed, 540 insertions(+), 509 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index df57f5e6ce11ba..238931770da3a2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12252,6 +12252,8 @@ def warn_acc_clause_unimplemented def err_acc_construct_appertainment : Error<"OpenACC construct '%0' cannot be used here; it can only " "be used in a statement context">; +def err_acc_clause_appertainment +: Error<"OpenACC '%1' clause not valid on '%0' directive">; def err_acc_branch_in_out_compute_construct : Error<"invalid %select{branch|return|throw}0 %select{out of|into}1 " "OpenACC Compute Construct">; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 580bf2a5d79df5..8bc929b1dfe4bb 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -41,6 +41,7 @@ namespace clang { class InMessageExpressionRAIIObject; class PoisonSEHIdentifiersRAIIObject; class OMPClause; + class OpenACCClause; class ObjCTypeParamList; struct OMPTraitProperty; struct OMPTraitSelector; @@ -3594,11 +3595,26 @@ class Parser : public CodeCompletionHandler { OpenACCDirectiveKind DirKind; SourceLocation StartLoc; SourceLocation EndLoc; -// TODO OpenACC: Add Clause list here once we have a type for that. +SmallVector Clauses; // 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. }; + /// Represents the 'error' state of parsing an OpenACC Clause, and stores + /// whether we can continue parsing, or should give up on the directive. + enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 }; + + /// A type to represent the state of parsing an OpenACC Clause. Situations + /// that result in an OpenACCClause pointer are a success and can continue + /// parsing, however some other situations can also continue. + /// FIXME: This is better represented as a std::expected when we get C++23. + using OpenACCClauseParseResult = + llvm::PointerIntPair; + + OpenACCClauseParseResult OpenACCCanContinue(); + OpenACCClauseParseResult OpenACCCannotContinue(); + OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause); + /// Parses the OpenACC directive (the entire pragma) including the clause /// list, but does not produce the main AST node. OpenACCDirectiveParseInfo ParseOpenACCDirective(); @@ -3613,12 +3629,18 @@ class Parser : public CodeCompletionHandler { bool ParseOpenACCClauseVarList(OpenACCClauseKind Kind); /// Parses any parameters for an OpenACC Clause, including required/optional /// parens. - bool ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind, -OpenACCClauseKind Kind); - /// Parses a single clause in a clause-list for OpenACC. - bool ParseOpenACCClause(OpenACCDirectiveKind DirKind); + OpenACCClauseParseResult + ParseOpenACCClauseParams(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind, OpenACCClauseKind Kind, + SourceLocation ClauseLoc); + /// Parses a single clause in a clause-list for OpenACC. Returns nullptr on + /// error. + OpenACCClauseParseResult + ParseOpenACCClause(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind); /// Parses the clause-list for an OpenACC directive. - void ParseOpenACCClauseList(OpenACCDirectiveKind
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
erichkeane wrote: Build failure is completely unrelated, but I think this does everything you've asked for @alexey-bataev . Let me know what you think! https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/alexey-bataev edited https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/alexey-bataev approved this pull request. LG with a nit https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
@@ -1204,15 +1238,16 @@ Parser::OpenACCDirectiveParseInfo Parser::ParseOpenACCDirective() { Diag(Tok, diag::err_expected) << tok::l_paren; } - // Parses the list of clauses, if present. - ParseOpenACCClauseList(DirKind); + // Parses the list of clauses, if present, plus set up return value. + OpenACCDirectiveParseInfo ParseInfo{DirKind, StartLoc, SourceLocation{}, + ParseOpenACCClauseList(DirKind)}; assert(Tok.is(tok::annot_pragma_openacc_end) && "Didn't parse all OpenACC Clauses"); - SourceLocation EndLoc = ConsumeAnnotationToken(); - assert(EndLoc.isValid()); + ParseInfo.EndLoc = ConsumeAnnotationToken(); + assert(ParseInfo.EndLoc.isValid()); alexey-bataev wrote: Add assertion message https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/erichkeane updated https://github.com/llvm/llvm-project/pull/87821 >From ca5f957bb002d79997e630cdf1aaad5703ea2ba4 Mon Sep 17 00:00:00 2001 From: erichkeane Date: Fri, 5 Apr 2024 10:53:47 -0700 Subject: [PATCH 1/6] [OpenACC] Implement Sema work for OpenACC Clauses Now that we have AST nodes for OpenACC Clauses, this patch adds their creation to Sema and makes the Parser call all the required functions. This also redoes TreeTransform to work with the clauses/make sure they are transformed. Much of this is NFC, since there is no clause we can test this behavior with. However, there IS one noticable change; we are now no longer diagnosing that a clause is 'not implemented' unless it there was no errors parsing its parameters. This is because it cleans up how we create and diagnose clauses. --- .../clang/Basic/DiagnosticSemaKinds.td| 2 + clang/include/clang/Parse/Parser.h| 34 +- clang/include/clang/Sema/SemaOpenACC.h| 39 +- clang/lib/Parse/ParseOpenACC.cpp | 142 +++-- clang/lib/Sema/SemaOpenACC.cpp| 69 ++- clang/lib/Sema/TreeTransform.h| 79 ++- clang/test/ParserOpenACC/parse-clauses.c | 573 +++--- clang/test/ParserOpenACC/parse-clauses.cpp| 9 +- clang/test/ParserOpenACC/parse-wait-clause.c | 102 ++-- 9 files changed, 540 insertions(+), 509 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index df57f5e6ce11ba..238931770da3a2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12252,6 +12252,8 @@ def warn_acc_clause_unimplemented def err_acc_construct_appertainment : Error<"OpenACC construct '%0' cannot be used here; it can only " "be used in a statement context">; +def err_acc_clause_appertainment +: Error<"OpenACC '%1' clause not valid on '%0' directive">; def err_acc_branch_in_out_compute_construct : Error<"invalid %select{branch|return|throw}0 %select{out of|into}1 " "OpenACC Compute Construct">; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 580bf2a5d79df5..8bc929b1dfe4bb 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -41,6 +41,7 @@ namespace clang { class InMessageExpressionRAIIObject; class PoisonSEHIdentifiersRAIIObject; class OMPClause; + class OpenACCClause; class ObjCTypeParamList; struct OMPTraitProperty; struct OMPTraitSelector; @@ -3594,11 +3595,26 @@ class Parser : public CodeCompletionHandler { OpenACCDirectiveKind DirKind; SourceLocation StartLoc; SourceLocation EndLoc; -// TODO OpenACC: Add Clause list here once we have a type for that. +SmallVector Clauses; // 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. }; + /// Represents the 'error' state of parsing an OpenACC Clause, and stores + /// whether we can continue parsing, or should give up on the directive. + enum class OpenACCParseCanContinue { Cannot = 0, Can = 1 }; + + /// A type to represent the state of parsing an OpenACC Clause. Situations + /// that result in an OpenACCClause pointer are a success and can continue + /// parsing, however some other situations can also continue. + /// FIXME: This is better represented as a std::expected when we get C++23. + using OpenACCClauseParseResult = + llvm::PointerIntPair; + + OpenACCClauseParseResult OpenACCCanContinue(); + OpenACCClauseParseResult OpenACCCannotContinue(); + OpenACCClauseParseResult OpenACCSuccess(OpenACCClause *Clause); + /// Parses the OpenACC directive (the entire pragma) including the clause /// list, but does not produce the main AST node. OpenACCDirectiveParseInfo ParseOpenACCDirective(); @@ -3613,12 +3629,18 @@ class Parser : public CodeCompletionHandler { bool ParseOpenACCClauseVarList(OpenACCClauseKind Kind); /// Parses any parameters for an OpenACC Clause, including required/optional /// parens. - bool ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind, -OpenACCClauseKind Kind); - /// Parses a single clause in a clause-list for OpenACC. - bool ParseOpenACCClause(OpenACCDirectiveKind DirKind); + OpenACCClauseParseResult + ParseOpenACCClauseParams(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind, OpenACCClauseKind Kind, + SourceLocation ClauseLoc); + /// Parses a single clause in a clause-list for OpenACC. Returns nullptr on + /// error. + OpenACCClauseParseResult + ParseOpenACCClause(ArrayRef ExistingClauses, + OpenACCDirectiveKind DirKind); /// Parses the clause-list for an OpenACC directive. - void ParseOpenACCClauseList(OpenACCDirectiveKind
[clang] [OpenACC] Implement Sema work for OpenACC Clauses (PR #87821)
https://github.com/erichkeane closed https://github.com/llvm/llvm-project/pull/87821 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits