@@ -52,7 +52,8 @@ class CanonicalizationOfAcc {
52
52
// If there are n tile sizes in the list, the loop construct must be
53
53
// immediately followed by n tightly-nested loops.
54
54
template <typename C, typename D>
55
- void CheckTileClauseRestriction (const C &x) {
55
+ void CheckTileClauseRestriction (
56
+ const C &x, const parser::DoConstruct &outer) {
56
57
const auto &beginLoopDirective = std::get<D>(x.t );
57
58
const auto &accClauseList =
58
59
std::get<parser::AccClauseList>(beginLoopDirective.t );
@@ -63,11 +64,10 @@ class CanonicalizationOfAcc {
63
64
const std::list<parser::AccTileExpr> &listTileExpr = tileExprList.v ;
64
65
std::size_t tileArgNb = listTileExpr.size ();
65
66
66
- const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t )};
67
- if (outer->IsDoConcurrent ()) {
67
+ if (outer.IsDoConcurrent ()) {
68
68
return ; // Tile is not allowed on DO CONCURRENT
69
69
}
70
- for (const parser::DoConstruct *loop{&* outer}; loop && tileArgNb > 0 ;
70
+ for (const parser::DoConstruct *loop{&outer}; loop && tileArgNb > 0 ;
71
71
--tileArgNb) {
72
72
const auto &block{std::get<parser::Block>(loop->t )};
73
73
const auto it{block.begin ()};
@@ -89,9 +89,9 @@ class CanonicalizationOfAcc {
89
89
// A tile and collapse clause may not appear on loop that is associated with
90
90
// do concurrent.
91
91
template <typename C, typename D>
92
- void CheckDoConcurrentClauseRestriction (const C &x) {
93
- const auto &doCons{std::get<std::optional< parser::DoConstruct>>(x. t )};
94
- if (!doCons-> IsDoConcurrent ()) {
92
+ void CheckDoConcurrentClauseRestriction (
93
+ const C &x, const parser::DoConstruct &doCons) {
94
+ if (!doCons. IsDoConcurrent ()) {
95
95
return ;
96
96
}
97
97
const auto &beginLoopDirective = std::get<D>(x.t );
@@ -109,73 +109,36 @@ class CanonicalizationOfAcc {
109
109
110
110
void RewriteOpenACCLoopConstruct (parser::OpenACCLoopConstruct &x,
111
111
parser::Block &block, parser::Block::iterator it) {
112
- // Check the sequence of DoConstruct in the same iteration
113
- //
114
- // Original:
115
- // ExecutableConstruct -> OpenACCConstruct -> OpenACCLoopConstruct
116
- // ACCBeginLoopDirective
117
- // ExecutableConstruct -> DoConstruct
118
- //
119
- // After rewriting:
120
- // ExecutableConstruct -> OpenACCConstruct -> OpenACCLoopConstruct
121
- // AccBeginLoopDirective
122
- // DoConstruct
123
- parser::Block::iterator nextIt;
124
112
auto &beginDir{std::get<parser::AccBeginLoopDirective>(x.t )};
125
113
auto &dir{std::get<parser::AccLoopDirective>(beginDir.t )};
114
+ const auto &doCons{std::get<parser::DoConstruct>(x.t )};
126
115
127
- nextIt = it;
128
- if (++nextIt != block.end ()) {
129
- if (auto *doCons{parser::Unwrap<parser::DoConstruct>(*nextIt)}) {
130
- if (!doCons->GetLoopControl ()) {
131
- messages_.Say (dir.source ,
132
- " DO loop after the %s directive must have loop control" _err_en_US,
133
- parser::ToUpperCaseLetters (dir.source .ToString ()));
134
- return ;
135
- }
136
-
137
- // move DoConstruct
138
- std::get<std::optional<parser::DoConstruct>>(x.t ) = std::move (*doCons);
139
- nextIt = block.erase (nextIt);
140
-
141
- CheckDoConcurrentClauseRestriction<parser::OpenACCLoopConstruct,
142
- parser::AccBeginLoopDirective>(x);
143
- CheckTileClauseRestriction<parser::OpenACCLoopConstruct,
144
- parser::AccBeginLoopDirective>(x);
145
-
146
- return ; // found do-loop
147
- }
116
+ if (!doCons.GetLoopControl ()) {
117
+ messages_.Say (dir.source ,
118
+ " DO loop after the %s directive must have loop control" _err_en_US,
119
+ parser::ToUpperCaseLetters (dir.source .ToString ()));
120
+ return ;
148
121
}
149
- messages_.Say (dir.source ,
150
- " A DO loop must follow the %s directive" _err_en_US,
151
- parser::ToUpperCaseLetters (dir.source .ToString ()));
122
+
123
+ CheckDoConcurrentClauseRestriction<parser::OpenACCLoopConstruct,
124
+ parser::AccBeginLoopDirective>(x, doCons);
125
+ CheckTileClauseRestriction<parser::OpenACCLoopConstruct,
126
+ parser::AccBeginLoopDirective>(x, doCons);
152
127
}
153
128
154
129
void RewriteOpenACCCombinedConstruct (parser::OpenACCCombinedConstruct &x,
155
130
parser::Block &block, parser::Block::iterator it) {
156
- // Check the sequence of DoConstruct in the same iteration
157
- //
158
- // Original:
159
- // ExecutableConstruct -> OpenACCConstruct -> OpenACCCombinedConstruct
160
- // ACCBeginCombinedDirective
161
- // ExecutableConstruct -> DoConstruct
162
- // ExecutableConstruct -> AccEndCombinedDirective (if available)
163
- //
164
- // After rewriting:
165
- // ExecutableConstruct -> OpenACCConstruct -> OpenACCCombinedConstruct
166
- // ACCBeginCombinedDirective
167
- // DoConstruct
168
- // AccEndCombinedDirective (if available)
131
+ // Check the sequence of DoConstruct in the same iteration.
169
132
parser::Block::iterator nextIt;
170
133
auto &beginDir{std::get<parser::AccBeginCombinedDirective>(x.t )};
171
134
auto &dir{std::get<parser::AccCombinedDirective>(beginDir.t )};
172
- auto &doConstruct{std::get<std::optional<parser::DoConstruct>>(x.t )};
135
+ const auto &doConstruct{std::get<std::optional<parser::DoConstruct>>(x.t )};
173
136
174
137
if (doConstruct) {
175
138
CheckDoConcurrentClauseRestriction<parser::OpenACCCombinedConstruct,
176
- parser::AccBeginCombinedDirective>(x);
139
+ parser::AccBeginCombinedDirective>(x, *doConstruct );
177
140
CheckTileClauseRestriction<parser::OpenACCCombinedConstruct,
178
- parser::AccBeginCombinedDirective>(x);
141
+ parser::AccBeginCombinedDirective>(x, *doConstruct );
179
142
if (!doConstruct->GetLoopControl ()) {
180
143
messages_.Say (dir.source ,
181
144
" DO loop after the %s directive must have loop control" _err_en_US,
0 commit comments