Skip to content

Commit fec9503

Browse files
committed
Respond to Review Comments & fix failing test
1 parent bf0d3c6 commit fec9503

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

flang/include/flang/Parser/parse-tree.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ struct AccEndCombinedDirective;
267267
struct OpenACCDeclarativeConstruct;
268268
struct OpenACCRoutineConstruct;
269269
struct OpenMPConstruct;
270+
struct OpenMPLoopConstruct;
270271
struct OpenMPDeclarativeConstruct;
271272
struct OmpEndLoopDirective;
272273
struct OmpMemoryOrderClause;
@@ -5021,13 +5022,13 @@ struct OpenMPBlockConstruct {
50215022
};
50225023

50235024
// OpenMP directives enclosing do loop
5025+
using NestedConstruct =
5026+
std::variant<DoConstruct, common::Indirection<OpenMPLoopConstruct>>;
50245027
struct OpenMPLoopConstruct {
50255028
TUPLE_CLASS_BOILERPLATE(OpenMPLoopConstruct);
50265029
OpenMPLoopConstruct(OmpBeginLoopDirective &&a)
50275030
: t({std::move(a), std::nullopt, std::nullopt}) {}
5028-
std::tuple<OmpBeginLoopDirective,
5029-
std::optional<
5030-
std::variant<DoConstruct, common::Indirection<OpenMPLoopConstruct>>>,
5031+
std::tuple<OmpBeginLoopDirective, std::optional<NestedConstruct>,
50315032
std::optional<OmpEndLoopDirective>>
50325033
t;
50335034
};

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4231,7 +4231,8 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
42314231
mlir::Location currentLocation =
42324232
converter.genLocation(beginLoopDirective.source);
42334233

