Skip to content
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
2 changes: 1 addition & 1 deletion flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3544,7 +3544,7 @@ struct OmpDefaultmapClause {
TUPLE_CLASS_BOILERPLATE(OmpDefaultmapClause);
ENUM_CLASS(
ImplicitBehavior, Alloc, To, From, Tofrom, Firstprivate, None, Default)
ENUM_CLASS(VariableCategory, Scalar, Aggregate, Allocatable, Pointer)
ENUM_CLASS(VariableCategory, All, Scalar, Aggregate, Allocatable, Pointer)
std::tuple<ImplicitBehavior, std::optional<VariableCategory>> t;
};

Expand Down
9 changes: 6 additions & 3 deletions flang/lib/Lower/OpenMP/Clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,17 +561,20 @@ Defaultmap make(const parser::OmpClause::Defaultmap &inp,
CLAUSET_ENUM_CONVERT( //
convert2, wrapped::VariableCategory, Defaultmap::VariableCategory,
// clang-format off
MS(Scalar, Scalar)
MS(Aggregate, Aggregate)
MS(Pointer, Pointer)
MS(All, All)
MS(Allocatable, Allocatable)
MS(Pointer, Pointer)
MS(Scalar, Scalar)
// clang-format on
);

auto &t0 = std::get<wrapped::ImplicitBehavior>(inp.v.t);
auto &t1 = std::get<std::optional<wrapped::VariableCategory>>(inp.v.t);

auto category = t1 ? convert2(*t1) : Defaultmap::VariableCategory::All;
return Defaultmap{{/*ImplicitBehavior=*/convert1(t0),
/*VariableCategory=*/maybeApply(convert2, t1)}};
/*VariableCategory=*/category}};
}

