Skip to content

Commit 137ff16

Browse files
erichkeanesmallp-o-p
authored andcommitted
[OpenACC] Implement 'reduction' Sema on 'loop' construct
The reduction clause has some minor restrictions on the variable references that are implementable, so this implements those. Others require reachability analysis, so this patch documents that we're not going to do that in the CFE(or at least save it for the MLIR passes).
1 parent 171608a commit 137ff16

File tree

8 files changed

+1086
-26
lines changed

8 files changed

+1086
-26
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12718,7 +12718,18 @@ def err_acc_num_arg_conflict
1271812718
def err_acc_clause_in_clause_region
1271912719
: Error<"loop with a '%0' clause may not exist in the region of a '%1' "
1272012720
"clause%select{| on a 'kernels' compute construct}2">;
12721-
12721+
def err_acc_gang_reduction_conflict
12722+
: Error<"%select{OpenACC 'gang' clause with a 'dim' value greater than "
12723+
"1|OpenACC 'reduction' clause}0 cannot "
12724+
"appear on the same 'loop' construct as a %select{'reduction' "
12725+
"clause|'gang' clause with a 'dim' value greater than 1}0">;
12726+
def err_acc_gang_reduction_numgangs_conflict
12727+
: Error<"OpenACC '%0' clause cannot appear on the same 'loop' construct "
12728+
"as a '%1' clause inside a compute construct with a "
12729+
"'num_gangs' clause with more than one argument">;
12730+
def err_reduction_op_mismatch
12731+
: Error<"OpenACC 'reduction' variable must have the same operator in all "
12732+
"nested constructs (%0 vs %1)">;
1272212733
// AMDGCN builtins diagnostics
1272312734
def err_amdgcn_global_load_lds_size_invalid_value : Error<"invalid size value">;
1272412735
def note_amdgcn_global_load_lds_size_valid_value : Note<"size must be 1, 2, or 4">;

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SemaOpenACC : public SemaBase {
6868
/// used to diagnose if there are multiple 'for' loops at any one level.
6969
LLVM_PREFERRED_TYPE(bool)
7070
unsigned CurLevelHasLoopAlready : 1;
71+
7172
} LoopInfo{/*TopLevelLoopSeen=*/false, /*CurLevelHasLoopAlready=*/false};
7273

7374
/// The 'collapse' clause requires quite a bit of checking while
@@ -109,6 +110,14 @@ class SemaOpenACC : public SemaBase {
109110
bool TileDepthSatisfied = true;
110111
} TileInfo;
111112

113+
/// A list of the active reduction clauses, which allows us to check that all
114+
/// vars on nested constructs for the same reduction var have the same
115+
/// reduction operator. Currently this is enforced against all constructs
116+
/// despite the rule being in the 'loop' section. By current reading, this
117+
/// should apply to all anyway, but we may need to make this more like the
118+
/// 'loop' clause enforcement, where this is 'blocked' by a compute construct.
119+
llvm::SmallVector<OpenACCReductionClause *> ActiveReductionClauses;
120+
112121
public:
113122
ComputeConstructInfo &getActiveComputeConstructInfo() {
114123
return ActiveComputeConstructInfo;
@@ -615,7 +624,9 @@ class SemaOpenACC : public SemaBase {
615624

616625
/// Called while semantically analyzing the reduction clause, ensuring the var
617626
/// is the correct kind of reference.
618-
ExprResult CheckReductionVar(Expr *VarExpr);
627+
ExprResult CheckReductionVar(OpenACCDirectiveKind DirectiveKind,
628+
OpenACCReductionOperator ReductionOp,
629+
Expr *VarExpr);
619630

620631
/// Called to check the 'var' type is a variable of pointer type, necessary
621632
/// for 'deviceptr' and 'attach' clauses. Returns true on success.
@@ -634,6 +645,22 @@ class SemaOpenACC : public SemaBase {
634645
// Check a single expression on a gang clause.
635646
ExprResult CheckGangExpr(OpenACCGangKind GK, Expr *E);
636647

648+
// Does the checking for a 'gang' clause that needs to be done in dependent
649+
// and not dependent cases.
650+
OpenACCClause *
651+
CheckGangClause(ArrayRef<const OpenACCClause *> ExistingClauses,
652+
SourceLocation BeginLoc, SourceLocation LParenLoc,
653+
ArrayRef<OpenACCGangKind> GangKinds,
654+
ArrayRef<Expr *> IntExprs, SourceLocation EndLoc);
655+
// Does the checking for a 'reduction ' clause that needs to be done in
656+
// dependent and not dependent cases.
657+
OpenACCClause *
658+
CheckReductionClause(ArrayRef<const OpenACCClause *> ExistingClauses,
659+
OpenACCDirectiveKind DirectiveKind,
660+
SourceLocation BeginLoc, SourceLocation LParenLoc,
661+
OpenACCReductionOperator ReductionOp,
662+
ArrayRef<Expr *> Vars, SourceLocation EndLoc);
663+
637664
ExprResult BuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc);
638665
ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc);
639666

@@ -686,6 +713,7 @@ class SemaOpenACC : public SemaBase {
686713
SourceLocation OldLoopWorkerClauseLoc;
687714
SourceLocation OldLoopVectorClauseLoc;
688715
llvm::SmallVector<OpenACCLoopConstruct *> ParentlessLoopConstructs;
716+
llvm::SmallVector<OpenACCReductionClause *> ActiveReductionClauses;
689717
LoopInConstructRAII LoopRAII;
690718

691719
public:

0 commit comments

Comments
 (0)