Author: erichkeane Date: 2024-01-17T06:46:58-08:00 New Revision: 3a82a1c3f6bdc9259cc4641f66fc76d1e171e382
URL: https://github.com/llvm/llvm-project/commit/3a82a1c3f6bdc9259cc4641f66fc76d1e171e382 DIFF: https://github.com/llvm/llvm-project/commit/3a82a1c3f6bdc9259cc4641f66fc76d1e171e382.diff LOG: [OpenACC] Implement 'collapse' clause parsing. The 'collapse' clause takes an optional 'force:' followed by an integer constant expression. For now, parse this as an assignment expression, and we'll check it for value/ICE later. Added: clang/test/ParserOpenACC/parse-clauses.cpp Modified: clang/include/clang/Basic/OpenACCKinds.h clang/lib/Parse/ParseOpenACC.cpp clang/test/ParserOpenACC/parse-clauses.c Removed: ################################################################################ diff --git a/clang/include/clang/Basic/OpenACCKinds.h b/clang/include/clang/Basic/OpenACCKinds.h index 23d41c41b9a634..16cee08e4d8fce 100644 --- a/clang/include/clang/Basic/OpenACCKinds.h +++ b/clang/include/clang/Basic/OpenACCKinds.h @@ -217,6 +217,8 @@ enum class OpenACCClauseKind { /// 'reduction' clause, allowed on Parallel, Serial, Loop, and the combined /// constructs. Reduction, + /// 'collapse' clause, allowed on 'loop' and Combined constructs. + Collapse, /// Represents an invalid clause, for the purposes of parsing. Invalid, @@ -312,6 +314,9 @@ inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out, case OpenACCClauseKind::Reduction: return Out << "reduction"; + case OpenACCClauseKind::Collapse: + return Out << "collapse"; + case OpenACCClauseKind::Invalid: return Out << "<invalid>"; } diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp index b397553de01a08..7ff52f040330d3 100644 --- a/clang/lib/Parse/ParseOpenACC.cpp +++ b/clang/lib/Parse/ParseOpenACC.cpp @@ -92,6 +92,7 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) { .Case("attach", OpenACCClauseKind::Attach) .Case("auto", OpenACCClauseKind::Auto) .Case("create", OpenACCClauseKind::Create) + .Case("collapse", OpenACCClauseKind::Collapse) .Case("copy", OpenACCClauseKind::Copy) .Case("copyin", OpenACCClauseKind::CopyIn) .Case("copyout", OpenACCClauseKind::CopyOut) @@ -151,6 +152,7 @@ enum class OpenACCSpecialTokenKind { DevNum, Queues, Zero, + Force, }; bool isOpenACCSpecialToken(OpenACCSpecialTokenKind Kind, Token Tok) { @@ -166,6 +168,8 @@ bool isOpenACCSpecialToken(OpenACCSpecialTokenKind Kind, Token Tok) { return Tok.getIdentifierInfo()->isStr("queues"); case OpenACCSpecialTokenKind::Zero: return Tok.getIdentifierInfo()->isStr("zero"); + case OpenACCSpecialTokenKind::Force: + return Tok.getIdentifierInfo()->isStr("force"); } llvm_unreachable("Unknown 'Kind' Passed"); } @@ -462,6 +466,7 @@ ClauseParensKind getClauseParensKind(OpenACCDirectiveKind DirKind, case OpenACCClauseKind::Link: case OpenACCClauseKind::Host: case OpenACCClauseKind::Reduction: + case OpenACCClauseKind::Collapse: return ClauseParensKind::Required; case OpenACCClauseKind::Auto: @@ -654,6 +659,15 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind, if (ParseOpenACCClauseVarList(Kind)) return true; break; + case OpenACCClauseKind::Collapse: { + tryParseAndConsumeSpecialTokenKind(*this, OpenACCSpecialTokenKind::Force, + Kind); + ExprResult NumLoops = + getActions().CorrectDelayedTyposInExpr(ParseAssignmentExpression()); + if (NumLoops.isInvalid()) + return true; + break; + } default: llvm_unreachable("Not a required parens type?"); } diff --git a/clang/test/ParserOpenACC/parse-clauses.c b/clang/test/ParserOpenACC/parse-clauses.c index 6d548210e816ca..336343ecff28f8 100644 --- a/clang/test/ParserOpenACC/parse-clauses.c +++ b/clang/test/ParserOpenACC/parse-clauses.c @@ -54,6 +54,45 @@ void func() { // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} #pragma acc loop seq, + // expected-error@+2{{expected '('}} + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse + for(;;){} + + // expected-error@+2{{expected expression}} + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse() + for(;;){} + + // expected-error@+3{{invalid tag 'unknown' on 'collapse' clause}} + // expected-error@+2{{expected expression}} + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse(unknown:) + for(;;){} + + // expected-error@+2{{expected expression}} + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse(force:) + for(;;){} + + // expected-error@+2{{invalid tag 'unknown' on 'collapse' clause}} + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse(unknown:5) + for(;;){} + + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse(force:5) + for(;;){} + + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse(5) + for(;;){} + + // expected-error@+3{{expected ')'}} + // expected-note@+2{{to match this '('}} + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse(5, 6) + for(;;){} } void DefaultClause() { diff --git a/clang/test/ParserOpenACC/parse-clauses.cpp b/clang/test/ParserOpenACC/parse-clauses.cpp new file mode 100644 index 00000000000000..8771acc6b8eeb7 --- /dev/null +++ b/clang/test/ParserOpenACC/parse-clauses.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 %s -verify -fopenacc + +template<unsigned I, typename T> +void templ() { + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse(I) + for(;;){} + + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc loop collapse(T::value) + for(;;){} +} + +struct S { + static constexpr unsigned value = 5; +}; + +void use() { + templ<7, S>(); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits