Skip to content

Commit d942339

Browse files
committed
Revert "[flang][openacc] Check trip count invariance with other IVs (#79906)"
This reverts commit 0fa4463. Breaks buildbot https://lab.llvm.org/buildbot/#/builders/268/builds/7155
1 parent 0fa4463 commit d942339

File tree

2 files changed

+8
-83
lines changed

2 files changed

+8
-83
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "resolve-names-utils.h"
1414
#include "flang/Common/idioms.h"
1515
#include "flang/Evaluate/fold.h"
16-
#include "flang/Evaluate/tools.h"
1716
#include "flang/Evaluate/type.h"
1817
#include "flang/Parser/parse-tree-visitor.h"
1918
#include "flang/Parser/parse-tree.h"
@@ -267,7 +266,7 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
267266
Symbol::Flag::AccDevicePtr, Symbol::Flag::AccDeviceResident,
268267
Symbol::Flag::AccLink, Symbol::Flag::AccPresent};
269268

270-
void CheckAssociatedLoop(const parser::DoConstruct &);
269+
void CheckAssociatedLoopIndex(const parser::OpenACCLoopConstruct &);
271270
void ResolveAccObjectList(const parser::AccObjectList &, Symbol::Flag);
272271
void ResolveAccObject(const parser::AccObject &, Symbol::Flag);
273272
Symbol *ResolveAcc(const parser::Name &, Symbol::Flag, Scope &);
@@ -883,8 +882,7 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCLoopConstruct &x) {
883882
}
884883
ClearDataSharingAttributeObjects();
885884
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));
886-
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t)};
887-
CheckAssociatedLoop(*outer);
885+
CheckAssociatedLoopIndex(x);
888886
return true;
889887
}
890888

@@ -1089,10 +1087,6 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCCombinedConstruct &x) {
10891087
default:
10901088
break;
10911089
}
1092-
const auto &clauseList{std::get<parser::AccClauseList>(beginBlockDir.t)};
1093-
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));
1094-
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t)};
1095-
CheckAssociatedLoop(*outer);
10961090
ClearDataSharingAttributeObjects();
10971091
return true;
10981092
}
@@ -1224,8 +1218,8 @@ std::int64_t AccAttributeVisitor::GetAssociatedLoopLevelFromClauses(
12241218
return 1; // default is outermost loop
12251219
}
12261220

1227-
void AccAttributeVisitor::CheckAssociatedLoop(
1228-
const parser::DoConstruct &outerDoConstruct) {
1221+
void AccAttributeVisitor::CheckAssociatedLoopIndex(
1222+
const parser::OpenACCLoopConstruct &x) {
12291223
std::int64_t level{GetContext().associatedLoopLevel};
12301224
if (level <= 0) { // collapse value was negative or 0
12311225
return;
@@ -1256,41 +1250,10 @@ void AccAttributeVisitor::CheckAssociatedLoop(
12561250
return nullptr;
12571251
};
12581252

1259-
auto checkExprHasSymbols = [&](llvm::SmallVector<Symbol *> &ivs,
1260-
semantics::UnorderedSymbolSet &symbols) {
1261-
for (auto iv : ivs) {
1262-
if (symbols.count(*iv) != 0) {
1263-
context_.Say(GetContext().directiveSource,
1264-
"Trip count must be computable and invariant"_err_en_US);
1265-
}
1266-
}
1267-
};
1268-
1269-
Symbol::Flag flag;
1270-
llvm::SmallVector<Symbol *> ivs;
1271-
using Bounds = parser::LoopControl::Bounds;
1272-
for (const parser::DoConstruct *loop{&outerDoConstruct}; loop && level > 0;) {
1253+
const auto &outer{std::get<std::optional<parser::DoConstruct>>(x.t)};
1254+
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0;) {
12731255
// Go through all nested loops to ensure index variable exists.
1274-
if (const parser::Name * ivName{GetLoopIndex(*loop)}) {
1275-
if (auto *symbol{ResolveAcc(*ivName, flag, currScope())}) {
1276-
if (auto &control{loop->GetLoopControl()}) {
1277-
if (const Bounds * b{std::get_if<Bounds>(&control->u)}) {
1278-
if (auto lowerExpr{semantics::AnalyzeExpr(context_, b->lower)}) {
1279-
semantics::UnorderedSymbolSet lowerSyms =
1280-
evaluate::CollectSymbols(*lowerExpr);
1281-
checkExprHasSymbols(ivs, lowerSyms);
1282-
}
1283-
if (auto upperExpr{semantics::AnalyzeExpr(context_, b->upper)}) {
1284-
semantics::UnorderedSymbolSet upperSyms =
1285-
evaluate::CollectSymbols(*upperExpr);
1286-
checkExprHasSymbols(ivs, upperSyms);
1287-
}
1288-
}
1289-
}
1290-
ivs.push_back(symbol);
1291-
}
1292-
}
1293-
1256+
GetLoopIndex(*loop);
12941257
const auto &block{std::get<parser::Block>(loop->t)};
12951258
--level;
12961259
loop = getNextDoConstruct(block, level);

flang/test/Semantics/OpenACC/acc-loop.f90

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ program openacc_loop_validity
1010
type atype
1111
real(8), dimension(10) :: arr
1212
real(8) :: s
13-
integer :: n
1413
end type atype
1514

16-
integer :: i, j, k, b, gang_size, vector_size, worker_size
15+
integer :: i, j, b, gang_size, vector_size, worker_size
1716
integer, parameter :: N = 256
1817
integer, dimension(N) :: c
1918
logical, dimension(N) :: d, e
@@ -318,41 +317,4 @@ program openacc_loop_validity
318317
END DO
319318
END DO
320319

321-
!ERROR: Trip count must be computable and invariant
322-
!$acc loop collapse(2)
323-
DO i = 1, n
324-
DO j = 1, c(i)
325-
END DO
326-
END DO
327-
328-
!ERROR: Trip count must be computable and invariant
329-
!$acc loop collapse(2)
330-
DO i = 1, n
331-
DO j = 1, i
332-
END DO
333-
END DO
334-
335-
!ERROR: Trip count must be computable and invariant
336-
!$acc loop collapse(2)
337-
DO i = 1, n
338-
DO j = 1, ta(i)%n
339-
END DO
340-
END DO
341-
342-
!ERROR: Trip count must be computable and invariant
343-
!$acc parallel loop collapse(2)
344-
DO i = 1, n
345-
DO j = 1, ta(i)%n
346-
END DO
347-
END DO
348-
349-
!ERROR: Trip count must be computable and invariant
350-
!$acc loop collapse(3)
351-
DO i = 1, n
352-
DO j = 1, n
353-
DO k = 1, i
354-
END DO
355-
END DO
356-
END DO
357-
358320
end program openacc_loop_validity

0 commit comments

Comments
 (0)