Skip to content

[flang][OpenMP] Parsing support for iterator in DEPEND clause #113622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3566,7 +3566,9 @@ struct OmpDependClause {
WRAPPER_CLASS(Sink, std::list<OmpDependSinkVec>);
struct InOut {
TUPLE_CLASS_BOILERPLATE(InOut);
std::tuple<OmpTaskDependenceType, OmpObjectList> t;
std::tuple<std::optional<OmpIteratorModifier>, OmpTaskDependenceType,
OmpObjectList>
t;
};
std::variant<Source, Sink, InOut> u;
};
Expand Down
64 changes: 36 additions & 28 deletions flang/lib/Lower/OpenMP/ClauseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,35 +795,43 @@ bool ClauseProcessor::processCopyprivate(
bool ClauseProcessor::processDepend(mlir::omp::DependClauseOps &result) const {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();

return findRepeatableClause<omp::clause::Depend>(
[&](const omp::clause::Depend &clause, const parser::CharBlock &) {
using Depend = omp::clause::Depend;
assert(std::holds_alternative<Depend::DepType>(clause.u) &&
"Only the form with dependence type is handled at the moment");
auto &depType = std::get<Depend::DepType>(clause.u);
auto kind = std::get<Depend::TaskDependenceType>(depType.t);
auto &objects = std::get<omp::ObjectList>(depType.t);

mlir::omp::ClauseTaskDependAttr dependTypeOperand =
genDependKindAttr(firOpBuilder, kind);
result.dependKinds.append(objects.size(), dependTypeOperand);

for (const omp::Object &object : objects) {
assert(object.ref() && "Expecting designator");

if (evaluate::ExtractSubstring(*object.ref())) {
TODO(converter.getCurrentLocation(),
"substring not supported for task depend");
} else if (evaluate::IsArrayElement(*object.ref())) {
TODO(converter.getCurrentLocation(),
"array sections not supported for task depend");
}
auto process = [&](const omp::clause::Depend &clause,
const parser::CharBlock &) {
using Depend = omp::clause::Depend;
if (!std::holds_alternative<Depend::DepType>(clause.u)) {
TODO(converter.getCurrentLocation(),
"DEPEND clause with SINK or SOURCE is not supported yet");
}
auto &depType = std::get<Depend::DepType>(clause.u);
auto kind = std::get<Depend::TaskDependenceType>(depType.t);
auto &objects = std::get<omp::ObjectList>(depType.t);

semantics::Symbol *sym = object.sym();
const mlir::Value variable = converter.getSymbolAddress(*sym);
result.dependVars.push_back(variable);
}
});
if (std::get<std::optional<omp::clause::Iterator>>(depType.t)) {
TODO(converter.getCurrentLocation(),
"Support for iterator modifiers is not implemented yet");
}
mlir::omp::ClauseTaskDependAttr dependTypeOperand =
genDependKindAttr(firOpBuilder, kind);
result.dependKinds.append(objects.size(), dependTypeOperand);

for (const omp::Object &object : objects) {
assert(object.ref() && "Expecting designator");

if (evaluate::ExtractSubstring(*object.ref())) {
TODO(converter.getCurrentLocation(),
"substring not supported for task depend");
} else if (evaluate::IsArrayElement(*object.ref())) {
TODO(converter.getCurrentLocation(),
"array sections not supported for task depend");
}

semantics::Symbol *sym = object.sym();
const mlir::Value variable = converter.getSymbolAddress(*sym);
result.dependVars.push_back(variable);
}
};

return findRepeatableClause<omp::clause::Depend>(process);
}

bool ClauseProcessor::processHasDeviceAddr(
Expand Down
15 changes: 10 additions & 5 deletions flang/lib/Lower/OpenMP/Clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,16 @@ Depend make(const parser::OmpClause::Depend &inp,
},
// Depend::DepType
[&](const wrapped::InOut &s) -> Variant {
auto &t0 = std::get<parser::OmpTaskDependenceType>(s.t);
auto &t1 = std::get<parser::OmpObjectList>(s.t);
return Depend::DepType{{/*TaskDependenceType=*/convert1(t0.v),
/*Iterator=*/std::nullopt,
/*LocatorList=*/makeObjects(t1, semaCtx)}};
auto &t0 =
std::get<std::optional<parser::OmpIteratorModifier>>(s.t);
auto &t1 = std::get<parser::OmpTaskDependenceType>(s.t);
auto &t2 = std::get<parser::OmpObjectList>(s.t);

auto &&maybeIter = maybeApply(
[&](auto &&s) { return makeIterator(s, semaCtx); }, t0);
return Depend::DepType{{/*TaskDependenceType=*/convert1(t1.v),
/*Iterator=*/std::move(maybeIter),
/*LocatorList=*/makeObjects(t2, semaCtx)}};
},
},
inp.v.u)};
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ TYPE_CONTEXT_PARSER("Omp Depend clause"_en_US,
construct<OmpDependClause>(
construct<OmpDependClause::Source>("SOURCE"_tok)) ||
construct<OmpDependClause>(construct<OmpDependClause::InOut>(
Parser<OmpTaskDependenceType>{}, ":" >> Parser<OmpObjectList>{})))
maybe(Parser<OmpIteratorModifier>{} / ","_tok),
Parser<OmpTaskDependenceType>{} / ":", Parser<OmpObjectList>{})))

// 2.15.3.7 LINEAR (linear-list: linear-step)
// linear-list -> list | modifier(list)
Expand Down
9 changes: 9 additions & 0 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,15 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Depend &x) {
}
}
}
if (std::get<std::optional<parser::OmpIteratorModifier>>(inOut->t)) {
unsigned version{context_.langOptions().OpenMPVersion};
unsigned allowedInVersion{50};
if (version < allowedInVersion) {
context_.Say(GetContext().clauseSource,
"Iterator modifiers are not supported in %s, %s"_warn_en_US,
ThisVersion(version), TryVersion(allowedInVersion));
}
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions flang/test/Lower/OpenMP/Todo/depend-clause.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
!RUN: %not_todo_cmd bbc -emit-hlfir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 -o - %s 2>&1 | FileCheck %s

!CHECK: Support for iterator modifiers is not implemented yet
subroutine f00(x)
integer :: x(10)
!$omp task depend(iterator(i = 1:10), in: x(i))
x = 0
!$omp end task
end
9 changes: 9 additions & 0 deletions flang/test/Semantics/OpenMP/depend05.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=45 -Werror

subroutine f00(x)
integer :: x(10)
!WARNING: Iterator modifiers are not supported in OpenMP v4.5, try -fopenmp-version=50
!$omp task depend(iterator(i = 1:10), in: x(i))
x = 0
!$omp end task
end