[OpenACC] Implement Sema work for OpenACC Clauses (#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.
This commit is contained in:
@@ -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 is 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">;
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace clang {
|
||||
class InMessageExpressionRAIIObject;
|
||||
class PoisonSEHIdentifiersRAIIObject;
|
||||
class OMPClause;
|
||||
class OpenACCClause;
|
||||
class ObjCTypeParamList;
|
||||
struct OMPTraitProperty;
|
||||
struct OMPTraitSelector;
|
||||
@@ -3594,11 +3595,26 @@ private:
|
||||
OpenACCDirectiveKind DirKind;
|
||||
SourceLocation StartLoc;
|
||||
SourceLocation EndLoc;
|
||||
// TODO OpenACC: Add Clause list here once we have a type for that.
|
||||
SmallVector<OpenACCClause *> 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<OpenACCClause *, 1, OpenACCParseCanContinue>;
|
||||
|
||||
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 @@ private:
|
||||
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<const OpenACCClause *> ExistingClauses,
|
||||
OpenACCDirectiveKind DirKind, OpenACCClauseKind Kind,
|
||||
SourceLocation ClauseLoc);
|
||||
/// Parses a single clause in a clause-list for OpenACC. Returns nullptr on
|
||||
/// error.
|
||||
OpenACCClauseParseResult
|
||||
ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
|
||||
OpenACCDirectiveKind DirKind);
|
||||
/// Parses the clause-list for an OpenACC directive.
|
||||
void ParseOpenACCClauseList(OpenACCDirectiveKind DirKind);
|
||||
SmallVector<OpenACCClause *>
|
||||
ParseOpenACCClauseList(OpenACCDirectiveKind DirKind);
|
||||
bool ParseOpenACCWaitArgument();
|
||||
/// Parses the clause of the 'bind' argument, which can be a string literal or
|
||||
/// an ID expression.
|
||||
|
||||
@@ -21,13 +21,46 @@
|
||||
#include "clang/Sema/SemaBase.h"
|
||||
|
||||
namespace clang {
|
||||
class OpenACCClause;
|
||||
|
||||
class SemaOpenACC : public SemaBase {
|
||||
public:
|
||||
/// A type to represent all the data for an OpenACC Clause that has been
|
||||
/// parsed, but not yet created/semantically analyzed. This is effectively a
|
||||
/// discriminated union on the 'Clause Kind', with all of the individual
|
||||
/// clause details stored in a std::variant.
|
||||
class OpenACCParsedClause {
|
||||
OpenACCDirectiveKind DirKind;
|
||||
OpenACCClauseKind ClauseKind;
|
||||
SourceRange ClauseRange;
|
||||
SourceLocation LParenLoc;
|
||||
|
||||
// TODO OpenACC: Add variant here to store details of individual clauses.
|
||||
|
||||
public:
|
||||
OpenACCParsedClause(OpenACCDirectiveKind DirKind,
|
||||
OpenACCClauseKind ClauseKind, SourceLocation BeginLoc)
|
||||
: DirKind(DirKind), ClauseKind(ClauseKind), ClauseRange(BeginLoc, {}) {}
|
||||
|
||||
OpenACCDirectiveKind getDirectiveKind() const { return DirKind; }
|
||||
|
||||
OpenACCClauseKind getClauseKind() const { return ClauseKind; }
|
||||
|
||||
SourceLocation getBeginLoc() const { return ClauseRange.getBegin(); }
|
||||
|
||||
SourceLocation getLParenLoc() const { return LParenLoc; }
|
||||
|
||||
SourceLocation getEndLoc() const { return ClauseRange.getEnd(); }
|
||||
|
||||
void setLParenLoc(SourceLocation EndLoc) { LParenLoc = EndLoc; }
|
||||
void setEndLoc(SourceLocation EndLoc) { ClauseRange.setEnd(EndLoc); }
|
||||
};
|
||||
|
||||
SemaOpenACC(Sema &S);
|
||||
|
||||
/// Called after parsing an OpenACC Clause so that it can be checked.
|
||||
bool ActOnClause(OpenACCClauseKind ClauseKind, SourceLocation StartLoc);
|
||||
OpenACCClause *ActOnClause(ArrayRef<const OpenACCClause *> ExistingClauses,
|
||||
OpenACCParsedClause &Clause);
|
||||
|
||||
/// 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
|
||||
@@ -53,7 +86,10 @@ public:
|
||||
/// declaration group or associated statement.
|
||||
StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K,
|
||||
SourceLocation StartLoc,
|
||||
SourceLocation EndLoc, StmtResult AssocStmt);
|
||||
SourceLocation EndLoc,
|
||||
ArrayRef<OpenACCClause *> Clauses,
|
||||
StmtResult AssocStmt);
|
||||
|
||||
/// Called after the directive has been completely parsed, including the
|
||||
/// declaration group or associated statement.
|
||||
DeclGroupRef ActOnEndDeclDirective();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "clang/AST/OpenACCClause.h"
|
||||
#include "clang/Basic/OpenACCKinds.h"
|
||||
#include "clang/Parse/ParseDiagnostic.h"
|
||||
#include "clang/Parse/Parser.h"
|
||||
@@ -582,12 +583,26 @@ unsigned getOpenACCScopeFlags(OpenACCDirectiveKind DirKind) {
|
||||
|
||||
} // namespace
|
||||
|
||||
Parser::OpenACCClauseParseResult Parser::OpenACCCanContinue() {
|
||||
return {nullptr, OpenACCParseCanContinue::Can};
|
||||
}
|
||||
|
||||
Parser::OpenACCClauseParseResult Parser::OpenACCCannotContinue() {
|
||||
return {nullptr, OpenACCParseCanContinue::Cannot};
|
||||
}
|
||||
|
||||
Parser::OpenACCClauseParseResult Parser::OpenACCSuccess(OpenACCClause *Clause) {
|
||||
return {Clause, OpenACCParseCanContinue::Can};
|
||||
}
|
||||
|
||||
// OpenACC 3.3, section 1.7:
|
||||
// To simplify the specification and convey appropriate constraint information,
|
||||
// a pqr-list is a comma-separated list of pdr items. The one exception is a
|
||||
// clause-list, which is a list of one or more clauses optionally separated by
|
||||
// commas.
|
||||
void Parser::ParseOpenACCClauseList(OpenACCDirectiveKind DirKind) {
|
||||
SmallVector<OpenACCClause *>
|
||||
Parser::ParseOpenACCClauseList(OpenACCDirectiveKind DirKind) {
|
||||
SmallVector<OpenACCClause *> Clauses;
|
||||
bool FirstClause = true;
|
||||
while (getCurToken().isNot(tok::annot_pragma_openacc_end)) {
|
||||
// Comma is optional in a clause-list.
|
||||
@@ -595,13 +610,17 @@ void Parser::ParseOpenACCClauseList(OpenACCDirectiveKind DirKind) {
|
||||
ConsumeToken();
|
||||
FirstClause = false;
|
||||
|
||||
// Recovering from a bad clause is really difficult, so we just give up on
|
||||
// error.
|
||||
if (ParseOpenACCClause(DirKind)) {
|
||||
OpenACCClauseParseResult Result = ParseOpenACCClause(Clauses, DirKind);
|
||||
if (OpenACCClause *Clause = Result.getPointer()) {
|
||||
Clauses.push_back(Clause);
|
||||
} else if (Result.getInt() == OpenACCParseCanContinue::Cannot) {
|
||||
// Recovering from a bad clause is really difficult, so we just give up on
|
||||
// error.
|
||||
SkipUntilEndOfDirective(*this);
|
||||
return;
|
||||
return Clauses;
|
||||
}
|
||||
}
|
||||
return Clauses;
|
||||
}
|
||||
|
||||
ExprResult Parser::ParseOpenACCIntExpr() {
|
||||
@@ -762,42 +781,48 @@ bool Parser::ParseOpenACCGangArgList() {
|
||||
// really have its owner grammar and each individual one has its own definition.
|
||||
// However, they all are named with a single-identifier (or auto/default!)
|
||||
// token, followed in some cases by either braces or parens.
|
||||
bool Parser::ParseOpenACCClause(OpenACCDirectiveKind DirKind) {
|
||||
Parser::OpenACCClauseParseResult
|
||||
Parser::ParseOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
|
||||
OpenACCDirectiveKind DirKind) {
|
||||
// A number of clause names are actually keywords, so accept a keyword that
|
||||
// can be converted to a name.
|
||||
if (expectIdentifierOrKeyword(*this))
|
||||
return true;
|
||||
return OpenACCCannotContinue();
|
||||
|
||||
OpenACCClauseKind Kind = getOpenACCClauseKind(getCurToken());
|
||||
|
||||
if (Kind == OpenACCClauseKind::Invalid)
|
||||
return Diag(getCurToken(), diag::err_acc_invalid_clause)
|
||||
<< getCurToken().getIdentifierInfo();
|
||||
if (Kind == OpenACCClauseKind::Invalid) {
|
||||
Diag(getCurToken(), diag::err_acc_invalid_clause)
|
||||
<< getCurToken().getIdentifierInfo();
|
||||
return OpenACCCannotContinue();
|
||||
}
|
||||
|
||||
// Consume the clause name.
|
||||
SourceLocation ClauseLoc = ConsumeToken();
|
||||
|
||||
bool Result = ParseOpenACCClauseParams(DirKind, Kind);
|
||||
getActions().OpenACC().ActOnClause(Kind, ClauseLoc);
|
||||
return Result;
|
||||
return ParseOpenACCClauseParams(ExistingClauses, DirKind, Kind, ClauseLoc);
|
||||
}
|
||||
|
||||
bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
|
||||
OpenACCClauseKind Kind) {
|
||||
Parser::OpenACCClauseParseResult Parser::ParseOpenACCClauseParams(
|
||||
ArrayRef<const OpenACCClause *> ExistingClauses,
|
||||
OpenACCDirectiveKind DirKind, OpenACCClauseKind ClauseKind,
|
||||
SourceLocation ClauseLoc) {
|
||||
BalancedDelimiterTracker Parens(*this, tok::l_paren,
|
||||
tok::annot_pragma_openacc_end);
|
||||
SemaOpenACC::OpenACCParsedClause ParsedClause(DirKind, ClauseKind, ClauseLoc);
|
||||
|
||||
if (ClauseHasRequiredParens(DirKind, Kind)) {
|
||||
if (ClauseHasRequiredParens(DirKind, ClauseKind)) {
|
||||
ParsedClause.setLParenLoc(getCurToken().getLocation());
|
||||
if (Parens.expectAndConsume()) {
|
||||
// We are missing a paren, so assume that the person just forgot the
|
||||
// parameter. Return 'false' so we try to continue on and parse the next
|
||||
// clause.
|
||||
SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openacc_end,
|
||||
Parser::StopBeforeMatch);
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
|
||||
switch (Kind) {
|
||||
switch (ClauseKind) {
|
||||
case OpenACCClauseKind::Default: {
|
||||
Token DefKindTok = getCurToken();
|
||||
|
||||
@@ -818,34 +843,34 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
|
||||
// this clause list.
|
||||
if (CondExpr.isInvalid()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OpenACCClauseKind::CopyIn:
|
||||
tryParseAndConsumeSpecialTokenKind(
|
||||
*this, OpenACCSpecialTokenKind::ReadOnly, Kind);
|
||||
if (ParseOpenACCClauseVarList(Kind)) {
|
||||
*this, OpenACCSpecialTokenKind::ReadOnly, ClauseKind);
|
||||
if (ParseOpenACCClauseVarList(ClauseKind)) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
case OpenACCClauseKind::Create:
|
||||
case OpenACCClauseKind::CopyOut:
|
||||
tryParseAndConsumeSpecialTokenKind(*this, OpenACCSpecialTokenKind::Zero,
|
||||
Kind);
|
||||
if (ParseOpenACCClauseVarList(Kind)) {
|
||||
ClauseKind);
|
||||
if (ParseOpenACCClauseVarList(ClauseKind)) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
case OpenACCClauseKind::Reduction:
|
||||
// If we're missing a clause-kind (or it is invalid), see if we can parse
|
||||
// the var-list anyway.
|
||||
ParseReductionOperator(*this);
|
||||
if (ParseOpenACCClauseVarList(Kind)) {
|
||||
if (ParseOpenACCClauseVarList(ClauseKind)) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
case OpenACCClauseKind::Self:
|
||||
@@ -868,19 +893,19 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
|
||||
case OpenACCClauseKind::Present:
|
||||
case OpenACCClauseKind::Private:
|
||||
case OpenACCClauseKind::UseDevice:
|
||||
if (ParseOpenACCClauseVarList(Kind)) {
|
||||
if (ParseOpenACCClauseVarList(ClauseKind)) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
case OpenACCClauseKind::Collapse: {
|
||||
tryParseAndConsumeSpecialTokenKind(*this, OpenACCSpecialTokenKind::Force,
|
||||
Kind);
|
||||
ClauseKind);
|
||||
ExprResult NumLoops =
|
||||
getActions().CorrectDelayedTyposInExpr(ParseConstantExpression());
|
||||
if (NumLoops.isInvalid()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -888,7 +913,7 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
|
||||
ExprResult BindArg = ParseOpenACCBindClauseArgument();
|
||||
if (BindArg.isInvalid()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -900,7 +925,7 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
|
||||
ExprResult IntExpr = ParseOpenACCIntExpr();
|
||||
if (IntExpr.isInvalid()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -912,23 +937,28 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
|
||||
ConsumeToken();
|
||||
} else if (ParseOpenACCDeviceTypeList()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
case OpenACCClauseKind::Tile:
|
||||
if (ParseOpenACCSizeExprList()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Not a required parens type?");
|
||||
}
|
||||
|
||||
return Parens.consumeClose();
|
||||
} else if (ClauseHasOptionalParens(DirKind, Kind)) {
|
||||
ParsedClause.setEndLoc(getCurToken().getLocation());
|
||||
|
||||
if (Parens.consumeClose())
|
||||
return OpenACCCannotContinue();
|
||||
|
||||
} else if (ClauseHasOptionalParens(DirKind, ClauseKind)) {
|
||||
ParsedClause.setLParenLoc(getCurToken().getLocation());
|
||||
if (!Parens.consumeOpen()) {
|
||||
switch (Kind) {
|
||||
switch (ClauseKind) {
|
||||
case OpenACCClauseKind::Self: {
|
||||
assert(DirKind != OpenACCDirectiveKind::Update);
|
||||
ExprResult CondExpr = ParseOpenACCConditionalExpr(*this);
|
||||
@@ -936,21 +966,22 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
|
||||
// this clause list.
|
||||
if (CondExpr.isInvalid()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OpenACCClauseKind::Vector:
|
||||
case OpenACCClauseKind::Worker: {
|
||||
tryParseAndConsumeSpecialTokenKind(*this,
|
||||
Kind == OpenACCClauseKind::Vector
|
||||
ClauseKind ==
|
||||
OpenACCClauseKind::Vector
|
||||
? OpenACCSpecialTokenKind::Length
|
||||
: OpenACCSpecialTokenKind::Num,
|
||||
Kind);
|
||||
ClauseKind);
|
||||
ExprResult IntExpr = ParseOpenACCIntExpr();
|
||||
if (IntExpr.isInvalid()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -958,29 +989,32 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
|
||||
ExprResult AsyncArg = ParseOpenACCAsyncArgument();
|
||||
if (AsyncArg.isInvalid()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OpenACCClauseKind::Gang:
|
||||
if (ParseOpenACCGangArgList()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
case OpenACCClauseKind::Wait:
|
||||
if (ParseOpenACCWaitArgument()) {
|
||||
Parens.skipToEnd();
|
||||
return false;
|
||||
return OpenACCCanContinue();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Not an optional parens type?");
|
||||
}
|
||||
Parens.consumeClose();
|
||||
ParsedClause.setEndLoc(getCurToken().getLocation());
|
||||
if (Parens.consumeClose())
|
||||
return OpenACCCannotContinue();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return OpenACCSuccess(
|
||||
Actions.OpenACC().ActOnClause(ExistingClauses, ParsedClause));
|
||||
}
|
||||
|
||||
/// OpenACC 3.3 section 2.16:
|
||||
@@ -1204,15 +1238,17 @@ 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(),
|
||||
"Terminating annotation token not present");
|
||||
|
||||
return OpenACCDirectiveParseInfo{DirKind, StartLoc, EndLoc};
|
||||
return ParseInfo;
|
||||
}
|
||||
|
||||
// Parse OpenACC directive on a declaration.
|
||||
@@ -1255,5 +1291,6 @@ StmtResult Parser::ParseOpenACCDirectiveStmt() {
|
||||
}
|
||||
|
||||
return getActions().OpenACC().ActOnEndStmtDirective(
|
||||
DirInfo.DirKind, DirInfo.StartLoc, DirInfo.EndLoc, AssocStmt);
|
||||
DirInfo.DirKind, DirInfo.StartLoc, DirInfo.EndLoc, DirInfo.Clauses,
|
||||
AssocStmt);
|
||||
}
|
||||
|
||||
@@ -36,20 +36,44 @@ 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");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
SemaOpenACC::SemaOpenACC(Sema &S) : SemaBase(S) {}
|
||||
|
||||
bool SemaOpenACC::ActOnClause(OpenACCClauseKind ClauseKind,
|
||||
SourceLocation StartLoc) {
|
||||
if (ClauseKind == OpenACCClauseKind::Invalid)
|
||||
return false;
|
||||
// For now just diagnose that it is unsupported and leave the parsing to do
|
||||
// whatever it can do. This function will eventually need to start returning
|
||||
// some sort of Clause AST type, but for now just return true/false based on
|
||||
// success.
|
||||
return Diag(StartLoc, diag::warn_acc_clause_unimplemented) << ClauseKind;
|
||||
OpenACCClause *
|
||||
SemaOpenACC::ActOnClause(ArrayRef<const OpenACCClause *> ExistingClauses,
|
||||
OpenACCParsedClause &Clause) {
|
||||
if (Clause.getClauseKind() == OpenACCClauseKind::Invalid)
|
||||
return nullptr;
|
||||
|
||||
// Diagnose that we don't support this clause on this directive.
|
||||
if (!doesClauseApplyToDirective(Clause.getDirectiveKind(),
|
||||
Clause.getClauseKind())) {
|
||||
Diag(Clause.getBeginLoc(), diag::err_acc_clause_appertainment)
|
||||
<< Clause.getDirectiveKind() << Clause.getClauseKind();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// TODO OpenACC: Switch over the clauses we implement here and 'create'
|
||||
// them.
|
||||
|
||||
Diag(Clause.getBeginLoc(), diag::warn_acc_clause_unimplemented)
|
||||
<< Clause.getClauseKind();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SemaOpenACC::ActOnConstruct(OpenACCDirectiveKind K,
|
||||
SourceLocation StartLoc) {
|
||||
switch (K) {
|
||||
@@ -79,6 +103,7 @@ bool SemaOpenACC::ActOnStartStmtDirective(OpenACCDirectiveKind K,
|
||||
StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K,
|
||||
SourceLocation StartLoc,
|
||||
SourceLocation EndLoc,
|
||||
ArrayRef<OpenACCClause *> Clauses,
|
||||
StmtResult AssocStmt) {
|
||||
switch (K) {
|
||||
default:
|
||||
@@ -90,8 +115,7 @@ StmtResult SemaOpenACC::ActOnEndStmtDirective(OpenACCDirectiveKind K,
|
||||
case OpenACCDirectiveKind::Kernels:
|
||||
// TODO OpenACC: Add clauses to the construct here.
|
||||
return OpenACCComputeConstruct::Create(
|
||||
getASTContext(), K, StartLoc, EndLoc,
|
||||
/*Clauses=*/std::nullopt,
|
||||
getASTContext(), K, StartLoc, EndLoc, Clauses,
|
||||
AssocStmt.isUsable() ? AssocStmt.get() : nullptr);
|
||||
}
|
||||
llvm_unreachable("Unhandled case in directive handling?");
|
||||
|
||||
@@ -4005,17 +4005,10 @@ public:
|
||||
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K,
|
||||
SourceLocation BeginLoc,
|
||||
SourceLocation EndLoc,
|
||||
ArrayRef<OpenACCClause *> Clauses,
|
||||
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);
|
||||
|
||||
return getSema().OpenACC().ActOnEndStmtDirective(K, BeginLoc, EndLoc,
|
||||
StrBlock);
|
||||
Clauses, StrBlock);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -4036,6 +4029,10 @@ private:
|
||||
QualType TransformDependentNameType(TypeLocBuilder &TLB,
|
||||
DependentNameTypeLoc TL,
|
||||
bool DeducibleTSTContext);
|
||||
|
||||
llvm::SmallVector<OpenACCClause *>
|
||||
TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
|
||||
ArrayRef<const OpenACCClause *> OldClauses);
|
||||
};
|
||||
|
||||
template <typename Derived>
|
||||
@@ -11076,16 +11073,38 @@ OMPClause *TreeTransform<Derived>::TransformOMPXBareClause(OMPXBareClause *C) {
|
||||
//===----------------------------------------------------------------------===//
|
||||
// OpenACC transformation
|
||||
//===----------------------------------------------------------------------===//
|
||||
template <typename Derived>
|
||||
llvm::SmallVector<OpenACCClause *>
|
||||
TreeTransform<Derived>::TransformOpenACCClauseList(
|
||||
OpenACCDirectiveKind DirKind, ArrayRef<const OpenACCClause *> OldClauses) {
|
||||
// TODO OpenACC: Ensure we loop through the list and transform the individual
|
||||
// clauses.
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename Derived>
|
||||
StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
|
||||
OpenACCComputeConstruct *C) {
|
||||
// TODO OpenACC: Transform clauses.
|
||||
getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
|
||||
// FIXME: When implementing this for constructs that can take arguments, we
|
||||
// should do Sema for them here.
|
||||
|
||||
if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
|
||||
C->getBeginLoc()))
|
||||
return StmtError();
|
||||
|
||||
llvm::SmallVector<OpenACCClause *> TransformedClauses =
|
||||
getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
|
||||
C->clauses());
|
||||
|
||||
// Transform Structured Block.
|
||||
StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
|
||||
StrBlock =
|
||||
getSema().OpenACC().ActOnAssociatedStmt(C->getDirectiveKind(), StrBlock);
|
||||
|
||||
return getDerived().RebuildOpenACCComputeConstruct(
|
||||
C->getDirectiveKind(), C->getBeginLoc(), C->getEndLoc(), StrBlock);
|
||||
C->getDirectiveKind(), C->getBeginLoc(), C->getEndLoc(),
|
||||
TransformedClauses, StrBlock);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -56,9 +56,8 @@ void function();
|
||||
// expected-warning@+2{{OpenACC clause 'bind' not yet implemented, clause ignored}}
|
||||
// expected-warning@+1{{OpenACC construct 'routine' not yet implemented, pragma ignored}}
|
||||
#pragma acc routine(use) bind(NS::NSFunc)
|
||||
// expected-error@+4{{'RecordTy' does not refer to a value}}
|
||||
// expected-error@+3{{'RecordTy' does not refer to a value}}
|
||||
// expected-note@#RecTy{{declared here}}
|
||||
// expected-warning@+2{{OpenACC clause 'bind' not yet implemented, clause ignored}}
|
||||
// expected-warning@+1{{OpenACC construct 'routine' not yet implemented, pragma ignored}}
|
||||
#pragma acc routine(use) bind(NS::RecordTy)
|
||||
// expected-error@+4{{'Value' is a private member of 'NS::RecordTy'}}
|
||||
@@ -72,8 +71,7 @@ void function();
|
||||
// expected-warning@+2{{OpenACC clause 'bind' not yet implemented, clause ignored}}
|
||||
// expected-warning@+1{{OpenACC construct 'routine' not yet implemented, pragma ignored}}
|
||||
#pragma acc routine(use) bind(NS::TemplTy<int>)
|
||||
// expected-error@+3{{no member named 'unknown' in namespace 'NS'}}
|
||||
// expected-warning@+2{{OpenACC clause 'bind' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{no member named 'unknown' in namespace 'NS'}}
|
||||
// expected-warning@+1{{OpenACC construct 'routine' not yet implemented, pragma ignored}}
|
||||
#pragma acc routine(use) bind(NS::unknown<int>)
|
||||
// expected-warning@+2{{OpenACC clause 'bind' not yet implemented, clause ignored}}
|
||||
@@ -88,8 +86,7 @@ void function();
|
||||
// expected-warning@+1{{OpenACC construct 'routine' not yet implemented, pragma ignored}}
|
||||
#pragma acc routine(use) bind(NS::RecordTy::mem_function)
|
||||
|
||||
// expected-error@+3{{string literal with user-defined suffix cannot be used here}}
|
||||
// expected-warning@+2{{OpenACC clause 'bind' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{string literal with user-defined suffix cannot be used here}}
|
||||
// expected-warning@+1{{OpenACC construct 'routine' not yet implemented, pragma ignored}}
|
||||
#pragma acc routine(use) bind("unknown udl"_UDL)
|
||||
|
||||
|
||||
@@ -12,9 +12,8 @@ void func() {
|
||||
#pragma acc parallel wait clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait (
|
||||
{}
|
||||
|
||||
@@ -27,45 +26,38 @@ void func() {
|
||||
#pragma acc parallel wait () clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+4{{expected expression}}
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+3{{expected expression}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait (devnum:
|
||||
{}
|
||||
|
||||
// expected-error@+2{{expected expression}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+1{{expected expression}}
|
||||
#pragma acc parallel wait (devnum:)
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected expression}}
|
||||
// expected-error@+2{{invalid OpenACC clause 'clause'}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected expression}}
|
||||
// expected-error@+1{{invalid OpenACC clause 'clause'}}
|
||||
#pragma acc parallel wait (devnum:) clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+4{{expected ':'}}
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+3{{expected ':'}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait (devnum: i + j
|
||||
{}
|
||||
|
||||
// expected-error@+2{{expected ':'}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+1{{expected ':'}}
|
||||
#pragma acc parallel wait (devnum: i + j)
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected ':'}}
|
||||
// expected-error@+2{{invalid OpenACC clause 'clause'}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected ':'}}
|
||||
// expected-error@+1{{invalid OpenACC clause 'clause'}}
|
||||
#pragma acc parallel wait (devnum: i + j) clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait (queues:
|
||||
{}
|
||||
|
||||
@@ -78,9 +70,8 @@ void func() {
|
||||
#pragma acc parallel wait (queues:) clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait (devnum: i + j:queues:
|
||||
{}
|
||||
|
||||
@@ -93,27 +84,23 @@ void func() {
|
||||
#pragma acc parallel wait (devnum: i + j:queues:) clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+4{{use of undeclared identifier 'devnum'}}
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+3{{use of undeclared identifier 'devnum'}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait (queues:devnum: i + j
|
||||
{}
|
||||
|
||||
// expected-error@+2{{use of undeclared identifier 'devnum'}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+1{{use of undeclared identifier 'devnum'}}
|
||||
#pragma acc parallel wait (queues:devnum: i + j)
|
||||
{}
|
||||
|
||||
// expected-error@+3{{use of undeclared identifier 'devnum'}}
|
||||
// expected-error@+2{{invalid OpenACC clause 'clause'}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{use of undeclared identifier 'devnum'}}
|
||||
// expected-error@+1{{invalid OpenACC clause 'clause'}}
|
||||
#pragma acc parallel wait (queues:devnum: i + j) clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait(i, j, 1+1, 3.3
|
||||
{}
|
||||
|
||||
@@ -125,34 +112,29 @@ void func() {
|
||||
#pragma acc parallel wait(i, j, 1+1, 3.3) clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+4{{expected expression}}
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+3{{expected expression}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait(,
|
||||
{}
|
||||
|
||||
// expected-error@+2{{expected expression}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+1{{expected expression}}
|
||||
#pragma acc parallel wait(,)
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected expression}}
|
||||
// expected-error@+2{{invalid OpenACC clause 'clause'}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected expression}}
|
||||
// expected-error@+1{{invalid OpenACC clause 'clause'}}
|
||||
#pragma acc parallel wait(,) clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait(queues:i, j, 1+1, 3.3
|
||||
{}
|
||||
|
||||
// expected-error@+4{{expected expression}}
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+3{{expected expression}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait(queues:i, j, 1+1, 3.3,
|
||||
{}
|
||||
|
||||
@@ -165,9 +147,8 @@ void func() {
|
||||
#pragma acc parallel wait(queues:i, j, 1+1, 3.3) clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait(devnum:3:i, j, 1+1, 3.3
|
||||
{}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
@@ -178,9 +159,8 @@ void func() {
|
||||
#pragma acc parallel wait(devnum:3:i, j, 1+1, 3.3) clause-list
|
||||
{}
|
||||
|
||||
// expected-error@+3{{expected ')'}}
|
||||
// expected-note@+2{{to match this '('}}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
// expected-error@+2{{expected ')'}}
|
||||
// expected-note@+1{{to match this '('}}
|
||||
#pragma acc parallel wait(devnum:3:queues:i, j, 1+1, 3.3
|
||||
{}
|
||||
// expected-warning@+1{{OpenACC clause 'wait' not yet implemented, clause ignored}}
|
||||
|
||||
Reference in New Issue
Block a user