Skip to content

Commit 0aa7892

Browse files
committed
[OpenACC] Implement 'tile' for combined constructs
Like collapse, this clause has only mild changes that need to be made. Most of the associated work for the RAII container was already done previously, so this is mostly just updating the diagnostics to properly emit the right construct.
1 parent a15400d commit 0aa7892

7 files changed

+747
-16
lines changed

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class SemaOpenACC : public SemaBase {
107107
/// which allows us to diagnose if the number of arguments is too large for
108108
/// the current number of 'for' loops.
109109
bool TileDepthSatisfied = true;
110+
111+
/// Records the kind of the directive that this clause is attached to, which
112+
/// allows us to use it in diagnostics.
113+
OpenACCDirectiveKind DirectiveKind = OpenACCDirectiveKind::Invalid;
110114
} TileInfo;
111115

112116
/// A list of the active reduction clauses, which allows us to check that all

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -598,9 +598,6 @@ OpenACCClause *SemaOpenACCClauseVisitor::VisitDefaultClause(
598598

599599
OpenACCClause *SemaOpenACCClauseVisitor::VisitTileClause(
600600
SemaOpenACC::OpenACCParsedClause &Clause) {
601-
// TODO OpenACC: Remove this when we get combined construct impl for this.
602-
if (Clause.getDirectiveKind() != OpenACCDirectiveKind::Loop)
603-
return isNotImplemented();
604601

605602
// Duplicates here are not really sensible. We could possible permit
606603
// multiples if they all had the same value, but there isn't really a good
@@ -1718,6 +1715,7 @@ void SemaOpenACC::AssociatedStmtRAII::SetTileInfoBeforeAssociatedStmt(
17181715
SemaRef.TileInfo.ActiveTile = TileClause;
17191716
SemaRef.TileInfo.TileDepthSatisfied = false;
17201717
SemaRef.TileInfo.CurTileCount = TileClause->getSizeExprs().size();
1718+
SemaRef.TileInfo.DirectiveKind = DirKind;
17211719
}
17221720

17231721
SemaOpenACC::AssociatedStmtRAII::~AssociatedStmtRAII() {
@@ -2608,7 +2606,7 @@ void SemaOpenACC::ActOnWhileStmt(SourceLocation WhileLoc) {
26082606

26092607
if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
26102608
Diag(WhileLoc, diag::err_acc_invalid_in_loop)
2611-
<< /*while loop*/ 1 << OpenACCDirectiveKind::Loop
2609+
<< /*while loop*/ 1 << TileInfo.DirectiveKind
26122610
<< OpenACCClauseKind::Tile;
26132611
assert(TileInfo.ActiveTile && "tile count without object?");
26142612
Diag(TileInfo.ActiveTile->getBeginLoc(), diag::note_acc_active_clause_here)
@@ -2643,8 +2641,7 @@ void SemaOpenACC::ActOnDoStmt(SourceLocation DoLoc) {
26432641

26442642
if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
26452643
Diag(DoLoc, diag::err_acc_invalid_in_loop)
2646-
<< /*do loop*/ 2 << OpenACCDirectiveKind::Loop
2647-
<< OpenACCClauseKind::Tile;
2644+
<< /*do loop*/ 2 << TileInfo.DirectiveKind << OpenACCClauseKind::Tile;
26482645
assert(TileInfo.ActiveTile && "tile count without object?");
26492646
Diag(TileInfo.ActiveTile->getBeginLoc(), diag::note_acc_active_clause_here)
26502647
<< OpenACCClauseKind::Tile;
@@ -2692,7 +2689,7 @@ void SemaOpenACC::ForStmtBeginHelper(SourceLocation ForLoc,
26922689

26932690
if (LoopInfo.CurLevelHasLoopAlready) {
26942691
Diag(ForLoc, diag::err_acc_clause_multiple_loops)
2695-
<< OpenACCDirectiveKind::Loop << OpenACCClauseKind::Tile;
2692+
<< TileInfo.DirectiveKind << OpenACCClauseKind::Tile;
26962693
assert(TileInfo.ActiveTile && "No tile object?");
26972694
Diag(TileInfo.ActiveTile->getBeginLoc(),
26982695
diag::note_acc_active_clause_here)
@@ -3203,7 +3200,7 @@ void SemaOpenACC::ActOnForStmtEnd(SourceLocation ForLoc, StmtResult Body) {
32033200

32043201
if (OtherStmtLoc.isValid() && IsActiveTile) {
32053202
Diag(OtherStmtLoc, diag::err_acc_intervening_code)
3206-
<< OpenACCClauseKind::Tile << OpenACCDirectiveKind::Loop;
3203+
<< OpenACCClauseKind::Tile << TileInfo.DirectiveKind;
32073204
Diag(TileInfo.ActiveTile->getBeginLoc(),
32083205
diag::note_acc_active_clause_here)
32093206
<< OpenACCClauseKind::Tile;
@@ -3232,7 +3229,7 @@ bool SemaOpenACC::ActOnStartStmtDirective(OpenACCDirectiveKind K,
32323229
}
32333230
if (TileInfo.CurTileCount && *TileInfo.CurTileCount > 0) {
32343231
Diag(StartLoc, diag::err_acc_invalid_in_loop)
3235-
<< /*OpenACC Construct*/ 0 << OpenACCDirectiveKind::Loop
3232+
<< /*OpenACC Construct*/ 0 << TileInfo.DirectiveKind
32363233
<< OpenACCClauseKind::Tile << K;
32373234
assert(TileInfo.ActiveTile && "Tile count without object?");
32383235
Diag(TileInfo.ActiveTile->getBeginLoc(), diag::note_acc_active_clause_here)

clang/test/AST/ast-print-openacc-combined-construct.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clang_cc1 -fopenacc -Wno-openacc-deprecated-clause-alias -ast-print %s -o - | FileCheck %s
22

3+
constexpr int get_value() { return 1; }
34
void foo() {
45
int *iPtr;
56
// CHECK: #pragma acc parallel loop
@@ -210,4 +211,17 @@ void foo() {
210211
#pragma acc parallel loop collapse(force:2)
211212
for(int i = 0;i<5;++i)
212213
for(int i = 0;i<5;++i);
214+
215+
// CHECK: #pragma acc serial loop tile(1, 3, *, get_value())
216+
// CHECK-NEXT: for (int i = 0; i < 5; ++i)
217+
// CHECK-NEXT: for (int i = 0; i < 5; ++i)
218+
// CHECK-NEXT: for (int i = 0; i < 5; ++i)
219+
// CHECK-NEXT: for (int i = 0; i < 5; ++i)
220+
// CHECK-NEXT: ;
221+
#pragma acc serial loop tile(1, 3, *, get_value())
222+
for(int i = 0;i<5;++i)
223+
for(int i = 0;i<5;++i)
224+
for(int i = 0;i<5;++i)
225+
for(int i = 0;i<5;++i);
226+
213227
}

clang/test/SemaOpenACC/combined-construct-auto_seq_independent-clauses.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ void uses() {
158158
for(unsigned i = 0; i < 5; ++i);
159159
#pragma acc parallel loop auto async
160160
for(unsigned i = 0; i < 5; ++i);
161-
// expected-warning@+1{{OpenACC clause 'tile' not yet implemented}}
162161
#pragma acc parallel loop auto tile(1+2, 1)
163162
for(unsigned j = 0; j < 5; ++j)
164163
for(unsigned i = 0; i < 5; ++i);
@@ -286,7 +285,6 @@ void uses() {
286285
for(unsigned i = 0; i < 5; ++i);
287286
#pragma acc parallel loop async auto
288287
for(unsigned i = 0; i < 5; ++i);
289-
// expected-warning@+1{{OpenACC clause 'tile' not yet implemented}}
290288
#pragma acc parallel loop tile(1+2, 1) auto
291289
for(unsigned j = 0; j < 5; ++j)
292290
for(unsigned i = 0; i < 5; ++i);
@@ -415,7 +413,6 @@ void uses() {
415413
for(unsigned i = 0; i < 5; ++i);
416414
#pragma acc parallel loop independent async
417415
for(unsigned i = 0; i < 5; ++i);
418-
// expected-warning@+1{{OpenACC clause 'tile' not yet implemented}}
419416
#pragma acc parallel loop independent tile(1+2, 1)
420417
for(unsigned j = 0; j < 5; ++j)
421418
for(unsigned i = 0; i < 5; ++i);
@@ -543,7 +540,6 @@ void uses() {
543540
for(unsigned i = 0; i < 5; ++i);
544541
#pragma acc parallel loop async independent
545542
for(unsigned i = 0; i < 5; ++i);
546-
// expected-warning@+1{{OpenACC clause 'tile' not yet implemented}}
547543
#pragma acc parallel loop tile(1+2, 1) independent
548544
for(unsigned j = 0; j < 5; ++j)
549545
for(unsigned i = 0; i < 5; ++i);
@@ -678,7 +674,6 @@ void uses() {
678674
for(unsigned i = 0; i < 5; ++i);
679675
#pragma acc parallel loop seq async
680676
for(unsigned i = 0; i < 5; ++i);
681-
// expected-warning@+1{{OpenACC clause 'tile' not yet implemented}}
682677
#pragma acc parallel loop seq tile(1+2, 1)
683678
for(;;)
684679
for(unsigned i = 0; i < 5; ++i);
@@ -812,7 +807,6 @@ void uses() {
812807
for(unsigned i = 0; i < 5; ++i);
813808
#pragma acc parallel loop async seq
814809
for(unsigned i = 0; i < 5; ++i);
815-
// expected-warning@+1{{OpenACC clause 'tile' not yet implemented}}
816810
#pragma acc parallel loop tile(1+2, 1) seq
817811
for(;;)
818812
for(unsigned i = 0; i < 5; ++i);

clang/test/SemaOpenACC/combined-construct-device_type-clause.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ void uses() {
209209
#pragma acc parallel loop device_type(*) async
210210
for(int i = 0; i < 5; ++i);
211211

212-
// expected-warning@+1{{OpenACC clause 'tile' not yet implemented, clause ignored}}
213212
#pragma acc serial loop device_type(*) tile(*, 1)
214213
for(int j = 0; j < 5; ++j)
215214
for(int i = 0; i < 5; ++i);

0 commit comments

Comments
 (0)