Skip to content

Commit d48c849

Browse files
authored
[flang][OpenMP] Parsing support for iterator in DEPEND clause (#113622)
Warn about use of iterators OpenMP versions that didn't have them (support added in 5.0). Emit a TODO error in lowering.
1 parent 8239ea3 commit d48c849

File tree

7 files changed

+79
-35
lines changed

7 files changed

+79
-35
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3566,7 +3566,9 @@ struct OmpDependClause {
35663566
WRAPPER_CLASS(Sink, std::list<OmpDependSinkVec>);
35673567
struct InOut {
35683568
TUPLE_CLASS_BOILERPLATE(InOut);
3569-
std::tuple<OmpTaskDependenceType, OmpObjectList> t;
3569+
std::tuple<std::optional<OmpIteratorModifier>, OmpTaskDependenceType,
3570+
OmpObjectList>
3571+
t;
35703572
};
35713573
std::variant<Source, Sink, InOut> u;
35723574
};

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -795,35 +795,43 @@ bool ClauseProcessor::processCopyprivate(
795795
bool ClauseProcessor::processDepend(mlir::omp::DependClauseOps &result) const {
796796
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
797797

798-
return findRepeatableClause<omp::clause::Depend>(
799-
[&](const omp::clause::Depend &clause, const parser::CharBlock &) {
800-
using Depend = omp::clause::Depend;
801-
assert(std::holds_alternative<Depend::DepType>(clause.u) &&
802-
"Only the form with dependence type is handled at the moment");
803-
auto &depType = std::get<Depend::DepType>(clause.u);
804-
auto kind = std::get<Depend::TaskDependenceType>(depType.t);
805-
auto &objects = std::get<omp::ObjectList>(depType.t);
806-
807-
mlir::omp::ClauseTaskDependAttr dependTypeOperand =
808-
genDependKindAttr(firOpBuilder, kind);
809-
result.dependKinds.append(objects.size(), dependTypeOperand);
810-
811-
for (const omp::Object &object : objects) {
812-
assert(object.ref() && "Expecting designator");
813-
814-
if (evaluate::ExtractSubstring(*object.ref())) {
815-
TODO(converter.getCurrentLocation(),
816-
"substring not supported for task depend");
817-
} else if (evaluate::IsArrayElement(*object.ref())) {
818-
TODO(converter.getCurrentLocation(),
819-
"array sections not supported for task depend");
820-
}
798+
auto process = [&](const omp::clause::Depend &clause,
799+
const parser::CharBlock &) {
800+
using Depend = omp::clause::Depend;
801+
if (!std::holds_alternative<Depend::DepType>(clause.u)) {
802+
TODO(converter.getCurrentLocation(),
803+
"DEPEND clause with SINK or SOURCE is not supported yet");
804+
}
805+
auto &depType = std::get<Depend::DepType>(clause.u);
806+
auto kind = std::get<Depend::TaskDependenceType>(depType.t);
807+
auto &objects = std::get<omp::ObjectList>(depType.t);
821808

822-
semantics::Symbol *sym = object.sym();
823-
const mlir::Value variable = converter.getSymbolAddress(*sym);
824-
result.dependVars.push_back(variable);
825-
}
826-
});
809+
if (std::get<std::optional<omp::clause::Iterator>>(depType.t)) {
810+
TODO(converter.getCurrentLocation(),
811+
"Support for iterator modifiers is not implemented yet");
812+
}
813+
mlir::omp::ClauseTaskDependAttr dependTypeOperand =
814+
genDependKindAttr(firOpBuilder, kind);
815+
result.dependKinds.append(objects.size(), dependTypeOperand);
816+
817+
for (const omp::Object &object : objects) {
818+
assert(object.ref() && "Expecting designator");
819+
820+
if (evaluate::ExtractSubstring(*object.ref())) {
821+
TODO(converter.getCurrentLocation(),
822+
"substring not supported for task depend");
823+
} else if (evaluate::IsArrayElement(*object.ref())) {
824+
TODO(converter.getCurrentLocation(),
825+
"array sections not supported for task depend");
826+
}
827+
828+
semantics::Symbol *sym = object.sym();
829+
const mlir::Value variable = converter.getSymbolAddress(*sym);
830+
result.dependVars.push_back(variable);
831+
}
832+
};
833+
834+
return findRepeatableClause<omp::clause::Depend>(process);
827835
}
828836

829837
bool ClauseProcessor::processHasDeviceAddr(

flang/lib/Lower/OpenMP/Clauses.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,16 @@ Depend make(const parser::OmpClause::Depend &inp,
595595
},
596596
// Depend::DepType
597597
[&](const wrapped::InOut &s) -> Variant {
598-
auto &t0 = std::get<parser::OmpTaskDependenceType>(s.t);
599-
auto &t1 = std::get<parser::OmpObjectList>(s.t);
600-
return Depend::DepType{{/*TaskDependenceType=*/convert1(t0.v),
601-
/*Iterator=*/std::nullopt,
602-
/*LocatorList=*/makeObjects(t1, semaCtx)}};
598+
auto &t0 =
599+
std::get<std::optional<parser::OmpIteratorModifier>>(s.t);
600+
auto &t1 = std::get<parser::OmpTaskDependenceType>(s.t);
601+
auto &t2 = std::get<parser::OmpObjectList>(s.t);
602+
603+
auto &&maybeIter = maybeApply(
604+
[&](auto &&s) { return makeIterator(s, semaCtx); }, t0);
605+
return Depend::DepType{{/*TaskDependenceType=*/convert1(t1.v),
606+
/*Iterator=*/std::move(maybeIter),
607+
/*LocatorList=*/makeObjects(t2, semaCtx)}};
603608
},
604609
},
605610
inp.v.u)};

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ TYPE_CONTEXT_PARSER("Omp Depend clause"_en_US,
376376
construct<OmpDependClause>(
377377
construct<OmpDependClause::Source>("SOURCE"_tok)) ||
378378
construct<OmpDependClause>(construct<OmpDependClause::InOut>(
379-
Parser<OmpTaskDependenceType>{}, ":" >> Parser<OmpObjectList>{})))
379+
maybe(Parser<OmpIteratorModifier>{} / ","_tok),
380+
Parser<OmpTaskDependenceType>{} / ":", Parser<OmpObjectList>{})))
380381