4234-
auto &optLoopCons = std::get<1>(loopConstruct.t);
4234+
auto &optLoopCons =
4235+
std::get<std::optional<parser::NestedConstruct>>(loopConstruct.t);
42354236
if (optLoopCons.has_value())
42364237
if (auto *ompNestedLoopCons{
42374238
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(

flang/lib/Semantics/canonicalize-omp.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ class CanonicalizationOfOmp {
166166
std::get<parser::OmpBeginLoopDirective>(ompLoopCons->t);
167167
auto &beginLoopDirective =
168168
std::get<parser::OmpLoopDirective>(beginDirective.t);
169-
if ((beginLoopDirective.v == llvm::omp::Directive::OMPD_unroll ||
170-
beginLoopDirective.v == llvm::omp::Directive::OMPD_tile)) {
169+
if (beginLoopDirective.v == llvm::omp::Directive::OMPD_unroll ||
170+
beginLoopDirective.v == llvm::omp::Directive::OMPD_tile) {
171171
// iterate through the remaining block items to find the end directive
172172
// for the unroll/tile directive.
173173
parser::Block::iterator endIt;
@@ -188,18 +188,15 @@ class CanonicalizationOfOmp {
188188
}
189189
RewriteOpenMPLoopConstruct(*ompLoopCons, block, nextIt);
190190
auto &ompLoop =
191-
std::get<std::optional<std::variant<parser::DoConstruct,
192-
common::Indirection<parser::OpenMPLoopConstruct>>>>(x.t);
193-
ompLoop = std::optional<std::variant<parser::DoConstruct,
194-
common::Indirection<parser::OpenMPLoopConstruct>>>{
195-
std::variant<parser::DoConstruct,
196-
common::Indirection<parser::OpenMPLoopConstruct>>{
191+
std::get<std::optional<parser::NestedConstruct>>(x.t);
192+
ompLoop = std::optional<parser::NestedConstruct>{
193+
parser::NestedConstruct{
197194
common::Indirection{std::move(*ompLoopCons)}}};
198195
nextIt = block.erase(nextIt);
199196
} else {
200-
messages_.Say(dir.source,
201-
"Only OpenMP Loop Transformation Constructs can be nested within OpenMPLoopConstruct's"_err_en_US,
202-
parser::ToUpperCaseLetters(dir.source.ToString()));
197+
messages_.Say(beginLoopDirective.source,
198+
"Only Loop Transformation Constructs or Loop Nests can be nested within Loop Constructs"_err_en_US,
199+
parser::ToUpperCaseLetters(beginLoopDirective.source.ToString()));
203200
}
204201
} else {
205202
missingDoConstruct(dir);

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
762762
}
763763
SetLoopInfo(x);
764764

765-
auto &optLoopCons = std::get<1>(x.t);
765+
auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t);
766766
if (optLoopCons.has_value()) {
767767
if (const auto &doConstruct{
768768
std::get_if<parser::DoConstruct>(&*optLoopCons)}) {
@@ -789,7 +789,7 @@ const parser::Name OmpStructureChecker::GetLoopIndex(
789789
return std::get<Bounds>(x->GetLoopControl()->u).name.thing;
790790
}
791791
void OmpStructureChecker::SetLoopInfo(const parser::OpenMPLoopConstruct &x) {
792-
auto &optLoopCons = std::get<1>(x.t);
792+
auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t);
793793
if (optLoopCons.has_value()) {
794794
if (const auto &loopConstruct{
795795
std::get_if<parser::DoConstruct>(&*optLoopCons)}) {
@@ -863,7 +863,7 @@ void OmpStructureChecker::CheckIteratorModifier(const parser::OmpIterator &x) {
863863

864864
void OmpStructureChecker::CheckLoopItrVariableIsInt(
865865
const parser::OpenMPLoopConstruct &x) {
866-
auto &optLoopCons = std::get<1>(x.t);
866+
auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t);
867867
if (optLoopCons.has_value()) {
868868
if (const auto &loopConstruct{
869869
std::get_if<parser::DoConstruct>(&*optLoopCons)}) {
@@ -1086,7 +1086,7 @@ void OmpStructureChecker::CheckDistLinear(
10861086

10871087
// Match the loop index variables with the collected symbols from linear
10881088
// clauses.
1089-
auto &optLoopCons = std::get<1>(x.t);
1089+
auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t);
10901090
if (optLoopCons.has_value()) {
10911091
if (const auto &loopConstruct{
10921092
std::get_if<parser::DoConstruct>(&*optLoopCons)}) {

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
17961796
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));
17971797

17981798
if (beginDir.v == llvm::omp::Directive::OMPD_do) {
1799-
auto &optLoopCons = std::get<1>(x.t);
1799+
auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t);
18001800
if (optLoopCons.has_value()) {
18011801
if (const auto &doConstruct{
18021802
std::get_if<parser::DoConstruct>(&*optLoopCons)}) {
@@ -1965,7 +1965,7 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
19651965
bool hasCollapseClause{
19661966
clause ? (clause->Id() == llvm::omp::OMPC_collapse) : false};
19671967

1968-
auto &optLoopCons = std::get<1>(x.t);
1968+
auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t);
19691969
if (optLoopCons.has_value()) {
19701970
if (const auto &outer{std::get_if<parser::DoConstruct>(&*optLoopCons)}) {
19711971
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0;

flang/test/Semantics/OpenMP/loop-transformation-construct01.f90

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,23 @@ subroutine loop_transformation_construct2
3434
integer :: v(i)
3535

3636
!$omp do
37-
!ERROR: Only OpenMP Loop Transformation Constructs can be nested within OpenMPLoopConstruct's
37+
!ERROR: Only Loop Transformation Constructs or Loop Nests can be nested within Loop Constructs
3838
!$omp parallel do
3939
do x = 1, i
4040
v(x) = x(x) * 2
4141
end do
42-
!! This error occurs because the `parallel do` end directive never gets matched.
43-
!ERROR: The END PARALLEL DO directive must follow the DO loop associated with the loop construct
44-
!$omp end parallel do
45-
!$omp end do
42+
end subroutine
43+
44+
subroutine loop_transformation_construct3
45+
implicit none
46+
integer :: i = 5
47+
integer :: y
48+
integer :: v(i)
49+
50+
!$omp do
51+
do x = 1, i
52+
v(x) = x(x) * 2
53+
end do
54+
!ERROR: A DO loop must follow the TILE directive
55+
!$omp tile
4656
end subroutine

0 commit comments

Comments
 (0)