Skip to content

Commit 3a4b9f3

Browse files
committedDec 5, 2024·
[OpenACC] Implement 'gang' clause for Combined Constructs
This one is a bit complicated, as it has some interesting interactions, as 'gang' Sema is required to look at its containing compute construct. Except in the case of a combined construct, they are the same. This resulted in a large refactor of the checking code for CheckGangExpr, plus some additional work on the diagnostics for its interaction with 'num_gangs' and 'vector'/'worker'.
1 parent 707e089 commit 3a4b9f3

11 files changed

+888
-203
lines changed
 

‎clang/include/clang/AST/OpenACCClause.h

+8
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,14 @@ class OpenACCGangClause final
483483
return {getGangKind(I), getExprs()[I]};
484484
}
485485

486+
bool hasExprOfKind(OpenACCGangKind GK) const {
487+
for (unsigned I = 0; I < getNumExprs(); ++I) {
488+
if (getGangKind(I) == GK)
489+
return true;
490+
}
491+
return false;
492+
}
493+
486494
static OpenACCGangClause *
487495
Create(const ASTContext &Ctx, SourceLocation BeginLoc,
488496
SourceLocation LParenLoc, ArrayRef<OpenACCGangKind> GangKinds,

‎clang/include/clang/Basic/DiagnosticSemaKinds.td

+10-9
Original file line numberDiff line numberDiff line change
@@ -12755,21 +12755,22 @@ def err_acc_gang_multiple_elt
1275512755
: Error<"OpenACC 'gang' clause may have at most one %select{unnamed or "
1275612756
"'num'|'dim'|'static'}0 argument">;
1275712757
def err_acc_int_arg_invalid
12758-
: Error<"'%1' argument on '%0' clause is not permitted on a%select{n "
12759-
"orphaned|||}2 'loop' construct %select{|associated with a "
12760-
"'parallel' compute construct|associated with a 'kernels' compute "
12761-
"construct|associated with a 'serial' compute construct}2">;
12758+
: Error<"'%0' argument on '%1' clause is not permitted on a%select{|n "
12759+
"orphaned}2 '%3' construct%select{| associated with a '%5' compute "
12760+
"construct}4">;
1276212761
def err_acc_gang_dim_value
1276312762
: Error<"argument to 'gang' clause dimension must be %select{a constant "
1276412763
"expression|1, 2, or 3: evaluated to %1}0">;
1276512764
def err_acc_num_arg_conflict
12766-
: Error<"'num' argument to '%0' clause not allowed on a 'loop' construct "
12767-
"associated with a 'kernels' construct that has a "
12768-
"'%select{num_gangs|num_workers|vector_length}1' "
12769-
"clause">;
12765+
: Error<"'num' argument to '%0' clause not allowed on a '%1' "
12766+
"construct%select{| associated with a '%3' construct}2 that has a "
12767+
"'%4' clause">;
12768+
def err_acc_num_arg_conflict_reverse
12769+
: Error<"'num_gangs' clause not allowed on a 'kernels loop' construct that "
12770+
"has a 'gang' clause with a 'num' argument">;
1277012771
def err_acc_clause_in_clause_region
1277112772
: Error<"loop with a '%0' clause may not exist in the region of a '%1' "
12772-
"clause%select{| on a 'kernels' compute construct}2">;
12773+
"clause%select{| on a '%3' construct}2">;
1277312774
def err_acc_gang_reduction_conflict
1277412775
: Error<"%select{OpenACC 'gang' clause with a 'dim' value greater than "
1277512776
"1|OpenACC 'reduction' clause}0 cannot "

‎clang/include/clang/Sema/SemaOpenACC.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,14 @@ class SemaOpenACC : public SemaBase {
164164
}
165165

166166
/// If there is a current 'active' loop construct with a 'gang' clause on a
167-
/// 'kernel' construct, this will have the source location for it. This
168-
/// permits us to implement the restriction of no further 'gang' clauses.
169-
SourceLocation LoopGangClauseOnKernelLoc;
167+
/// 'kernel' construct, this will have the source location for it, and the
168+
/// 'kernel kind'. This permits us to implement the restriction of no further
169+
/// 'gang' clauses.
170+
struct LoopGangOnKernelTy {
171+
SourceLocation Loc;
172+
OpenACCDirectiveKind DirKind = OpenACCDirectiveKind::Invalid;
173+
} LoopGangClauseOnKernel;
174+
170175
/// If there is a current 'active' loop construct with a 'worker' clause on it
171176
/// (on any sort of construct), this has the source location for it. This
172177
/// permits us to implement the restriction of no further 'gang' or 'worker'
@@ -705,7 +710,9 @@ class SemaOpenACC : public SemaBase {
705710
ExprResult CheckTileSizeExpr(Expr *SizeExpr);
706711

707712
// Check a single expression on a gang clause.
708-
ExprResult CheckGangExpr(OpenACCGangKind GK, Expr *E);
713+
ExprResult CheckGangExpr(ArrayRef<const OpenACCClause *> ExistingClauses,
714+
OpenACCDirectiveKind DK, OpenACCGangKind GK,
715+
Expr *E);
709716

710717
// Does the checking for a 'gang' clause that needs to be done in dependent
711718
// and not dependent cases.
@@ -771,7 +778,7 @@ class SemaOpenACC : public SemaBase {
771778
SemaOpenACC &SemaRef;
772779
ComputeConstructInfo OldActiveComputeConstructInfo;
773780
OpenACCDirectiveKind DirKind;
774-
SourceLocation OldLoopGangClauseOnKernelLoc;
781+
LoopGangOnKernelTy OldLoopGangClauseOnKernel;
775782
SourceLocation OldLoopWorkerClauseLoc;
776783
SourceLocation OldLoopVectorClauseLoc;
777784
LoopWithoutSeqCheckingInfo OldLoopWithoutSeqInfo;

1 commit comments

Comments
 (1)

shafik commented on Jan 18, 2025

@shafik
Collaborator

@erichkeane in CheckGangKernelsExpr you have some unreachable code:

case OpenACCGangKind::Static:
    return CheckGangStaticExpr(S, E);
    return ExprError();
Please sign in to comment.