381382
// 2.15.3.7 LINEAR (linear-list: linear-step)
382383
// linear-list -> list | modifier(list)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3312,6 +3312,15 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Depend &x) {
33123312
}
33133313
}
33143314
}
3315+
if (std::get<std::optional<parser::OmpIteratorModifier>>(inOut->t)) {
3316+
unsigned version{context_.langOptions().OpenMPVersion};
3317+
unsigned allowedInVersion{50};
3318+
if (version < allowedInVersion) {
3319+
context_.Say(GetContext().clauseSource,
3320+
"Iterator modifiers are not supported in %s, %s"_warn_en_US,
3321+
ThisVersion(version), TryVersion(allowedInVersion));
3322+
}
3323+
}
33153324
}
33163325
}
33173326

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
!RUN: %not_todo_cmd bbc -emit-hlfir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s
2+
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s
3+
4+
!CHECK: Support for iterator modifiers is not implemented yet
5+
subroutine f00(x)
6+
integer :: x(10)
7+
!$omp task depend(iterator(i = 1:10), in: x(i))
8+
x = 0
9+
!$omp end task
10+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=45 -Werror
2+
3+
subroutine f00(x)
4+
integer :: x(10)
5+
!WARNING: Iterator modifiers are not supported in OpenMP v4.5, try -fopenmp-version=50
6+
!$omp task depend(iterator(i = 1:10), in: x(i))
7+
x = 0
8+
!$omp end task
9+
end

0 commit comments

Comments
 (0)