-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[flang][OpenMP] Add optional argument to requirement clauses #163557
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
Conversation
REQUIRES clauses apply to the compilation unit, which the OpenMP spec defines as the program unit in Fortran. Don't set REQUIRES flags on all containing scopes, only on the containng program unit, where flags coming from different directives are gathered. If we wanted to set the flags on subprograms, we would need to first accummulate all of them, then propagate them down to all subprograms. That is not done as it is not necessary (the containing program unit is always available).
For each program unit, collect the set of requirements from REQUIRES directives in the source, and modules used by the program unit, and add them to the details of the program unit symbol. The requirements in the symbol details as now stored as clauses. Since requirements need to be emitted in the module files as OpenMP directives, this makes the clause emission straightforward via getOpenMPClauseName. Each program unit, including modules, the corresponding symbol will have the transitive closure of the requirements for everything contained or used in that program unit.
OpenMP 6.0 added an optional logical parameter to the requirement clauses (except ATOMIC_DEFAULT_MEM_ORDER) to indicate whether the clause should take effect or not. The parameter defaults to true if not specified. The parameter value is a compile-time constant expression, but it may require folding to get the final value. Since name resolution happens before folding, the argument expression needs to be analyzed by hand. The determination of the value needs to happen during name resolution because the requirement directives need to be available through module files (and the module reader doesn't to semantic checks beyonn name resolution).
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-flang-openmp Author: Krzysztof Parzyszek (kparzysz) ChangesOpenMP 6.0 added an optional logical parameter to the requirement clauses (except ATOMIC_DEFAULT_MEM_ORDER) to indicate whether the clause should take effect or not. The parameter defaults to true if not specified. The parameter value is a compile-time constant expression, but it may require folding to get the final value. Since name resolution happens before folding, the argument expression needs to be analyzed by hand. The determination of the value needs to happen during name resolution because the requirement directives need to be available through module files (and the module reader doesn't to semantic checks beyond name resolution). Patch is 25.45 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/163557.diff 11 Files Affected:
diff --git a/flang/include/flang/Lower/OpenMP/Clauses.h b/flang/include/flang/Lower/OpenMP/Clauses.h
index 5cd196a7869a2..273e61166fd9d 100644
--- a/flang/include/flang/Lower/OpenMP/Clauses.h
+++ b/flang/include/flang/Lower/OpenMP/Clauses.h
@@ -282,6 +282,7 @@ using Replayable = tomp::clause::ReplayableT<TypeTy, IdTy, ExprTy>;
using ReverseOffload = tomp::clause::ReverseOffloadT<TypeTy, IdTy, ExprTy>;
using Safelen = tomp::clause::SafelenT<TypeTy, IdTy, ExprTy>;
using Schedule = tomp::clause::ScheduleT<TypeTy, IdTy, ExprTy>;
+using SelfMaps = tomp::clause::SelfMapsT<TypeTy, IdTy, ExprTy>;
using SeqCst = tomp::clause::SeqCstT<TypeTy, IdTy, ExprTy>;
using Severity = tomp::clause::SeverityT<TypeTy, IdTy, ExprTy>;
using Shared = tomp::clause::SharedT<TypeTy, IdTy, ExprTy>;
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 14885293fd5eb..8854dc2267c8e 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -566,6 +566,7 @@ class ParseTreeDumper {
NODE(OmpDoacross, Sink)
NODE(OmpDoacross, Source)
NODE(parser, OmpDoacrossClause)
+ NODE(parser, OmpDynamicAllocatorsClause)
NODE(parser, OmpDynGroupprivateClause)
NODE(OmpDynGroupprivateClause, Modifier)
NODE(parser, OmpEndDirective)
@@ -659,9 +660,11 @@ class ParseTreeDumper {
NODE(parser, OmpRefModifier)
NODE_ENUM(OmpRefModifier, Value)
NODE(parser, OmpReplayableClause)
+ NODE(parser, OmpReverseOffloadClause)
NODE(parser, OmpScheduleClause)
NODE(OmpScheduleClause, Modifier)
NODE_ENUM(OmpScheduleClause, Kind)
+ NODE(parser, OmpSelfMapsClause)
NODE(parser, OmpSelfModifier)
NODE_ENUM(OmpSelfModifier, Value)
NODE(parser, OmpSeverityClause)
@@ -689,6 +692,8 @@ class ParseTreeDumper {
NODE(parser, OmpTransparentClause)
NODE(parser, OmpTypeNameList)
NODE(parser, OmpTypeSpecifier)
+ NODE(parser, OmpUnifiedAddressClause)
+ NODE(parser, OmpUnifiedSharedMemoryClause)
NODE(parser, OmpUpdateClause)
NODE(parser, OmpUseClause)
NODE(parser, OmpVariableCategory)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index d919b777d7487..18b583669421a 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -337,6 +337,7 @@ using IntConstantExpr = Integer<ConstantExpr>; // R1031
using ScalarLogicalExpr = Scalar<LogicalExpr>;
using ScalarIntExpr = Scalar<IntExpr>;
using ScalarIntConstantExpr = Scalar<IntConstantExpr>;
+using ScalarLogicalConstantExpr = Scalar<Logical<ConstantExpr>>;
using ScalarDefaultCharExpr = Scalar<DefaultCharExpr>;
// R1030 default-char-constant-expr is used in the Standard only as part of
// scalar-default-char-constant-expr.
@@ -4414,6 +4415,16 @@ struct OmpDeviceTypeClause {
WRAPPER_CLASS_BOILERPLATE(OmpDeviceTypeClause, DeviceTypeDescription);
};
+// Ref: [5.0:60-63], [5.1:83-86], [5.2:212-213], [6.0:356-362]
+//
+// dynamic-allocators-clause ->
+// DYNAMIC_ALLOCATORS // since 5.0
+// [(scalar-logical-const-expr)] // since 6.0
+struct OmpDynamicAllocatorsClause {
+ WRAPPER_CLASS_BOILERPLATE(
+ OmpDynamicAllocatorsClause, ScalarLogicalConstantExpr);
+};
+
struct OmpDynGroupprivateClause {
TUPLE_CLASS_BOILERPLATE(OmpDynGroupprivateClause);
MODIFIER_BOILERPLATE(OmpAccessGroup, OmpPrescriptiveness);
@@ -4690,7 +4701,16 @@ struct OmpReductionClause {
// replayable-clause ->
// REPLAYABLE[(replayable-expression)] // since 6.0
struct OmpReplayableClause {
- WRAPPER_CLASS_BOILERPLATE(OmpReplayableClause, Scalar<Logical<ConstantExpr>>);
+ WRAPPER_CLASS_BOILERPLATE(OmpReplayableClause, ScalarLogicalConstantExpr);
+};
+
+// Ref: [5.0:60-63], [5.1:83-86], [5.2:212-213], [6.0:356-362]
+//
+// reverse-offload-clause ->
+// REVERSE_OFFLOAD // since 5.0
+// [(scalar-logical-const-expr)] // since 6.0
+struct OmpReverseOffloadClause {
+ WRAPPER_CLASS_BOILERPLATE(OmpReverseOffloadClause, ScalarLogicalConstantExpr);
};
// Ref: [4.5:56-63], [5.0:101-109], [5.1:126-133], [5.2:252-254]
@@ -4708,6 +4728,14 @@ struct OmpScheduleClause {
std::tuple<MODIFIERS(), Kind, std::optional<ScalarIntExpr>> t;
};
+// ref: [6.0:361-362]
+//
+// self-maps-clause ->
+// SELF_MAPS [(scalar-logical-const-expr)] // since 6.0
+struct OmpSelfMapsClause {
+ WRAPPER_CLASS_BOILERPLATE(OmpSelfMapsClause, ScalarLogicalConstantExpr);
+};
+
// REF: [5.2:217]
// severity-clause ->
// SEVERITY(warning|fatal)
@@ -4750,6 +4778,25 @@ struct OmpTransparentClause {
WRAPPER_CLASS_BOILERPLATE(OmpTransparentClause, ScalarIntExpr);
};
+// Ref: [5.0:60-63], [5.1:83-86], [5.2:212-213], [6.0:356-362]
+//
+// unified-address-clause ->
+// UNIFIED_ADDRESS // since 5.0
+// [(scalar-logical-const-expr)] // since 6.0
+struct OmpUnifiedAddressClause {
+ WRAPPER_CLASS_BOILERPLATE(OmpUnifiedAddressClause, ScalarLogicalConstantExpr);
+};
+
+// Ref: [5.0:60-63], [5.1:83-86], [5.2:212-213], [6.0:356-362]
+//
+// unified-shared-memory-clause ->
+// UNIFIED_SHARED_MEMORY // since 5.0
+// [(scalar-logical-const-expr)] // since 6.0
+struct OmpUnifiedSharedMemoryClause {
+ WRAPPER_CLASS_BOILERPLATE(
+ OmpUnifiedSharedMemoryClause, ScalarLogicalConstantExpr);
+};
+
// Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322]
//
// In ATOMIC construct
diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp
index fac37a372caaf..60e569efa964a 100644
--- a/flang/lib/Lower/OpenMP/Clauses.cpp
+++ b/flang/lib/Lower/OpenMP/Clauses.cpp
@@ -219,7 +219,6 @@ MAKE_EMPTY_CLASS(AcqRel, AcqRel);
MAKE_EMPTY_CLASS(Acquire, Acquire);
MAKE_EMPTY_CLASS(Capture, Capture);
MAKE_EMPTY_CLASS(Compare, Compare);
-MAKE_EMPTY_CLASS(DynamicAllocators, DynamicAllocators);
MAKE_EMPTY_CLASS(Full, Full);
MAKE_EMPTY_CLASS(Inbranch, Inbranch);
MAKE_EMPTY_CLASS(Mergeable, Mergeable);
@@ -235,13 +234,9 @@ MAKE_EMPTY_CLASS(OmpxBare, OmpxBare);
MAKE_EMPTY_CLASS(Read, Read);
MAKE_EMPTY_CLASS(Relaxed, Relaxed);
MAKE_EMPTY_CLASS(Release, Release);
-MAKE_EMPTY_CLASS(ReverseOffload, ReverseOffload);
MAKE_EMPTY_CLASS(SeqCst, SeqCst);
-MAKE_EMPTY_CLASS(SelfMaps, SelfMaps);
MAKE_EMPTY_CLASS(Simd, Simd);
MAKE_EMPTY_CLASS(Threads, Threads);
-MAKE_EMPTY_CLASS(UnifiedAddress, UnifiedAddress);
-MAKE_EMPTY_CLASS(UnifiedSharedMemory, UnifiedSharedMemory);
MAKE_EMPTY_CLASS(Unknown, Unknown);
MAKE_EMPTY_CLASS(Untied, Untied);
MAKE_EMPTY_CLASS(Weak, Weak);
@@ -775,7 +770,18 @@ Doacross make(const parser::OmpClause::Doacross &inp,
return makeDoacross(inp.v.v, semaCtx);
}
-// DynamicAllocators: empty
+DynamicAllocators make(const parser::OmpClause::DynamicAllocators &inp,
+ semantics::SemanticsContext &semaCtx) {
+ // inp.v -> td::optional<arser::OmpDynamicAllocatorsClause>
+ auto &&maybeRequired = maybeApply(
+ [&](const parser::OmpDynamicAllocatorsClause &c) {
+ return makeExpr(c.v, semaCtx);
+ },
+ inp.v);
+
+ return DynamicAllocators{/*Required=*/std::move(maybeRequired)};
+}
+
DynGroupprivate make(const parser::OmpClause::DynGroupprivate &inp,
semantics::SemanticsContext &semaCtx) {
@@ -1321,7 +1327,18 @@ Reduction make(const parser::OmpClause::Reduction &inp,
// Relaxed: empty
// Release: empty
-// ReverseOffload: empty
+
+ReverseOffload make(const parser::OmpClause::ReverseOffload &inp,
+ semantics::SemanticsContext &semaCtx) {
+ // inp.v -> std::optional<parser::OmpReverseOffloadClause>
+ auto &&maybeRequired = maybeApply(
+ [&](const parser::OmpReverseOffloadClause &c) {
+ return makeExpr(c.v, semaCtx);
+ },
+ inp.v);
+
+ return ReverseOffload{/*Required=*/std::move(maybeRequired)};
+}
Safelen make(const parser::OmpClause::Safelen &inp,
semantics::SemanticsContext &semaCtx) {
@@ -1374,6 +1391,18 @@ Schedule make(const parser::OmpClause::Schedule &inp,
// SeqCst: empty
+SelfMaps make(const parser::OmpClause::SelfMaps &inp,
+ semantics::SemanticsContext &semaCtx) {
+ // inp.v -> std::optional<parser::OmpSelfMapsClause>
+ auto &&maybeRequired = maybeApply(
+ [&](const parser::OmpSelfMapsClause &c) {
+ return makeExpr(c.v, semaCtx);
+ },
+ inp.v);
+
+ return SelfMaps{/*Required=*/std::move(maybeRequired)};
+}
+
Severity make(const parser::OmpClause::Severity &inp,
semantics::SemanticsContext &semaCtx) {
// inp -> empty
@@ -1463,8 +1492,29 @@ To make(const parser::OmpClause::To &inp,
/*LocatorList=*/makeObjects(t3, semaCtx)}};
}
-// UnifiedAddress: empty
-// UnifiedSharedMemory: empty
+UnifiedAddress make(const parser::OmpClause::UnifiedAddress &inp,
+ semantics::SemanticsContext &semaCtx) {
+ // inp.v -> std::optional<parser::OmpUnifiedAddressClause>
+ auto &&maybeRequired = maybeApply(
+ [&](const parser::OmpUnifiedAddressClause &c) {
+ return makeExpr(c.v, semaCtx);
+ },
+ inp.v);
+
+ return UnifiedAddress{/*Required=*/std::move(maybeRequired)};
+}
+
+UnifiedSharedMemory make(const parser::OmpClause::UnifiedSharedMemory &inp,
+ semantics::SemanticsContext &semaCtx) {
+ // inp.v -> std::optional<parser::OmpUnifiedSharedMemoryClause>
+ auto &&maybeRequired = maybeApply(
+ [&](const parser::OmpUnifiedSharedMemoryClause &c) {
+ return makeExpr(c.v, semaCtx);
+ },
+ inp.v);
+
+ return UnifiedSharedMemory{/*Required=*/std::move(maybeRequired)};
+}
Uniform make(const parser::OmpClause::Uniform &inp,
semantics::SemanticsContext &semaCtx) {
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 9507021057476..0a70930a0db33 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -1158,7 +1158,8 @@ TYPE_PARSER( //
"DOACROSS" >>
construct<OmpClause>(parenthesized(Parser<OmpDoacrossClause>{})) ||
"DYNAMIC_ALLOCATORS" >>
- construct<OmpClause>(construct<OmpClause::DynamicAllocators>()) ||
+ construct<OmpClause>(construct<OmpClause::DynamicAllocators>(
+ maybe(parenthesized(scalarLogicalConstantExpr)))) ||
"DYN_GROUPPRIVATE" >>
construct<OmpClause>(construct<OmpClause::DynGroupprivate>(
parenthesized(Parser<OmpDynGroupprivateClause>{}))) ||
@@ -1270,12 +1271,15 @@ TYPE_PARSER( //
"REPLAYABLE" >> construct<OmpClause>(construct<OmpClause::Replayable>(
maybe(parenthesized(Parser<OmpReplayableClause>{})))) ||
"REVERSE_OFFLOAD" >>
- construct<OmpClause>(construct<OmpClause::ReverseOffload>()) ||
+ construct<OmpClause>(construct<OmpClause::ReverseOffload>(
+ maybe(parenthesized(scalarLogicalConstantExpr)))) ||
"SAFELEN" >> construct<OmpClause>(construct<OmpClause::Safelen>(
parenthesized(scalarIntConstantExpr))) ||
"SCHEDULE" >> construct<OmpClause>(construct<OmpClause::Schedule>(
parenthesized(Parser<OmpScheduleClause>{}))) ||
"SEQ_CST" >> construct<OmpClause>(construct<OmpClause::SeqCst>()) ||
+ "SELF_MAPS" >> construct<OmpClause>(construct<OmpClause::SelfMaps>(
+ maybe(parenthesized(scalarLogicalConstantExpr)))) ||
"SEVERITY" >> construct<OmpClause>(construct<OmpClause::Severity>(
parenthesized(Parser<OmpSeverityClause>{}))) ||
"SHARED" >> construct<OmpClause>(construct<OmpClause::Shared>(
@@ -1303,9 +1307,11 @@ TYPE_PARSER( //
construct<OmpClause>(construct<OmpClause::UseDeviceAddr>(
parenthesized(Parser<OmpObjectList>{}))) ||
"UNIFIED_ADDRESS" >>
- construct<OmpClause>(construct<OmpClause::UnifiedAddress>()) ||
+ construct<OmpClause>(construct<OmpClause::UnifiedAddress>(
+ maybe(parenthesized(scalarLogicalConstantExpr)))) ||
"UNIFIED_SHARED_MEMORY" >>
- construct<OmpClause>(construct<OmpClause::UnifiedSharedMemory>()) ||
+ construct<OmpClause>(construct<OmpClause::UnifiedSharedMemory>(
+ maybe(parenthesized(scalarLogicalConstantExpr)))) ||
"UNIFORM" >> construct<OmpClause>(construct<OmpClause::Uniform>(
parenthesized(nonemptyList(name)))) ||
"UNTIED" >> construct<OmpClause>(construct<OmpClause::Untied>()) ||
diff --git a/flang/lib/Semantics/check-omp-structure.cpp b/flang/lib/Semantics/check-omp-structure.cpp
index d65a89e768466..1c27df18fba20 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1517,19 +1517,42 @@ void OmpStructureChecker::Leave(const parser::OpenMPDepobjConstruct &x) {
void OmpStructureChecker::Enter(const parser::OpenMPRequiresConstruct &x) {
const auto &dirName{x.v.DirName()};
PushContextAndClauseSets(dirName.source, dirName.v);
+ unsigned version{context_.langOptions().OpenMPVersion};
- if (visitedAtomicSource_.empty()) {
- return;
- }
for (const parser::OmpClause &clause : x.v.Clauses().v) {
llvm::omp::Clause id{clause.Id()};
if (id == llvm::omp::Clause::OMPC_atomic_default_mem_order) {
- parser::MessageFormattedText txt(
- "REQUIRES directive with '%s' clause found lexically after atomic operation without a memory order clause"_err_en_US,
- parser::ToUpperCaseLetters(llvm::omp::getOpenMPClauseName(id)));
- parser::Message message(clause.source, txt);
- message.Attach(visitedAtomicSource_, "Previous atomic construct"_en_US);
- context_.Say(std::move(message));
+ if (!visitedAtomicSource_.empty()) {
+ parser::MessageFormattedText txt(
+ "REQUIRES directive with '%s' clause found lexically after atomic operation without a memory order clause"_err_en_US,
+ parser::ToUpperCaseLetters(llvm::omp::getOpenMPClauseName(id)));
+ parser::Message message(clause.source, txt);
+ message.Attach(visitedAtomicSource_, "Previous atomic construct"_en_US);
+ context_.Say(std::move(message));
+ }
+ } else {
+ bool hasArgument{common::visit(
+ [&](auto &&s) {
+ using TypeS = llvm::remove_cvref_t<decltype(s)>;
+ if constexpr ( //
+ std::is_same_v<TypeS, parser::OmpClause::DynamicAllocators> ||
+ std::is_same_v<TypeS, parser::OmpClause::ReverseOffload> ||
+ std::is_same_v<TypeS, parser::OmpClause::SelfMaps> ||
+ std::is_same_v<TypeS, parser::OmpClause::UnifiedAddress> ||
+ std::is_same_v<TypeS, parser::OmpClause::UnifiedSharedMemory>) {
+ return s.v.has_value();
+ } else {
+ return false;
+ }
+ },
+ clause.u)};
+ if (version < 60 && hasArgument) {
+ context_.Say(clause.source,
+ "An argument to %s is an %s feature, %s"_warn_en_US,
+ parser::ToUpperCaseLetters(
+ llvm::omp::getOpenMPClauseName(clause.Id())),
+ ThisVersion(60), TryVersion(60));
+ }
}
}
}
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 122849356ca39..7067ed3d99286 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -557,6 +557,21 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
using RequiresClauses = WithOmpDeclarative::RequiresClauses;
PushContext(x.source, llvm::omp::Directive::OMPD_requires);
+ auto getArgument{[&](auto &&maybeClause) {
+ if (maybeClause) {
+ // Scalar<Logical<Constant<common::Indirection<Expr>>>>
+ auto &parserExpr{maybeClause->v.thing.thing.thing.value()};
+ evaluate::ExpressionAnalyzer ea{context_};
+ if (auto &&maybeExpr{ea.Analyze(parserExpr)}) {
+ if (auto v{omp::GetLogicalValue(*maybeExpr)}) {
+ return *v;
+ }
+ }
+ }
+ // If the argument is missing, it is assumed to be true.
+ return true;
+ }};
+
// Gather information from the clauses.
RequiresClauses reqs;
const common::OmpMemoryOrderType *memOrder{nullptr};
@@ -573,16 +588,19 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
if constexpr ( //
std::is_same_v<TypeS, OmpClause::DynamicAllocators> ||
std::is_same_v<TypeS, OmpClause::ReverseOffload> ||
+ std::is_same_v<TypeS, OmpClause::SelfMaps> ||
std::is_same_v<TypeS, OmpClause::UnifiedAddress> ||
std::is_same_v<TypeS, OmpClause::UnifiedSharedMemory>) {
- return RequiresClauses{clause.Id()};
- } else {
- return RequiresClauses{};
+ if (getArgument(s.v)) {
+ return RequiresClauses{clause.Id()};
+ }
}
+ return RequiresClauses{};
},
},
clause.u);
}
+
// Merge clauses into parents' symbols details.
AddOmpRequiresToScope(currScope(), &reqs, memOrder);
return true;
diff --git a/flang/test/Parser/OpenMP/requires.f90 b/flang/test/Parser/OpenMP/requires.f90
index 6cbb06eaf93c0..8169403835705 100644
--- a/flang/test/Parser/OpenMP/requires.f90
+++ b/flang/test/Parser/OpenMP/requires.f90
@@ -30,4 +30,18 @@
!PARSE-TREE: | OmpClause -> ReverseOffload
!PARSE-TREE: | Flags = None
+!$omp requires self_maps(.true.) unified_address(.false.)
+
+!UNPARSE: !$OMP REQUIRES SELF_MAPS(.true._4) UNIFIED_ADDRESS(.false._4)
+
+!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPRequiresConstruct -> OmpDirectiveSpecification
+!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = requires
+!PARSE-TREE: | OmpClauseList -> OmpClause -> SelfMaps -> OmpSelfMapsClause -> Scalar -> Logical -> Constant -> Expr = '.true._4'
+!PARSE-TREE: | | LiteralConstant -> LogicalLiteralConstant
+!PARSE-TREE: | | | bool = 'true'
+!PARSE-TREE: | OmpClause -> UnifiedAddress -> OmpUnifiedAddressClause -> Scalar -> Logical -> Constant -> Expr = '.false._4'
+!PARSE-TREE: | | LiteralConstant -> LogicalLiteralConstant
+!PARSE-TREE: | | | bool = 'false'
+!PARSE-TREE: | Flags = None
+
end
diff --git a/flang/test/Semantics/OpenMP/requires10.f90 b/flang/test/Semantics/OpenMP/requires10.f90
new file mode 100644
index 0000000000000..9f9832da3726e
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/requires10.f90
@@ -0,0 +1,13 @@
+!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=52
+
+subroutine f00(x)
+ logical :: x
+ !ERROR: An argument to REVERSE_OFFLOAD is an OpenMP v6.0 feature, try -fopenmp-version=60
+ !ERROR: Must be a constant value
+ !$omp requires reverse_offload(x)
+end
+
+subroutine f01
+ !WARNING: An argument to REVERSE_OFFLOAD is an OpenMP v6.0 feature, try -fopenmp-version=60
+ !$omp requires reverse_offload(.true.)
+end
diff --git a/llvm/include/llvm/Frontend/OpenMP/ClauseT.h b/llvm/include/llvm/Frontend/OpenMP/ClauseT.h
index db781b58944bc..9153dd1c56b7f 100644
--- a/llvm/include/llvm/Frontend/OpenMP/ClauseT.h
+++ b/llvm/include/llvm/Frontend/OpenMP/ClauseT.h
@@ -571,7 +571,9 @@ struct DoacrossT {
// V5.2: [8.2.1] `requirement` clauses
template <typename T, typename I, typename E> //
struct DynamicAllocatorsT {
- using EmptyTrait = std::true_type;
+ using Requires = E;
+ using WrapperTrait = std::true_type;
+ OPT(Requires) v;
};
template <typename T, typename I, typename E> //
@@ -1055,7 +1057,9 @@ struct ReplayableT {
// V5.2: [8.2.1] `requirement` clauses
template <typename T, typename I, typename E> //
struct ReverseOffloadT {
- using EmptyTrait = std::true_type;
+ using Requires = E;
+ using WrapperTrait = std::true_type;
+ OPT(Requires) v;
};
// V5.2: [10.4.2] `safelen` clause
@@ -1077,6 +1081,14 @@ struct ScheduleT {
std::tuple<Kind, OPT(OrderingModifier), OPT(ChunkModifier), OPT(ChunkSize)> t;
};
+// [6.0:361]
+template <typename T, typename I, typename E> //
+struct SelfMapsT {
+ using Requires = E;
+ using WrapperTrait = std::true_type;
+ OPT(Requires) v;
+};
+
// V5.2: [15.8.1] Memory-order clauses
templa...
[truncated]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
nit: If I understand correctly, we won't generate a requires statement in a module file when this evaluates to .false.. Please could you add a test for that. Also a test (could be the same one) that demonstrates that we do resolve at least trivial compile time expressions.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/17617 Here is the relevant piece of the build log for the reference
|
OpenMP 6.0 added an optional logical parameter to the requirement clauses (except ATOMIC_DEFAULT_MEM_ORDER) to indicate whether the clause should take effect or not. The parameter defaults to true if not specified.
The parameter value is a compile-time constant expression, but it may require folding to get the final value. Since name resolution happens before folding, the argument expression needs to be analyzed by hand. The determination of the value needs to happen during name resolution because the requirement directives need to be available through module files (and the module reader doesn't to semantic checks beyond name resolution).