@@ -66,9 +66,14 @@ class SemaOpenACC : public SemaBase {
66
66
struct DeviceTypeDetails {
67
67
SmallVector<DeviceTypeArgument> Archs;
68
68
};
69
+ struct ReductionDetails {
70
+ OpenACCReductionOperator Op;
71
+ SmallVector<Expr *> VarList;
72
+ };
69
73
70
74
std::variant<std::monostate, DefaultDetails, ConditionDetails,
71
- IntExprDetails, VarListDetails, WaitDetails, DeviceTypeDetails>
75
+ IntExprDetails, VarListDetails, WaitDetails, DeviceTypeDetails,
76
+ ReductionDetails>
72
77
Details = std::monostate{};
73
78
74
79
public:
@@ -170,6 +175,10 @@ class SemaOpenACC : public SemaBase {
170
175
return const_cast <OpenACCParsedClause *>(this )->getIntExprs ();
171
176
}
172
177
178
+ OpenACCReductionOperator getReductionOp () const {
179
+ return std::get<ReductionDetails>(Details).Op ;
180
+ }
181
+
173
182
ArrayRef<Expr *> getVarList () {
174
183
assert ((ClauseKind == OpenACCClauseKind::Private ||
175
184
ClauseKind == OpenACCClauseKind::NoCreate ||
@@ -188,8 +197,13 @@ class SemaOpenACC : public SemaBase {
188
197
ClauseKind == OpenACCClauseKind::PresentOrCreate ||
189
198
ClauseKind == OpenACCClauseKind::Attach ||
190
199
ClauseKind == OpenACCClauseKind::DevicePtr ||
200
+ ClauseKind == OpenACCClauseKind::Reduction ||
191
201
ClauseKind == OpenACCClauseKind::FirstPrivate) &&
192
202
" Parsed clause kind does not have a var-list" );
203
+
204
+ if (ClauseKind == OpenACCClauseKind::Reduction)
205
+ return std::get<ReductionDetails>(Details).VarList ;
206
+
193
207
return std::get<VarListDetails>(Details).VarList ;
194
208
}
195
209
@@ -334,6 +348,13 @@ class SemaOpenACC : public SemaBase {
334
348
Details = VarListDetails{std::move (VarList), IsReadOnly, IsZero};
335
349
}
336
350
351
+ void setReductionDetails (OpenACCReductionOperator Op,
352
+ llvm::SmallVector<Expr *> &&VarList) {
353
+ assert (ClauseKind == OpenACCClauseKind::Reduction &&
354
+ " reduction details only valid on reduction" );
355
+ Details = ReductionDetails{Op, std::move (VarList)};
356
+ }
357
+
337
358
void setWaitDetails (Expr *DevNum, SourceLocation QueuesLoc,
338
359
llvm::SmallVector<Expr *> &&IntExprs) {
339
360
assert (ClauseKind == OpenACCClauseKind::Wait &&
@@ -394,7 +415,11 @@ class SemaOpenACC : public SemaBase {
394
415
395
416
// / Called when encountering a 'var' for OpenACC, ensures it is actually a
396
417
// / declaration reference to a variable of the correct type.
397
- ExprResult ActOnVar (Expr *VarExpr);
418
+ ExprResult ActOnVar (OpenACCClauseKind CK, Expr *VarExpr);
419
+
420
+ // / Called while semantically analyzing the reduction clause, ensuring the var
421
+ // / is the correct kind of reference.
422
+ ExprResult CheckReductionVar (Expr *VarExpr);
398
423
399
424
// / Called to check the 'var' type is a variable of pointer type, necessary
400
425
// / for 'deviceptr' and 'attach' clauses. Returns true on success.
0 commit comments