Skip to content

Commit 80beefa

Browse files
authored
[flang][OpenMP] Use OmpDirectiveSpecification in REQUIRES (#160595)
1 parent cdc3061 commit 80beefa

File tree

7 files changed

+45
-18
lines changed

7 files changed

+45
-18
lines changed

flang/include/flang/Parser/openmp-utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ struct ConstructId {
4141
MAKE_CONSTR_ID(OpenMPDeclarativeAllocate, D::OMPD_allocate);
4242
MAKE_CONSTR_ID(OpenMPDeclareReductionConstruct, D::OMPD_declare_reduction);
4343
MAKE_CONSTR_ID(OpenMPExecutableAllocate, D::OMPD_allocate);
44-
MAKE_CONSTR_ID(OpenMPRequiresConstruct, D::OMPD_requires);
4544

4645
#undef MAKE_CONSTR_ID
4746

@@ -94,8 +93,7 @@ struct DirectiveNameScope {
9493
return std::get<OmpBeginDirective>(x.t).DirName();
9594
} else if constexpr (std::is_same_v<T, OpenMPDeclarativeAllocate> ||
9695
std::is_same_v<T, OpenMPDeclareReductionConstruct> ||
97-
std::is_same_v<T, OpenMPExecutableAllocate> ||
98-
std::is_same_v<T, OpenMPRequiresConstruct>) {
96+
std::is_same_v<T, OpenMPExecutableAllocate>) {
9997
return MakeName(std::get<Verbatim>(x.t).source, ConstructId<T>::id);
10098
} else {
10199
return GetFromTuple(

flang/include/flang/Parser/parse-tree.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4991,9 +4991,8 @@ struct OpenMPGroupprivate {
49914991

49924992
// 2.4 requires -> REQUIRES requires-clause[ [ [,] requires-clause]...]
49934993
struct OpenMPRequiresConstruct {
4994-
TUPLE_CLASS_BOILERPLATE(OpenMPRequiresConstruct);
4994+
WRAPPER_CLASS_BOILERPLATE(OpenMPRequiresConstruct, OmpDirectiveSpecification);
49954995
CharBlock source;
4996-
std::tuple<Verbatim, OmpClauseList> t;
49974996
};
49984997

49994998
// 2.15.2 threadprivate -> THREADPRIVATE (variable-name-list)

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,9 @@ TYPE_PARSER(sourced( //
18361836

18371837
// 2.4 Requires construct
18381838
TYPE_PARSER(sourced(construct<OpenMPRequiresConstruct>(
1839-
verbatim("REQUIRES"_tok), Parser<OmpClauseList>{})))
1839+
predicated(OmpDirectiveNameParser{},
1840+
IsDirective(llvm::omp::Directive::OMPD_requires)) >=
1841+
Parser<OmpDirectiveSpecification>{})))
18401842

18411843
// 2.15.2 Threadprivate directive
18421844
TYPE_PARSER(sourced( //

flang/lib/Parser/unparse.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,10 +2594,10 @@ class UnparseVisitor {
25942594
Put("\n");
25952595
EndOpenMP();
25962596
}
2597-
void Unparse(const OpenMPRequiresConstruct &y) {
2597+
void Unparse(const OpenMPRequiresConstruct &x) {
25982598
BeginOpenMP();
2599-
Word("!$OMP REQUIRES ");
2600-
Walk(std::get<OmpClauseList>(y.t));
2599+
Word("!$OMP ");
2600+
Walk(x.v);
26012601
Put("\n");
26022602
EndOpenMP();
26032603
}

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,6 @@ template <typename Checker> struct DirectiveSpellingVisitor {
624624
checker_(x.v.DirName().source, Directive::OMPD_groupprivate);
625625
return false;
626626
}
627-
bool Pre(const parser::OpenMPRequiresConstruct &x) {
628-
checker_(std::get<parser::Verbatim>(x.t).source, Directive::OMPD_requires);
629-
return false;
630-
}
631627
bool Pre(const parser::OmpBeginDirective &x) {
632628
checker_(x.DirName().source, x.DirId());
633629
return false;
@@ -1498,14 +1494,13 @@ void OmpStructureChecker::Leave(const parser::OpenMPDepobjConstruct &x) {
14981494
}
14991495

15001496
void OmpStructureChecker::Enter(const parser::OpenMPRequiresConstruct &x) {
1501-
const auto &dir{std::get<parser::Verbatim>(x.t)};
1502-
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_requires);
1497+
const auto &dirName{x.v.DirName()};
1498+
PushContextAndClauseSets(dirName.source, dirName.v);
15031499

15041500
if (visitedAtomicSource_.empty()) {
15051501
return;
15061502
}
1507-
const auto &clauseList{std::get<parser::OmpClauseList>(x.t)};
1508-
for (const parser::OmpClause &clause : clauseList.v) {
1503+
for (const parser::OmpClause &clause : x.v.Clauses().v) {
15091504
llvm::omp::Clause id{clause.Id()};
15101505
if (id == llvm::omp::Clause::OMPC_atomic_default_mem_order) {
15111506
parser::MessageFormattedText txt(

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
523523
// Gather information from the clauses.
524524
Flags flags;
525525
std::optional<common::OmpMemoryOrderType> memOrder;
526-
for (const auto &clause : std::get<parser::OmpClauseList>(x.t).v) {
526+
for (const parser::OmpClause &clause : x.v.Clauses().v) {
527527
flags |= common::visit(
528528
common::visitors{
529529
[&memOrder](
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
!RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=50 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
2+
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=50 %s | FileCheck --check-prefix="PARSE-TREE" %s
3+
4+
!$omp requires atomic_default_mem_order(seq_cst)
5+
6+
!UNPARSE: !$OMP REQUIRES ATOMIC_DEFAULT_MEM_ORDER(SEQ_CST)
7+
8+
!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPRequiresConstruct -> OmpDirectiveSpecification
9+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = requires
10+
!PARSE-TREE: | OmpClauseList -> OmpClause -> AtomicDefaultMemOrder -> OmpAtomicDefaultMemOrderClause -> OmpMemoryOrderType = Seq_Cst
11+
!PARSE-TREE: | Flags = None
12+
13+
!$omp requires unified_shared_memory unified_address
14+
15+
!UNPARSE: !$OMP REQUIRES UNIFIED_SHARED_MEMORY UNIFIED_ADDRESS
16+
17+
!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPRequiresConstruct -> OmpDirectiveSpecification
18+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = requires
19+
!PARSE-TREE: | OmpClauseList -> OmpClause -> UnifiedSharedMemory
20+
!PARSE-TREE: | OmpClause -> UnifiedAddress
21+
!PARSE-TREE: | Flags = None
22+
23+
!$omp requires dynamic_allocators reverse_offload
24+
25+
!UNPARSE: !$OMP REQUIRES DYNAMIC_ALLOCATORS REVERSE_OFFLOAD
26+
27+
!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPRequiresConstruct -> OmpDirectiveSpecification
28+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = requires
29+
!PARSE-TREE: | OmpClauseList -> OmpClause -> DynamicAllocators
30+
!PARSE-TREE: | OmpClause -> ReverseOffload
31+
!PARSE-TREE: | Flags = None
32+
33+
end

0 commit comments

Comments
 (0)