Doacross makeDoacross(const parser::OmpDoacross &doa,
Expand Down
5 changes: 4 additions & 1 deletion flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "flang/Optimizer/Builder/Todo.h"
#include "flang/Optimizer/Dialect/FIRType.h"
#include "flang/Optimizer/HLFIR/HLFIROps.h"
#include "flang/Parser/characters.h"
#include "flang/Parser/parse-tree.h"
#include "flang/Semantics/openmp-directive-sets.h"
#include "flang/Semantics/tools.h"
Expand Down Expand Up @@ -2881,7 +2882,9 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
!std::holds_alternative<clause::InReduction>(clause.u) &&
!std::holds_alternative<clause::Mergeable>(clause.u) &&
!std::holds_alternative<clause::TaskReduction>(clause.u)) {
TODO(clauseLocation, "OpenMP Block construct clause");
std::string name =
parser::ToUpperCaseLetters(llvm::omp::getOpenMPClauseName(clause.id));
TODO(clauseLocation, name + " clause is not implemented yet");
}
}

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 @@ -270,7 +270,7 @@ TYPE_PARSER(construct<OmpMapClause>(
// 2.19.7.2 defaultmap(implicit-behavior[:variable-category])
// implicit-behavior -> ALLOC | TO | FROM | TOFROM | FIRSRTPRIVATE | NONE |
// DEFAULT
// variable-category -> SCALAR | AGGREGATE | ALLOCATABLE | POINTER
// variable-category -> ALL | SCALAR | AGGREGATE | ALLOCATABLE | POINTER
TYPE_PARSER(construct<OmpDefaultmapClause>(
construct<OmpDefaultmapClause::ImplicitBehavior>(
"ALLOC" >> pure(OmpDefaultmapClause::ImplicitBehavior::Alloc) ||
Expand All @@ -283,6 +283,7 @@ TYPE_PARSER(construct<OmpDefaultmapClause>(
"DEFAULT" >> pure(OmpDefaultmapClause::ImplicitBehavior::Default)),
maybe(":" >>
construct<OmpDefaultmapClause::VariableCategory>(
"ALL"_id >> pure(OmpDefaultmapClause::VariableCategory::All) ||
"SCALAR" >> pure(OmpDefaultmapClause::VariableCategory::Scalar) ||
"AGGREGATE" >>
pure(OmpDefaultmapClause::VariableCategory::Aggregate) ||
Expand Down
45 changes: 41 additions & 4 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3333,14 +3333,17 @@ void OmpStructureChecker::Leave(const parser::OmpAtomicRead &) {
CheckNotAllowedIfClause(llvm::omp::Clause::OMPC_read,
{llvm::omp::Clause::OMPC_release, llvm::omp::Clause::OMPC_acq_rel});
}

void OmpStructureChecker::Leave(const parser::OmpAtomicWrite &) {
CheckNotAllowedIfClause(llvm::omp::Clause::OMPC_write,
{llvm::omp::Clause::OMPC_acquire, llvm::omp::Clause::OMPC_acq_rel});
}

void OmpStructureChecker::Leave(const parser::OmpAtomicUpdate &) {
CheckNotAllowedIfClause(llvm::omp::Clause::OMPC_update,
{llvm::omp::Clause::OMPC_acquire, llvm::omp::Clause::OMPC_acq_rel});
}

// OmpAtomic node represents atomic directive without atomic-clause.
// atomic-clause - READ,WRITE,UPDATE,CAPTURE.
void OmpStructureChecker::Leave(const parser::OmpAtomic &) {
Expand All @@ -3353,6 +3356,7 @@ void OmpStructureChecker::Leave(const parser::OmpAtomic &) {
"Clause ACQ_REL is not allowed on the ATOMIC directive"_err_en_US);
}
}

// Restrictions specific to each clause are implemented apart from the
// generalized restrictions.
void OmpStructureChecker::Enter(const parser::OmpClause::Aligned &x) {
Expand All @@ -3364,15 +3368,48 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Aligned &x) {
}
// 2.8.1 TODO: list-item attribute check
}

void OmpStructureChecker::Enter(const parser::OmpClause::Defaultmap &x) {
CheckAllowedClause(llvm::omp::Clause::OMPC_defaultmap);
unsigned version{context_.langOptions().OpenMPVersion};
using ImplicitBehavior = parser::OmpDefaultmapClause::ImplicitBehavior;
auto behavior{std::get<ImplicitBehavior>(x.v.t)};
if (version <= 45) {
if (behavior != ImplicitBehavior::Tofrom) {
context_.Say(GetContext().clauseSource,
"%s is not allowed in %s, %s"_warn_en_US,
parser::ToUpperCaseLetters(
parser::OmpDefaultmapClause::EnumToString(behavior)),
ThisVersion(version), TryVersion(50));
}
}
using VariableCategory = parser::OmpDefaultmapClause::VariableCategory;
if (!std::get<std::optional<VariableCategory>>(x.v.t)) {
context_.Say(GetContext().clauseSource,
"The argument TOFROM:SCALAR must be specified on the DEFAULTMAP "
"clause"_err_en_US);
auto maybeCategory{std::get<std::optional<VariableCategory>>(x.v.t)};
if (!maybeCategory) {
if (version <= 45) {
context_.Say(GetContext().clauseSource,
"The DEFAULTMAP clause requires a variable-category SCALAR in %s, %s"_warn_en_US,
ThisVersion(version), TryVersion(50));
}
} else {
VariableCategory category{*maybeCategory};
unsigned tryVersion{0};
if (version <= 45 && category != VariableCategory::Scalar) {
tryVersion = 50;
}
if (version < 52 && category == VariableCategory::All) {
tryVersion = 52;
}
if (tryVersion) {
context_.Say(GetContext().clauseSource,
"%s is not allowed in %s, %s"_warn_en_US,
parser::ToUpperCaseLetters(
parser::OmpDefaultmapClause::EnumToString(category)),
ThisVersion(version), TryVersion(tryVersion));
}
}
}

void OmpStructureChecker::Enter(const parser::OmpClause::If &x) {
CheckAllowedClause(llvm::omp::Clause::OMPC_if);
using dirNameModifier = parser::OmpIfClause::DirectiveNameModifier;
Expand Down
8 changes: 8 additions & 0 deletions flang/test/Lower/OpenMP/Todo/defaultmap-clause.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
!RUN: %not_todo_cmd bbc -emit-hlfir -fopenmp -fopenmp-version=45 -o - %s 2>&1 | FileCheck %s
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=45 -o - %s 2>&1 | FileCheck %s

!CHECK: not yet implemented: DEFAULTMAP clause is not implemented yet
subroutine f00
!$omp target defaultmap(tofrom:scalar)
!$omp end target
end
2 changes: 1 addition & 1 deletion flang/test/Lower/OpenMP/Todo/task_detach.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
! `detach` clause
!===============================================================================

! CHECK: not yet implemented: OpenMP Block construct clause
! CHECK: not yet implemented: DETACH clause is not implemented yet
subroutine omp_task_detach()
use omp_lib
integer (kind=omp_event_handle_kind) :: event
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Lower/OpenMP/Todo/task_untied.f90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
! `untied` clause
!===============================================================================

! CHECK: not yet implemented: OpenMP Block construct clause
! CHECK: not yet implemented: UNTIED clause is not implemented yet
subroutine omp_task_untied()
!$omp task untied
call foo()
Expand Down
84 changes: 84 additions & 0 deletions flang/test/Parser/OpenMP/defaultmap-clause.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
!RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=52 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=52 %s | FileCheck --check-prefix="PARSE-TREE" %s

subroutine f00
!$omp target defaultmap(from)
!$omp end target
end

!UNPARSE: SUBROUTINE f00
!UNPARSE: !$OMP TARGET DEFAULTMAP(FROM)
!UNPARSE: !$OMP END TARGET
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target
!PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause
!PARSE-TREE: | | ImplicitBehavior = From
!PARSE-TREE: Block

subroutine f01
!$omp target defaultmap(firstprivate: aggregate)
!$omp end target
end

!UNPARSE: SUBROUTINE f01
!UNPARSE: !$OMP TARGET DEFAULTMAP(FIRSTPRIVATE:AGGREGATE)
!UNPARSE: !$OMP END TARGET
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target
!PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause
!PARSE-TREE: | | ImplicitBehavior = Firstprivate
!PARSE-TREE: | | VariableCategory = Aggregate

subroutine f02
!$omp target defaultmap(alloc: all)
!$omp end target
end

!UNPARSE: SUBROUTINE f02
!UNPARSE: !$OMP TARGET DEFAULTMAP(ALLOC:ALL)
!UNPARSE: !$OMP END TARGET
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target
!PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause
!PARSE-TREE: | | ImplicitBehavior = Alloc
!PARSE-TREE: | | VariableCategory = All

! Both "all" and "allocatable" are valid, and "all" is a prefix of
! "allocatable". Make sure we parse this correctly.
subroutine f03
!$omp target defaultmap(alloc: allocatable)
!$omp end target
end

!UNPARSE: SUBROUTINE f03
!UNPARSE: !$OMP TARGET DEFAULTMAP(ALLOC:ALLOCATABLE)
!UNPARSE: !$OMP END TARGET
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target
!PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause
!PARSE-TREE: | | ImplicitBehavior = Alloc
!PARSE-TREE: | | VariableCategory = Allocatable

subroutine f04
!$omp target defaultmap(tofrom: scalar)
!$omp end target
end

!UNPARSE: SUBROUTINE f04
!UNPARSE: !$OMP TARGET DEFAULTMAP(TOFROM:SCALAR)
!UNPARSE: !$OMP END TARGET
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE: | OmpBlockDirective -> llvm::omp::Directive = target
!PARSE-TREE: | OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause
!PARSE-TREE: | | ImplicitBehavior = Tofrom
!PARSE-TREE: | | VariableCategory = Scalar
12 changes: 6 additions & 6 deletions flang/test/Semantics/OpenMP/combined-constructs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ program main
enddo
!$omp end target parallel

!ERROR: The argument TOFROM:SCALAR must be specified on the DEFAULTMAP clause
!ERROR: The DEFAULTMAP clause requires a variable-category SCALAR in OpenMP v1.1, try -fopenmp-version=50
!$omp target parallel defaultmap(tofrom)
do i = 1, N
a(i) = 3.14
Expand Down Expand Up @@ -80,7 +80,7 @@ program main
enddo
!$omp end target parallel do

!ERROR: The argument TOFROM:SCALAR must be specified on the DEFAULTMAP clause
!ERROR: The DEFAULTMAP clause requires a variable-category SCALAR in OpenMP v1.1, try -fopenmp-version=50
!$omp target parallel do defaultmap(tofrom)
do i = 1, N
a(i) = 3.14
Expand Down Expand Up @@ -140,7 +140,7 @@ program main
enddo
!$omp end target teams

!ERROR: The argument TOFROM:SCALAR must be specified on the DEFAULTMAP clause
!ERROR: The DEFAULTMAP clause requires a variable-category SCALAR in OpenMP v1.1, try -fopenmp-version=50
!$omp target teams defaultmap(tofrom)
do i = 1, N
a(i) = 3.14
Expand Down Expand Up @@ -240,7 +240,7 @@ program main
enddo
!$omp end target teams distribute

!ERROR: The argument TOFROM:SCALAR must be specified on the DEFAULTMAP clause
!ERROR: The DEFAULTMAP clause requires a variable-category SCALAR in OpenMP v1.1, try -fopenmp-version=50
!$omp target teams distribute defaultmap(tofrom)
do i = 1, N
a(i) = 3.14
Expand Down Expand Up @@ -333,7 +333,7 @@ program main
enddo
!$omp end target teams distribute parallel do

!ERROR: The argument TOFROM:SCALAR must be specified on the DEFAULTMAP clause
!ERROR: The DEFAULTMAP clause requires a variable-category SCALAR in OpenMP v1.1, try -fopenmp-version=50
!$omp target teams distribute parallel do defaultmap(tofrom)
do i = 1, N
a(i) = 3.14
Expand Down Expand Up @@ -433,7 +433,7 @@ program main
enddo
!$omp end target teams distribute parallel do simd

!ERROR: The argument TOFROM:SCALAR must be specified on the DEFAULTMAP clause
!ERROR: The DEFAULTMAP clause requires a variable-category SCALAR in OpenMP v1.1, try -fopenmp-version=50
!$omp target teams distribute parallel do simd defaultmap(tofrom)
do i = 1, N
a(i) = 3.14
Expand Down
34 changes: 34 additions & 0 deletions flang/test/Semantics/OpenMP/defaultmap-clause-v45.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=45 -Werror

subroutine f00
!WARNING: The DEFAULTMAP clause requires a variable-category SCALAR in OpenMP v4.5, try -fopenmp-version=50
!$omp target defaultmap(tofrom)
!$omp end target
end

subroutine f01
!WARNING: AGGREGATE is not allowed in OpenMP v4.5, try -fopenmp-version=50
!$omp target defaultmap(tofrom:aggregate)
!$omp end target
end

subroutine f02
!WARNING: FROM is not allowed in OpenMP v4.5, try -fopenmp-version=50
!$omp target defaultmap(from:scalar)
!$omp end target
end

subroutine f03
!WARNING: ALL is not allowed in OpenMP v4.5, try -fopenmp-version=52
!$omp target defaultmap(tofrom:all)
!$omp end target
end

subroutine f04
!WARNING: FROM is not allowed in OpenMP v4.5, try -fopenmp-version=50
!WARNING: POINTER is not allowed in OpenMP v4.5, try -fopenmp-version=50
!$omp target defaultmap(from:pointer)
!$omp end target
end


23 changes: 23 additions & 0 deletions flang/test/Semantics/OpenMP/defaultmap-clause-v50.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=50 -Werror

subroutine f00
!$omp target defaultmap(tofrom)
!$omp end target
end

subroutine f01
!$omp target defaultmap(tofrom:aggregate)
!$omp end target
end

subroutine f02
!$omp target defaultmap(from:scalar)
!$omp end target
end

subroutine f03
!WARNING: ALL is not allowed in OpenMP v5.0, try -fopenmp-version=52
!$omp target defaultmap(tofrom:all)
!$omp end target
end

1 change: 0 additions & 1 deletion flang/test/Semantics/OpenMP/device-constructs.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ program main
enddo
!$omp end target

!ERROR: The argument TOFROM:SCALAR must be specified on the DEFAULTMAP clause
!$omp target defaultmap(tofrom)
do i = 1, N
a = 3.14
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Frontend/OpenMP/ClauseT.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ template <typename T, typename I, typename E> //
struct DefaultmapT {
ENUM(ImplicitBehavior, Alloc, To, From, Tofrom, Firstprivate, None, Default,
Present);
ENUM(VariableCategory, Scalar, Aggregate, Pointer, Allocatable);
ENUM(VariableCategory, All, Scalar, Aggregate, Pointer, Allocatable);
using TupleTrait = std::true_type;
std::tuple<ImplicitBehavior, OPT(VariableCategory)> t;
};
Expand Down
Loading