Skip to content

[flang][OpenMP] Semantic checks for DOACROSS clause #115397

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 10 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
14 changes: 9 additions & 5 deletions flang/examples/FeatureList/FeatureList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,17 @@ struct NodeVisitor {
READ_FEATURE(OmpDefaultmapClause::ImplicitBehavior)
READ_FEATURE(OmpDefaultmapClause::VariableCategory)
READ_FEATURE(OmpDependClause)
READ_FEATURE(OmpDependClause::InOut)
READ_FEATURE(OmpDependClause::Sink)
READ_FEATURE(OmpDependClause::Source)
READ_FEATURE(OmpDependClause::TaskDep)
READ_FEATURE(OmpDoacross::Sink)
READ_FEATURE(OmpDoacross::Source)
READ_FEATURE(OmpDoacrossClause)
READ_FEATURE(OmpDependenceType)
READ_FEATURE(OmpDependenceType::Type)
READ_FEATURE(OmpTaskDependenceType)
READ_FEATURE(OmpTaskDependenceType::Type)
READ_FEATURE(OmpDependSinkVec)
READ_FEATURE(OmpDependSinkVecLength)
READ_FEATURE(OmpIteration)
READ_FEATURE(OmpIterationOffset)
READ_FEATURE(OmpIterationVector)
READ_FEATURE(OmpEndAllocators)
READ_FEATURE(OmpEndAtomic)
READ_FEATURE(OmpEndBlockDirective)
Expand Down
19 changes: 12 additions & 7 deletions flang/include/flang/Parser/dump-parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,20 @@ class ParseTreeDumper {
NODE(parser, OmpDefaultmapClause)
NODE_ENUM(OmpDefaultmapClause, ImplicitBehavior)
NODE_ENUM(OmpDefaultmapClause, VariableCategory)
NODE(parser, OmpDependClause)
NODE(parser, OmpDetachClause)
NODE(OmpDependClause, InOut)
NODE(OmpDependClause, Sink)
NODE(OmpDependClause, Source)
NODE(parser, OmpDependenceType)
NODE_ENUM(OmpDependenceType, Type)
NODE(parser, OmpTaskDependenceType)
NODE_ENUM(OmpTaskDependenceType, Type)
NODE(parser, OmpDependSinkVec)
NODE(parser, OmpDependSinkVecLength)
NODE(parser, OmpIterationOffset)
NODE(parser, OmpIteration)
NODE(parser, OmpIterationVector)
NODE(parser, OmpDoacross)
NODE(OmpDoacross, Sink)
NODE(OmpDoacross, Source)
NODE(parser, OmpDependClause)
NODE(OmpDependClause, TaskDep)
NODE(parser, OmpDetachClause)
NODE(parser, OmpDoacrossClause)
NODE(parser, OmpDestroyClause)
NODE(parser, OmpEndAllocators)
NODE(parser, OmpEndAtomic)
Expand Down
79 changes: 58 additions & 21 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3439,16 +3439,35 @@ struct OmpObject {

WRAPPER_CLASS(OmpObjectList, std::list<OmpObject>);

// Ref: [4.5:169-170], [5.0:255-256], [5.1:288-289]
//
// dependence-type ->
// SINK | SOURCE | // since 4.5
// IN | OUT | INOUT | // since 4.5, until 5.1
// MUTEXINOUTSET | DEPOBJ | // since 5.0, until 5.1
// INOUTSET // since 5.1, until 5.1
//
// All of these, except SINK and SOURCE became task-dependence-type in 5.2.
//
// Keeping these two as separate types, since having them all together
// creates conflicts when parsing the DEPEND clause. For DEPEND(SINK: ...),
// the SINK may be parsed as 'task-dependence-type', and the list after
// the ':' would then be parsed as OmpObjectList (instead of the iteration
// vector). This would accept the vector "i, j, k" (although interpreted
// incorrectly), while flagging a syntax error for "i+1, j, k".
struct OmpDependenceType {
ENUM_CLASS(Type, Sink, Source);
WRAPPER_CLASS_BOILERPLATE(OmpDependenceType, Type);
};

// Ref: [4.5:169-170], [5.0:254-256], [5.1:287-289], [5.2:321]
//
// task-dependence-type -> // "dependence-type" in 5.1 and before
// IN | OUT | INOUT | // since 4.5
// SOURCE | SINK | // since 4.5, until 5.1
// MUTEXINOUTSET | DEPOBJ | // since 5.0
// INOUTSET // since 5.2
struct OmpTaskDependenceType {
ENUM_CLASS(
Type, In, Out, Inout, Inoutset, Mutexinoutset, Source, Sink, Depobj)
ENUM_CLASS(Type, In, Out, Inout, Inoutset, Mutexinoutset, Depobj)
WRAPPER_CLASS_BOILERPLATE(OmpTaskDependenceType, Type);
};

Expand Down Expand Up @@ -3528,41 +3547,55 @@ struct OmpDefaultmapClause {
std::tuple<ImplicitBehavior, std::optional<VariableCategory>> t;
};

// 2.13.9 depend-vec-length -> +/- non-negative-constant
struct OmpDependSinkVecLength {
TUPLE_CLASS_BOILERPLATE(OmpDependSinkVecLength);
// 2.13.9 iteration-offset -> +/- non-negative-constant
struct OmpIterationOffset {
TUPLE_CLASS_BOILERPLATE(OmpIterationOffset);
std::tuple<DefinedOperator, ScalarIntConstantExpr> t;
};

// 2.13.9 depend-vec -> induction-variable [depend-vec-length], ...
struct OmpDependSinkVec {
TUPLE_CLASS_BOILERPLATE(OmpDependSinkVec);
std::tuple<Name, std::optional<OmpDependSinkVecLength>> t;
// 2.13.9 iteration -> induction-variable [iteration-offset]
struct OmpIteration {
TUPLE_CLASS_BOILERPLATE(OmpIteration);
std::tuple<Name, std::optional<OmpIterationOffset>> t;
};

WRAPPER_CLASS(OmpIterationVector, std::list<OmpIteration>);

// Extract this into a separate structure (instead of having it directly in
// OmpDoacrossClause), so that the context in TYPE_CONTEXT_PARSER can be set
// separately for OmpDependClause and OmpDoacrossClause.
struct OmpDoacross {
OmpDependenceType::Type GetDepType() const;

WRAPPER_CLASS(Sink, OmpIterationVector);
EMPTY_CLASS(Source);
UNION_CLASS_BOILERPLATE(OmpDoacross);
std::variant<Sink, Source> u;
};

// Ref: [4.5:169-170], [5.0:255-256], [5.1:288-289], [5.2:323-324]
//
// depend-clause ->
// DEPEND(SOURCE) | // since 4.5, until 5.1
// DEPEND(SINK: depend-vec) | // since 4.5, until 5.1
// DEPEND([depend-modifier,]dependence-type: locator-list) // since 4.5
// DEPEND(SINK: iteration-vector) | // since 4.5, until 5.1
// DEPEND([depend-modifier,]
// task-dependence-type: locator-list) // since 4.5
//
// depend-modifier -> iterator-modifier // since 5.0
struct OmpDependClause {
OmpTaskDependenceType::Type GetDepType() const;

UNION_CLASS_BOILERPLATE(OmpDependClause);
EMPTY_CLASS(Source);
WRAPPER_CLASS(Sink, std::list<OmpDependSinkVec>);
struct InOut {
TUPLE_CLASS_BOILERPLATE(InOut);
struct TaskDep {
OmpTaskDependenceType::Type GetTaskDepType() const;
TUPLE_CLASS_BOILERPLATE(TaskDep);
std::tuple<std::optional<OmpIteratorModifier>, OmpTaskDependenceType,
OmpObjectList>
t;
};
std::variant<Source, Sink, InOut> u;
std::variant<TaskDep, OmpDoacross> u;
};

WRAPPER_CLASS(OmpDoacrossClause, OmpDoacross);

// Ref: [5.0:254-255], [5.1:287-288], [5.2:73]
//
// destroy-clause ->
Expand Down Expand Up @@ -3775,8 +3808,12 @@ struct OmpNumTasksClause {

// Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322]
//
// update-clause -> UPDATE(task-dependence-type) // since 5.0
WRAPPER_CLASS(OmpUpdateClause, OmpTaskDependenceType);
// update-clause -> UPDATE(dependence-type) // since 5.0, until 5.1
// update-clause -> UPDATE(task-dependence-type) // since 5.2
struct OmpUpdateClause {
UNION_CLASS_BOILERPLATE(OmpUpdateClause);
std::variant<OmpDependenceType, OmpTaskDependenceType> u;
};

// OpenMP Clauses
struct OmpClause {
Expand Down
30 changes: 15 additions & 15 deletions flang/lib/Lower/OpenMP/ClauseProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,28 @@ genProcBindKindAttr(fir::FirOpBuilder &firOpBuilder,

static mlir::omp::ClauseTaskDependAttr
genDependKindAttr(lower::AbstractConverter &converter,
const omp::clause::Depend::TaskDependenceType kind) {
const omp::clause::DependenceType kind) {
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
mlir::Location currentLocation = converter.getCurrentLocation();

mlir::omp::ClauseTaskDepend pbKind;
switch (kind) {
case omp::clause::Depend::TaskDependenceType::In:
case omp::clause::DependenceType::In:
pbKind = mlir::omp::ClauseTaskDepend::taskdependin;
break;
case omp::clause::Depend::TaskDependenceType::Out:
case omp::clause::DependenceType::Out:
pbKind = mlir::omp::ClauseTaskDepend::taskdependout;
break;
case omp::clause::Depend::TaskDependenceType::Inout:
case omp::clause::DependenceType::Inout:
pbKind = mlir::omp::ClauseTaskDepend::taskdependinout;
break;
case omp::clause::Depend::TaskDependenceType::Mutexinoutset:
case omp::clause::Depend::TaskDependenceType::Inoutset:
case omp::clause::DependenceType::Mutexinoutset:
case omp::clause::DependenceType::Inoutset:
TODO(currentLocation, "INOUTSET and MUTEXINOUTSET are not supported yet");
break;
case omp::clause::Depend::TaskDependenceType::Depobj:
case omp::clause::Depend::TaskDependenceType::Sink:
case omp::clause::Depend::TaskDependenceType::Source:
case omp::clause::DependenceType::Depobj:
case omp::clause::DependenceType::Sink:
case omp::clause::DependenceType::Source:
llvm_unreachable("unhandled parser task dependence type");
break;
}
Expand Down Expand Up @@ -803,20 +803,20 @@ bool ClauseProcessor::processDepend(mlir::omp::DependClauseOps &result) const {
auto process = [&](const omp::clause::Depend &clause,
const parser::CharBlock &) {
using Depend = omp::clause::Depend;
if (!std::holds_alternative<Depend::DepType>(clause.u)) {
if (!std::holds_alternative<Depend::TaskDep>(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);
auto &taskDep = std::get<Depend::TaskDep>(clause.u);
auto depType = std::get<clause::DependenceType>(taskDep.t);
auto &objects = std::get<omp::ObjectList>(taskDep.t);

if (std::get<std::optional<omp::clause::Iterator>>(depType.t)) {
if (std::get<std::optional<omp::clause::Iterator>>(taskDep.t)) {
TODO(converter.getCurrentLocation(),
"Support for iterator modifiers is not implemented yet");
}
mlir::omp::ClauseTaskDependAttr dependTypeOperand =
genDependKindAttr(converter, kind);
genDependKindAttr(converter, depType);
result.dependKinds.append(objects.size(), dependTypeOperand);

for (const omp::Object &object : objects) {
Expand Down
Loading
Loading