[flang-commits] [flang] Adding parsing and semantic check support for omp masked (PR #91432)
Anchu Rajendran S via flang-commits
flang-commits at lists.llvm.org
Wed May 15 23:02:55 PDT 2024
https://github.com/anchuraj updated https://github.com/llvm/llvm-project/pull/91432
>From 99de7e20a6612ba8635816f5227cbb375ed87a39 Mon Sep 17 00:00:00 2001
From: Anchu Rajendran <asudhaku at amd.com>
Date: Tue, 7 May 2024 21:32:25 -0500
Subject: [PATCH 1/6] Adding parsing and semantic check support for omp masked
---
flang/lib/Parser/openmp-parsers.cpp | 19 +++--
flang/lib/Parser/unparse.cpp | 18 ++++
flang/lib/Semantics/resolve-directives.cpp | 61 +++++++++++---
flang/test/Parser/OpenMP/masked-unparse.f90 | 92 +++++++++++++++++++++
flang/test/Semantics/OpenMP/masked.f90 | 13 +++
5 files changed, 186 insertions(+), 17 deletions(-)
create mode 100644 flang/test/Parser/OpenMP/masked-unparse.f90
create mode 100644 flang/test/Semantics/OpenMP/masked.f90
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 48f213794247d..e470bf7856607 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -220,12 +220,11 @@ TYPE_PARSER(construct<OmpAlignedClause>(
// 2.9.5 ORDER ([order-modifier :]concurrent)
TYPE_PARSER(construct<OmpOrderModifier>(
- "REPRODUCIBLE" >> pure(OmpOrderModifier::Kind::Reproducible)) ||
+ "REPRODUCIBLE" >> pure(OmpOrderModifier::Kind::Reproducible)) ||
construct<OmpOrderModifier>(
- "UNCONSTRAINED" >> pure(OmpOrderModifier::Kind::Unconstrained)))
+ "UNCONSTRAINED" >> pure(OmpOrderModifier::Kind::Unconstrained)))
-TYPE_PARSER(construct<OmpOrderClause>(
- maybe(Parser<OmpOrderModifier>{} / ":"),
+TYPE_PARSER(construct<OmpOrderClause>(maybe(Parser<OmpOrderModifier>{} / ":"),
"CONCURRENT" >> pure(OmpOrderClause::Type::Concurrent)))
TYPE_PARSER(
@@ -266,6 +265,8 @@ TYPE_PARSER(
construct<OmpClause>(construct<OmpClause::DynamicAllocators>()) ||
"ENTER" >> construct<OmpClause>(construct<OmpClause::Enter>(
parenthesized(Parser<OmpObjectList>{}))) ||
+ "FILTER" >> construct<OmpClause>(construct<OmpClause::Filter>(
+ parenthesized(scalarIntExpr))) ||
"FINAL" >> construct<OmpClause>(construct<OmpClause::Final>(
parenthesized(scalarLogicalExpr))) ||
"FULL" >> construct<OmpClause>(construct<OmpClause::Full>()) ||
@@ -486,9 +487,17 @@ TYPE_PARSER(
endOfLine)
// Directives enclosing structured-block
-TYPE_PARSER(construct<OmpBlockDirective>(first(
+TYPE_PARSER(construct<OmpBlockDirective>(first("MASKED TASKLOOP SIMD" >>
+ pure(llvm::omp::Directive::OMPD_masked_taskloop_simd),
+ "MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_taskloop),
+ "MASKED" >> pure(llvm::omp::Directive::OMPD_masked),
"MASTER" >> pure(llvm::omp::Directive::OMPD_master),
"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered),
+ "PARALLEL MASKED TASKLOOP SIMD" >>
+ pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd),
+ "PARALLEL MASKED TASKLOOP" >>
+ pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop),
+ "PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked),
"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare),
"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel),
"SINGLE" >> pure(llvm::omp::Directive::OMPD_single),
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 3398b395f198f..7b6b083cf3e62 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2283,12 +2283,30 @@ class UnparseVisitor {
}
void Unparse(const OmpBlockDirective &x) {
switch (x.v) {
+ case llvm::omp::Directive::OMPD_masked_taskloop_simd:
+ Word("MASKED TASKLOOP SIMD");
+ break;
+ case llvm::omp::Directive::OMPD_masked_taskloop:
+ Word("MASKED TASKLOOP");
+ break;
+ case llvm::omp::Directive::OMPD_masked:
+ Word("MASKED");
+ break;
case llvm::omp::Directive::OMPD_master:
Word("MASTER");
break;
case llvm::omp::Directive::OMPD_ordered:
Word("ORDERED ");
break;
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
+ Word("PARALLEL MASKED TASKLOOP SIMD");
+ break;
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
+ Word("PARALLEL MASKED TASKLOOP");
+ break;
+ case llvm::omp::Directive::OMPD_parallel_masked:
+ Word("PARALLEL MASKED");
+ break;
case llvm::omp::Directive::OMPD_parallel_workshare:
Word("PARALLEL WORKSHARE ");
break;
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 2add2056f658d..b11fa3174277d 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -19,8 +19,10 @@
#include "flang/Parser/parse-tree.h"
#include "flang/Parser/tools.h"
#include "flang/Semantics/expression.h"
+#include <cstdint>
#include <list>
#include <map>
+#include <optional>
#include <sstream>
template <typename T>
@@ -50,6 +52,7 @@ template <typename T> class DirectiveAttributeVisitor {
Symbol::Flag defaultDSA{Symbol::Flag::AccShared}; // TODOACC
std::map<const Symbol *, Symbol::Flag> objectWithDSA;
bool withinConstruct{false};
+ std::optional<int64_t> maskedTId;
std::int64_t associatedLoopLevel{0};
};
@@ -90,6 +93,9 @@ template <typename T> class DirectiveAttributeVisitor {
void SetContextAssociatedLoopLevel(std::int64_t level) {
GetContext().associatedLoopLevel = level;
}
+ void SetMaskedTId(std::optional<int64_t> tid) {
+ GetContext().maskedTId = tid;
+ }
Symbol &MakeAssocSymbol(const SourceName &name, Symbol &prev, Scope &scope) {
const auto pair{scope.try_emplace(name, Attrs{}, HostAssocDetails{prev})};
return *pair.first->second;
@@ -646,6 +652,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
private:
std::int64_t GetAssociatedLoopLevelFromClauses(const parser::OmpClauseList &);
+ std::optional<int64_t> GetMaskedTId(const parser::OmpClauseList &);
Symbol::Flags dataSharingAttributeFlags{Symbol::Flag::OmpShared,
Symbol::Flag::OmpPrivate, Symbol::Flag::OmpFirstPrivate,
@@ -1105,18 +1112,18 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCCombinedConstruct &x) {
static bool IsLastNameArray(const parser::Designator &designator) {
const auto &name{GetLastName(designator)};
const evaluate::DataRef dataRef{*(name.symbol)};
- return common::visit(
- common::visitors{
- [](const evaluate::SymbolRef &ref) {
- return ref->Rank() > 0 ||
- ref->GetType()->category() == DeclTypeSpec::Numeric;
- },
- [](const evaluate::ArrayRef &aref) {
- return aref.base().IsSymbol() ||
- aref.base().GetComponent().base().Rank() == 0;
- },
- [](const auto &) { return false; },
- },
+ return common::visit(common::visitors{
+ [](const evaluate::SymbolRef &ref) {
+ return ref->Rank() > 0 ||
+ ref->GetType()->category() ==
+ DeclTypeSpec::Numeric;
+ },
+ [](const evaluate::ArrayRef &aref) {
+ return aref.base().IsSymbol() ||
+ aref.base().GetComponent().base().Rank() == 0;
+ },
+ [](const auto &) { return false; },
+ },
dataRef.u);
}
@@ -1498,11 +1505,35 @@ void AccAttributeVisitor::CheckMultipleAppearances(
AddDataSharingAttributeObject(*target);
}
}
+std::optional<int64_t> OmpAttributeVisitor::GetMaskedTId(
+ const parser::OmpClauseList &clauseList) {
+ for (const auto &clause : clauseList.v) {
+ if (const auto *filterClause{
+ std::get_if<parser::OmpClause::Filter>(&clause.u)}) {
+ if (const auto v{EvaluateInt64(context_, filterClause->v)}) {
+ return v;
+ }
+ }
+ }
+ // if no thread id is specified in filter clause, the masked thread id should
+ // be master's
+ return 0;
+}
bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
const auto &beginBlockDir{std::get<parser::OmpBeginBlockDirective>(x.t)};
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
+ const auto &clauseList{std::get<parser::OmpClauseList>(beginBlockDir.t)};
switch (beginDir.v) {
+ case llvm::omp::Directive::OMPD_masked_taskloop_simd:
+ case llvm::omp::Directive::OMPD_masked_taskloop:
+ case llvm::omp::Directive::OMPD_masked:
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
+ case llvm::omp::Directive::OMPD_parallel_masked:
+ PushContext(beginDir.source, beginDir.v);
+ SetMaskedTId(GetMaskedTId(clauseList));
+ break;
case llvm::omp::Directive::OMPD_master:
case llvm::omp::Directive::OMPD_ordered:
case llvm::omp::Directive::OMPD_parallel:
@@ -1532,6 +1563,12 @@ void OmpAttributeVisitor::Post(const parser::OpenMPBlockConstruct &x) {
const auto &beginBlockDir{std::get<parser::OmpBeginBlockDirective>(x.t)};
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
switch (beginDir.v) {
+ case llvm::omp::Directive::OMPD_masked_taskloop_simd:
+ case llvm::omp::Directive::OMPD_masked_taskloop:
+ case llvm::omp::Directive::OMPD_masked:
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
+ case llvm::omp::Directive::OMPD_parallel_masked:
case llvm::omp::Directive::OMPD_parallel:
case llvm::omp::Directive::OMPD_single:
case llvm::omp::Directive::OMPD_target:
diff --git a/flang/test/Parser/OpenMP/masked-unparse.f90 b/flang/test/Parser/OpenMP/masked-unparse.f90
new file mode 100644
index 0000000000000..48c202628f25f
--- /dev/null
+++ b/flang/test/Parser/OpenMP/masked-unparse.f90
@@ -0,0 +1,92 @@
+! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck --ignore-case %s
+! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s
+
+! Check for parsing of masked directive with filter clause.
+
+
+subroutine test_masked()
+ integer :: c = 1
+ !PARSE-TREE: OmpBeginBlockDirective
+ !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked
+ !CHECK: !$omp masked
+ !$omp masked
+ c = c + 1
+ !$omp end masked
+ !PARSE-TREE: OmpBeginBlockDirective
+ !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked
+ !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '1_4'
+ !PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '1'
+ !CHECK: !$omp masked filter(1_4)
+ !$omp masked filter(1)
+ c = c + 2
+ !$omp end masked
+end subroutine
+
+subroutine test_masked_taskloop_simd()
+ integer :: i, j = 1
+ !PARSE-TREE: OmpBeginBlockDirective
+ !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked taskloop simd
+ !CHECK: !$omp masked taskloop simd
+ !$omp masked taskloop simd
+ do i=1,10
+ j = j + 1
+ end do
+ !$omp end masked taskloop simd
+end subroutine
+
+subroutine test_masked_taskloop
+ integer :: i, j = 1
+ !PARSE-TREE: OmpBeginBlockDirective
+ !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked taskloop
+ !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4'
+ !PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '2'
+ !CHECK: !$omp masked taskloop filter(2_4)
+ !$omp masked taskloop filter(2)
+ do i=1,10
+ j = j + 1
+ end do
+ !$omp end masked taskloop
+end subroutine
+
+subroutine test_parallel_masked
+ integer, parameter :: i = 1, j = 1
+ integer :: c = 2
+ !PARSE-TREE: OmpBeginBlockDirective
+ !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel masked
+ !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4'
+ !PARSE-TREE-NEXT: Add
+ !PARSE-TREE-NEXT: Expr = '1_4'
+ !PARSE-TREE-NEXT: Designator -> DataRef -> Name = 'i'
+ !PARSE-TREE-NEXT: Expr = '1_4'
+ !PARSE-TREE-NEXT: Designator -> DataRef -> Name = 'j'
+ !CHECK: !$omp parallel masked filter(2_4)
+ !$omp parallel masked filter(i+j)
+ c = c + 2
+ !$omp end parallel masked
+end subroutine
+
+subroutine test_parallel_masked_taskloop_simd
+ integer :: i, j = 1
+ !PARSE-TREE: OmpBeginBlockDirective
+ !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel masked taskloop simd
+ !CHECK: !$omp parallel masked taskloop simd
+ !$omp parallel masked taskloop simd
+ do i=1,10
+ j = j + 1
+ end do
+ !$omp end parallel masked taskloop simd
+end subroutine
+
+subroutine test_parallel_masked_taskloop
+ integer :: i, j = 1
+ !PARSE-TREE: OmpBeginBlockDirective
+ !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel masked taskloop
+ !PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4'
+ !PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '2'
+ !CHECK: !$omp parallel masked taskloop filter(2_4)
+ !$omp parallel masked taskloop filter(2)
+ do i=1,10
+ j = j + 1
+ end do
+ !$omp end parallel masked taskloop
+end subroutine
diff --git a/flang/test/Semantics/OpenMP/masked.f90 b/flang/test/Semantics/OpenMP/masked.f90
new file mode 100644
index 0000000000000..1113853ee8a94
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/masked.f90
@@ -0,0 +1,13 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
+
+subroutine test_masked()
+ integer :: c = 1
+ !ERROR: At most one FILTER clause can appear on the MASKED directive
+ !$omp masked filter(1) filter(2)
+ c = c + 1
+ !$omp end masked
+ !ERROR: NOWAIT clause is not allowed on the MASKED directive
+ !$omp masked nowait
+ c = c + 2
+ !$omp end masked
+end subroutine
>From 553b416d19dc299b461d8dc3800f8da5e8d08a93 Mon Sep 17 00:00:00 2001
From: Anchu Rajendran <asudhaku at amd.com>
Date: Wed, 8 May 2024 12:37:26 -0500
Subject: [PATCH 2/6] R2: Removing the unrelated formatting changes
---
flang/lib/Parser/openmp-parsers.cpp | 7 ++++---
flang/lib/Semantics/resolve-directives.cpp | 24 +++++++++++-----------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index e470bf7856607..b1900993f1f42 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -220,11 +220,12 @@ TYPE_PARSER(construct<OmpAlignedClause>(
// 2.9.5 ORDER ([order-modifier :]concurrent)
TYPE_PARSER(construct<OmpOrderModifier>(
- "REPRODUCIBLE" >> pure(OmpOrderModifier::Kind::Reproducible)) ||
+ "REPRODUCIBLE" >> pure(OmpOrderModifier::Kind::Reproducible)) ||
construct<OmpOrderModifier>(
- "UNCONSTRAINED" >> pure(OmpOrderModifier::Kind::Unconstrained)))
+ "UNCONSTRAINED" >> pure(OmpOrderModifier::Kind::Unconstrained)))
-TYPE_PARSER(construct<OmpOrderClause>(maybe(Parser<OmpOrderModifier>{} / ":"),
+TYPE_PARSER(construct<OmpOrderClause>(
+ maybe(Parser<OmpOrderModifier>{} / ":"),
"CONCURRENT" >> pure(OmpOrderClause::Type::Concurrent)))
TYPE_PARSER(
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index b11fa3174277d..9301b1247795d 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1112,18 +1112,18 @@ bool AccAttributeVisitor::Pre(const parser::OpenACCCombinedConstruct &x) {
static bool IsLastNameArray(const parser::Designator &designator) {
const auto &name{GetLastName(designator)};
const evaluate::DataRef dataRef{*(name.symbol)};
- return common::visit(common::visitors{
- [](const evaluate::SymbolRef &ref) {
- return ref->Rank() > 0 ||
- ref->GetType()->category() ==
- DeclTypeSpec::Numeric;
- },
- [](const evaluate::ArrayRef &aref) {
- return aref.base().IsSymbol() ||
- aref.base().GetComponent().base().Rank() == 0;
- },
- [](const auto &) { return false; },
- },
+ return common::visit(
+ common::visitors{
+ [](const evaluate::SymbolRef &ref) {
+ return ref->Rank() > 0 ||
+ ref->GetType()->category() == DeclTypeSpec::Numeric;
+ },
+ [](const evaluate::ArrayRef &aref) {
+ return aref.base().IsSymbol() ||
+ aref.base().GetComponent().base().Rank() == 0;
+ },
+ [](const auto &) { return false; },
+ },
dataRef.u);
}
>From 00c24c4b043a7e5117644dfb11e1a15705b30cd2 Mon Sep 17 00:00:00 2001
From: Anchu Rajendran <asudhaku at amd.com>
Date: Thu, 9 May 2024 22:43:44 -0500
Subject: [PATCH 3/6] R3: Removing maskedTId changes & adding graceful failure
in Lowering
---
.../flang/Semantics/openmp-directive-sets.h | 6 ++
flang/lib/Lower/OpenMP/OpenMP.cpp | 4 +-
flang/lib/Semantics/resolve-directives.cpp | 25 -------
.../Lower/OpenMP/Todo/masked-directive.f90 | 65 +++++++++++++++++++
4 files changed, 74 insertions(+), 26 deletions(-)
create mode 100644 flang/test/Lower/OpenMP/Todo/masked-directive.f90
diff --git a/flang/include/flang/Semantics/openmp-directive-sets.h b/flang/include/flang/Semantics/openmp-directive-sets.h
index 842d251b682aa..0709ab1759a07 100644
--- a/flang/include/flang/Semantics/openmp-directive-sets.h
+++ b/flang/include/flang/Semantics/openmp-directive-sets.h
@@ -205,9 +205,15 @@ static const OmpDirectiveSet compositeConstructSet{
};
static const OmpDirectiveSet blockConstructSet{
+ Directive::OMPD_masked,
+ Directive::OMPD_masked_taskloop,
+ Directive::OMPD_masked_taskloop_simd,
Directive::OMPD_master,
Directive::OMPD_ordered,
Directive::OMPD_parallel,
+ Directive::OMPD_parallel_masked,
+ Directive::OMPD_parallel_masked_taskloop,
+ Directive::OMPD_parallel_masked_taskloop_simd,
Directive::OMPD_parallel_workshare,
Directive::OMPD_single,
Directive::OMPD_target,
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index f21acdd64d7c3..f6638faf285ea 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1970,10 +1970,12 @@ static void genOMPDispatch(Fortran::lower::AbstractConverter &converter,
genWsloopOp(converter, symTable, semaCtx, eval, loc, clauses, queue, item);
break;
case llvm::omp::Directive::OMPD_loop:
- case llvm::omp::Directive::OMPD_masked:
TODO(loc, "Unhandled loop directive (" +
llvm::omp::getOpenMPDirectiveName(dir) + ")");
break;
+ case llvm::omp::Directive::OMPD_masked:
+ TODO(loc, "Unhandled directive " +
+ llvm::omp::getOpenMPDirectiveName(dir));
case llvm::omp::Directive::OMPD_master:
genMasterOp(converter, symTable, semaCtx, eval, loc, clauses, queue, item);
break;
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 9301b1247795d..f179128eb1d8c 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -19,10 +19,8 @@
#include "flang/Parser/parse-tree.h"
#include "flang/Parser/tools.h"
#include "flang/Semantics/expression.h"
-#include <cstdint>
#include <list>
#include <map>
-#include <optional>
#include <sstream>
template <typename T>
@@ -52,7 +50,6 @@ template <typename T> class DirectiveAttributeVisitor {
Symbol::Flag defaultDSA{Symbol::Flag::AccShared}; // TODOACC
std::map<const Symbol *, Symbol::Flag> objectWithDSA;
bool withinConstruct{false};
- std::optional<int64_t> maskedTId;
std::int64_t associatedLoopLevel{0};
};
@@ -93,9 +90,6 @@ template <typename T> class DirectiveAttributeVisitor {
void SetContextAssociatedLoopLevel(std::int64_t level) {
GetContext().associatedLoopLevel = level;
}
- void SetMaskedTId(std::optional<int64_t> tid) {
- GetContext().maskedTId = tid;
- }
Symbol &MakeAssocSymbol(const SourceName &name, Symbol &prev, Scope &scope) {
const auto pair{scope.try_emplace(name, Attrs{}, HostAssocDetails{prev})};
return *pair.first->second;
@@ -652,7 +646,6 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
private:
std::int64_t GetAssociatedLoopLevelFromClauses(const parser::OmpClauseList &);
- std::optional<int64_t> GetMaskedTId(const parser::OmpClauseList &);
Symbol::Flags dataSharingAttributeFlags{Symbol::Flag::OmpShared,
Symbol::Flag::OmpPrivate, Symbol::Flag::OmpFirstPrivate,
@@ -1505,25 +1498,10 @@ void AccAttributeVisitor::CheckMultipleAppearances(
AddDataSharingAttributeObject(*target);
}
}
-std::optional<int64_t> OmpAttributeVisitor::GetMaskedTId(
- const parser::OmpClauseList &clauseList) {
- for (const auto &clause : clauseList.v) {
- if (const auto *filterClause{
- std::get_if<parser::OmpClause::Filter>(&clause.u)}) {
- if (const auto v{EvaluateInt64(context_, filterClause->v)}) {
- return v;
- }
- }
- }
- // if no thread id is specified in filter clause, the masked thread id should
- // be master's
- return 0;
-}
bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
const auto &beginBlockDir{std::get<parser::OmpBeginBlockDirective>(x.t)};
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
- const auto &clauseList{std::get<parser::OmpClauseList>(beginBlockDir.t)};
switch (beginDir.v) {
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
case llvm::omp::Directive::OMPD_masked_taskloop:
@@ -1531,9 +1509,6 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
case llvm::omp::Directive::OMPD_parallel_masked:
- PushContext(beginDir.source, beginDir.v);
- SetMaskedTId(GetMaskedTId(clauseList));
- break;
case llvm::omp::Directive::OMPD_master:
case llvm::omp::Directive::OMPD_ordered:
case llvm::omp::Directive::OMPD_parallel:
diff --git a/flang/test/Lower/OpenMP/Todo/masked-directive.f90 b/flang/test/Lower/OpenMP/Todo/masked-directive.f90
new file mode 100644
index 0000000000000..5bafe328d8922
--- /dev/null
+++ b/flang/test/Lower/OpenMP/Todo/masked-directive.f90
@@ -0,0 +1,65 @@
+
+! This test checks lowering of OpenMP masked Directive.
+
+// RUN: not flang-new -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
+
+subroutine test_masked()
+ integer :: c = 1
+ // CHECK: not yet implemented: Unhandled Directive masked
+ !$omp masked
+ c = c + 1
+ !$omp end masked
+ // CHECK: not yet implemented: Unhandled Directive masked
+ !$omp masked filter(1)
+ c = c + 2
+ !$omp end masked
+end subroutine
+
+subroutine test_masked_taskloop_simd()
+ integer :: i, j = 1
+ // CHECK: not yet implemented: Unhandled Directive masked
+ !$omp masked taskloop simd
+ do i=1,10
+ j = j + 1
+ end do
+ !$omp end masked taskloop simd
+end subroutine
+
+subroutine test_masked_taskloop
+ integer :: i, j = 1
+ // CHECK: not yet implemented: Unhandled Directive masked
+ !$omp masked taskloop filter(2)
+ do i=1,10
+ j = j + 1
+ end do
+ !$omp end masked taskloop
+end subroutine
+
+subroutine test_parallel_masked
+ integer, parameter :: i = 1, j = 1
+ integer :: c = 2
+ // CHECK: not yet implemented: Unhandled Directive masked
+ !$omp parallel masked filter(i+j)
+ c = c + 2
+ !$omp end parallel masked
+end subroutine
+
+subroutine test_parallel_masked_taskloop_simd
+ integer :: i, j = 1
+ // CHECK: not yet implemented: Unhandled Directive masked
+ !$omp parallel masked taskloop simd
+ do i=1,10
+ j = j + 1
+ end do
+ !$omp end parallel masked taskloop simd
+end subroutine
+
+subroutine test_parallel_masked_taskloop
+ integer :: i, j = 1
+ // CHECK: not yet implemented: Unhandled Directive masked
+ !$omp parallel masked taskloop filter(2)
+ do i=1,10
+ j = j + 1
+ end do
+ !$omp end parallel masked taskloop
+end subroutine
>From 712d385c5a9fb42d10c71a65ce3cf1b6f0087d27 Mon Sep 17 00:00:00 2001
From: Anchu Rajendran <asudhaku at amd.com>
Date: Wed, 15 May 2024 00:33:02 -0500
Subject: [PATCH 4/6] R4: Moved Taskloop directives to be parsed as Loop
Directives
---
.../flang/Semantics/openmp-directive-sets.h | 4 --
flang/lib/Parser/openmp-parsers.cpp | 15 ++---
flang/lib/Parser/unparse.cpp | 24 ++++----
flang/lib/Semantics/resolve-directives.cpp | 12 ++--
.../Lower/OpenMP/Todo/masked-directive.f90 | 58 ++-----------------
flang/test/Parser/OpenMP/masked-unparse.f90 | 16 ++---
6 files changed, 36 insertions(+), 93 deletions(-)
diff --git a/flang/include/flang/Semantics/openmp-directive-sets.h b/flang/include/flang/Semantics/openmp-directive-sets.h
index 0709ab1759a07..da66e0eda3216 100644
--- a/flang/include/flang/Semantics/openmp-directive-sets.h
+++ b/flang/include/flang/Semantics/openmp-directive-sets.h
@@ -206,14 +206,10 @@ static const OmpDirectiveSet compositeConstructSet{
static const OmpDirectiveSet blockConstructSet{
Directive::OMPD_masked,
- Directive::OMPD_masked_taskloop,
- Directive::OMPD_masked_taskloop_simd,
Directive::OMPD_master,
Directive::OMPD_ordered,
Directive::OMPD_parallel,
Directive::OMPD_parallel_masked,
- Directive::OMPD_parallel_masked_taskloop,
- Directive::OMPD_parallel_masked_taskloop_simd,
Directive::OMPD_parallel_workshare,
Directive::OMPD_single,
Directive::OMPD_target,
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index b1900993f1f42..e67dbcca30e7d 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -378,8 +378,15 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
"DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_distribute),
"DO SIMD" >> pure(llvm::omp::Directive::OMPD_do_simd),
"DO" >> pure(llvm::omp::Directive::OMPD_do),
+ "MASKED TASKLOOP SIMD" >>
+ pure(llvm::omp::Directive::OMPD_masked_taskloop_simd),
+ "MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_taskloop),
"PARALLEL DO SIMD" >> pure(llvm::omp::Directive::OMPD_parallel_do_simd),
"PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_parallel_do),
+ "PARALLEL MASKED TASKLOOP SIMD" >>
+ pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd),
+ "PARALLEL MASKED TASKLOOP" >>
+ pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop),
"SIMD" >> pure(llvm::omp::Directive::OMPD_simd),
"TARGET PARALLEL DO SIMD" >>
pure(llvm::omp::Directive::OMPD_target_parallel_do_simd),
@@ -488,16 +495,10 @@ TYPE_PARSER(
endOfLine)
// Directives enclosing structured-block
-TYPE_PARSER(construct<OmpBlockDirective>(first("MASKED TASKLOOP SIMD" >>
- pure(llvm::omp::Directive::OMPD_masked_taskloop_simd),
- "MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_taskloop),
+TYPE_PARSER(construct<OmpBlockDirective>(first(
"MASKED" >> pure(llvm::omp::Directive::OMPD_masked),
"MASTER" >> pure(llvm::omp::Directive::OMPD_master),
"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered),
- "PARALLEL MASKED TASKLOOP SIMD" >>
- pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd),
- "PARALLEL MASKED TASKLOOP" >>
- pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop),
"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked),
"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare),
"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel),
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 7b6b083cf3e62..22c9a2a13d8dc 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2194,12 +2194,24 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_do_simd:
Word("DO SIMD ");
break;
+ case llvm::omp::Directive::OMPD_masked_taskloop_simd:
+ Word("MASKED TASKLOOP SIMD");
+ break;
+ case llvm::omp::Directive::OMPD_masked_taskloop:
+ Word("MASKED TASKLOOP");
+ break;
case llvm::omp::Directive::OMPD_parallel_do:
Word("PARALLEL DO ");
break;
case llvm::omp::Directive::OMPD_parallel_do_simd:
Word("PARALLEL DO SIMD ");
break;
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
+ Word("PARALLEL MASKED TASKLOOP SIMD");
+ break;
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
+ Word("PARALLEL MASKED TASKLOOP");
+ break;
case llvm::omp::Directive::OMPD_simd:
Word("SIMD ");
break;
@@ -2283,12 +2295,6 @@ class UnparseVisitor {
}
void Unparse(const OmpBlockDirective &x) {
switch (x.v) {
- case llvm::omp::Directive::OMPD_masked_taskloop_simd:
- Word("MASKED TASKLOOP SIMD");
- break;
- case llvm::omp::Directive::OMPD_masked_taskloop:
- Word("MASKED TASKLOOP");
- break;
case llvm::omp::Directive::OMPD_masked:
Word("MASKED");
break;
@@ -2298,12 +2304,6 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_ordered:
Word("ORDERED ");
break;
- case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
- Word("PARALLEL MASKED TASKLOOP SIMD");
- break;
- case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
- Word("PARALLEL MASKED TASKLOOP");
- break;
case llvm::omp::Directive::OMPD_parallel_masked:
Word("PARALLEL MASKED");
break;
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index f179128eb1d8c..dbc531372c3f4 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1503,11 +1503,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
const auto &beginBlockDir{std::get<parser::OmpBeginBlockDirective>(x.t)};
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
switch (beginDir.v) {
- case llvm::omp::Directive::OMPD_masked_taskloop_simd:
- case llvm::omp::Directive::OMPD_masked_taskloop:
case llvm::omp::Directive::OMPD_masked:
- case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
- case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
case llvm::omp::Directive::OMPD_parallel_masked:
case llvm::omp::Directive::OMPD_master:
case llvm::omp::Directive::OMPD_ordered:
@@ -1538,11 +1534,7 @@ void OmpAttributeVisitor::Post(const parser::OpenMPBlockConstruct &x) {
const auto &beginBlockDir{std::get<parser::OmpBeginBlockDirective>(x.t)};
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
switch (beginDir.v) {
- case llvm::omp::Directive::OMPD_masked_taskloop_simd:
- case llvm::omp::Directive::OMPD_masked_taskloop:
case llvm::omp::Directive::OMPD_masked:
- case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
- case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
case llvm::omp::Directive::OMPD_parallel_masked:
case llvm::omp::Directive::OMPD_parallel:
case llvm::omp::Directive::OMPD_single:
@@ -1610,8 +1602,12 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
case llvm::omp::Directive::OMPD_distribute_simd:
case llvm::omp::Directive::OMPD_do:
case llvm::omp::Directive::OMPD_do_simd:
+ case llvm::omp::Directive::OMPD_masked_taskloop_simd:
+ case llvm::omp::Directive::OMPD_masked_taskloop:
case llvm::omp::Directive::OMPD_parallel_do:
case llvm::omp::Directive::OMPD_parallel_do_simd:
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
+ case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
case llvm::omp::Directive::OMPD_simd:
case llvm::omp::Directive::OMPD_target_parallel_do:
case llvm::omp::Directive::OMPD_target_parallel_do_simd:
diff --git a/flang/test/Lower/OpenMP/Todo/masked-directive.f90 b/flang/test/Lower/OpenMP/Todo/masked-directive.f90
index 5bafe328d8922..4b71a3a1e27cf 100644
--- a/flang/test/Lower/OpenMP/Todo/masked-directive.f90
+++ b/flang/test/Lower/OpenMP/Todo/masked-directive.f90
@@ -1,65 +1,15 @@
! This test checks lowering of OpenMP masked Directive.
-// RUN: not flang-new -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
+! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
+! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
+
+! CHECK: not yet implemented: Unhandled Directive masked
subroutine test_masked()
integer :: c = 1
- // CHECK: not yet implemented: Unhandled Directive masked
!$omp masked
c = c + 1
!$omp end masked
- // CHECK: not yet implemented: Unhandled Directive masked
- !$omp masked filter(1)
- c = c + 2
- !$omp end masked
-end subroutine
-
-subroutine test_masked_taskloop_simd()
- integer :: i, j = 1
- // CHECK: not yet implemented: Unhandled Directive masked
- !$omp masked taskloop simd
- do i=1,10
- j = j + 1
- end do
- !$omp end masked taskloop simd
-end subroutine
-
-subroutine test_masked_taskloop
- integer :: i, j = 1
- // CHECK: not yet implemented: Unhandled Directive masked
- !$omp masked taskloop filter(2)
- do i=1,10
- j = j + 1
- end do
- !$omp end masked taskloop
end subroutine
-subroutine test_parallel_masked
- integer, parameter :: i = 1, j = 1
- integer :: c = 2
- // CHECK: not yet implemented: Unhandled Directive masked
- !$omp parallel masked filter(i+j)
- c = c + 2
- !$omp end parallel masked
-end subroutine
-
-subroutine test_parallel_masked_taskloop_simd
- integer :: i, j = 1
- // CHECK: not yet implemented: Unhandled Directive masked
- !$omp parallel masked taskloop simd
- do i=1,10
- j = j + 1
- end do
- !$omp end parallel masked taskloop simd
-end subroutine
-
-subroutine test_parallel_masked_taskloop
- integer :: i, j = 1
- // CHECK: not yet implemented: Unhandled Directive masked
- !$omp parallel masked taskloop filter(2)
- do i=1,10
- j = j + 1
- end do
- !$omp end parallel masked taskloop
-end subroutine
diff --git a/flang/test/Parser/OpenMP/masked-unparse.f90 b/flang/test/Parser/OpenMP/masked-unparse.f90
index 48c202628f25f..16d7ca68e3e18 100644
--- a/flang/test/Parser/OpenMP/masked-unparse.f90
+++ b/flang/test/Parser/OpenMP/masked-unparse.f90
@@ -24,8 +24,8 @@ subroutine test_masked()
subroutine test_masked_taskloop_simd()
integer :: i, j = 1
- !PARSE-TREE: OmpBeginBlockDirective
- !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked taskloop simd
+ !PARSE-TREE: OmpBeginLoopDirective
+ !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = masked taskloop simd
!CHECK: !$omp masked taskloop simd
!$omp masked taskloop simd
do i=1,10
@@ -36,8 +36,8 @@ subroutine test_masked_taskloop_simd()
subroutine test_masked_taskloop
integer :: i, j = 1
- !PARSE-TREE: OmpBeginBlockDirective
- !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = masked taskloop
+ !PARSE-TREE: OmpBeginLoopDirective
+ !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = masked taskloop
!PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4'
!PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '2'
!CHECK: !$omp masked taskloop filter(2_4)
@@ -67,8 +67,8 @@ subroutine test_parallel_masked
subroutine test_parallel_masked_taskloop_simd
integer :: i, j = 1
- !PARSE-TREE: OmpBeginBlockDirective
- !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel masked taskloop simd
+ !PARSE-TREE: OmpBeginLoopDirective
+ !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel masked taskloop simd
!CHECK: !$omp parallel masked taskloop simd
!$omp parallel masked taskloop simd
do i=1,10
@@ -79,8 +79,8 @@ subroutine test_parallel_masked_taskloop_simd
subroutine test_parallel_masked_taskloop
integer :: i, j = 1
- !PARSE-TREE: OmpBeginBlockDirective
- !PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel masked taskloop
+ !PARSE-TREE: OmpBeginLoopDirective
+ !PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel masked taskloop
!PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Filter -> Scalar -> Integer -> Expr = '2_4'
!PARSE-TREE-NEXT: LiteralConstant -> IntLiteralConstant = '2'
!CHECK: !$omp parallel masked taskloop filter(2_4)
>From 38d4a937bf1b3ad20a0d899513a705c883519516 Mon Sep 17 00:00:00 2001
From: Anchu Rajendran <asudhaku at amd.com>
Date: Wed, 15 May 2024 03:32:48 -0500
Subject: [PATCH 5/6] R6: addressing format issues
---
flang/lib/Lower/OpenMP/OpenMP.cpp | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index f6638faf285ea..ba2aeb5414452 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1970,12 +1970,9 @@ static void genOMPDispatch(Fortran::lower::AbstractConverter &converter,
genWsloopOp(converter, symTable, semaCtx, eval, loc, clauses, queue, item);
break;
case llvm::omp::Directive::OMPD_loop:
- TODO(loc, "Unhandled loop directive (" +
- llvm::omp::getOpenMPDirectiveName(dir) + ")");
- break;
case llvm::omp::Directive::OMPD_masked:
- TODO(loc, "Unhandled directive " +
- llvm::omp::getOpenMPDirectiveName(dir));
+ TODO(loc, "Unhandled directive " + llvm::omp::getOpenMPDirectiveName(dir));
+ break;
case llvm::omp::Directive::OMPD_master:
genMasterOp(converter, symTable, semaCtx, eval, loc, clauses, queue, item);
break;
>From 893c1ea59623e04d831cfd48edc68244c3228598 Mon Sep 17 00:00:00 2001
From: Anchu Rajendran <asudhaku at amd.com>
Date: Thu, 16 May 2024 01:02:38 -0500
Subject: [PATCH 6/6] R7: Fixing the typo
---
flang/test/Lower/OpenMP/Todo/masked-directive.f90 | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/flang/test/Lower/OpenMP/Todo/masked-directive.f90 b/flang/test/Lower/OpenMP/Todo/masked-directive.f90
index 4b71a3a1e27cf..77767715af522 100644
--- a/flang/test/Lower/OpenMP/Todo/masked-directive.f90
+++ b/flang/test/Lower/OpenMP/Todo/masked-directive.f90
@@ -1,11 +1,9 @@
-
! This test checks lowering of OpenMP masked Directive.
! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
-! CHECK: not yet implemented: Unhandled Directive masked
-
+! CHECK: not yet implemented: Unhandled directive masked
subroutine test_masked()
integer :: c = 1
!$omp masked
More information about the flang-commits
mailing list