Skip to content

Commit 86cc364

Browse files
committed
[flang][OpenMP] Fix parsing of ASSUME directive
The ASSUME directive is block-associated and whether the end-directive is optional or not depends on the form of the block. This is all taken care of automatically since the AST node for ASSUME inherits from OmpBlockConstruct.
1 parent 7b467bc commit 86cc364

File tree

8 files changed

+141
-94
lines changed

8 files changed

+141
-94
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ class ParseTreeDumper {
517517
NODE(OmpAppendArgsClause, OmpAppendOp)
518518
NODE(parser, OmpArgument)
519519
NODE(parser, OmpArgumentList)
520-
NODE(parser, OmpAssumeDirective)
521520
NODE(parser, OmpAtClause)
522521
NODE_ENUM(OmpAtClause, ActionTime)
523522
NODE(parser, OmpAtomicDefaultMemOrderClause)
@@ -571,7 +570,6 @@ class ParseTreeDumper {
571570
NODE(parser, OmpDoacrossClause)
572571
NODE(parser, OmpDynGroupprivateClause)
573572
NODE(OmpDynGroupprivateClause, Modifier)
574-
NODE(parser, OmpEndAssumeDirective)
575573
NODE(parser, OmpEndCriticalDirective)
576574
NODE(parser, OmpEndDirective)
577575
NODE(parser, OmpEndLoopDirective)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct ConstructId {
3838
static constexpr llvm::omp::Directive id{Id}; \
3939
}
4040

41-
MAKE_CONSTR_ID(OmpAssumeDirective, D::OMPD_assume);
4241
MAKE_CONSTR_ID(OmpCriticalDirective, D::OMPD_critical);
4342
MAKE_CONSTR_ID(OmpDeclareVariantDirective, D::OMPD_declare_variant);
4443
MAKE_CONSTR_ID(OmpErrorDirective, D::OMPD_error);
@@ -104,8 +103,7 @@ struct DirectiveNameScope {
104103
} else if constexpr (TupleTrait<T>) {
105104
if constexpr (std::is_base_of_v<OmpBlockConstruct, T>) {
106105
return std::get<OmpBeginDirective>(x.t).DirName();
107-
} else if constexpr (std::is_same_v<T, OmpAssumeDirective> ||
108-
std::is_same_v<T, OmpCriticalDirective> ||
106+
} else if constexpr (std::is_same_v<T, OmpCriticalDirective> ||
109107
std::is_same_v<T, OmpDeclareVariantDirective> ||
110108
std::is_same_v<T, OmpErrorDirective> ||
111109
std::is_same_v<T, OmpMetadirectiveDirective> ||

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4835,28 +4835,14 @@ struct OpenMPDeclarativeAssumes {
48354835
CharBlock source;
48364836
};
48374837

4838-
struct OmpAssumeDirective {
4839-
TUPLE_CLASS_BOILERPLATE(OmpAssumeDirective);
4840-
std::tuple<Verbatim, OmpClauseList> t;
4841-
CharBlock source;
4842-
};
4843-
4844-
struct OmpEndAssumeDirective {
4845-
WRAPPER_CLASS_BOILERPLATE(OmpEndAssumeDirective, Verbatim);
4846-
CharBlock source;
4847-
};
4848-
4849-
// Ref: [5.2: 213-216]
4838+
// Ref: [5.1:86-89], [5.2:215], [6.0:369]
48504839
//
4851-
// assume-construct ->
4852-
// ASSUME absent-clause | contains-clause | holds_clause | no-openmp-clause
4853-
// no-openmp-routines-clause | no-parallelism-clause
4854-
// block
4840+
// assume-directive -> // since 5.1
4841+
// ASSUME assumption-clause...
4842+
// block
48554843
// [END ASSUME]
4856-
struct OpenMPAssumeConstruct {
4857-
TUPLE_CLASS_BOILERPLATE(OpenMPAssumeConstruct);
4858-
std::tuple<OmpAssumeDirective, Block, std::optional<OmpEndAssumeDirective>> t;
4859-
CharBlock source;
4844+
struct OpenMPAssumeConstruct : public OmpBlockConstruct {
4845+
INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPAssumeConstruct, OmpBlockConstruct);
48604846
};
48614847

48624848
// 2.7.2 SECTIONS

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,16 +1843,8 @@ TYPE_PARSER(
18431843
Parser<OmpMetadirectiveDirective>{})) /
18441844
endOmpLine))
18451845

1846-
// Assume Construct
1847-
TYPE_PARSER(sourced(construct<OmpAssumeDirective>(
1848-
verbatim("ASSUME"_tok), Parser<OmpClauseList>{})))
1849-
1850-
TYPE_PARSER(sourced(construct<OmpEndAssumeDirective>(
1851-
startOmpLine >> verbatim("END ASSUME"_tok))))
1852-
1853-
TYPE_PARSER(sourced(
1854-
construct<OpenMPAssumeConstruct>(Parser<OmpAssumeDirective>{} / endOmpLine,
1855-
block, maybe(Parser<OmpEndAssumeDirective>{} / endOmpLine))))
1846+
TYPE_PARSER(construct<OpenMPAssumeConstruct>(
1847+
sourced(OmpBlockConstructParser{llvm::omp::Directive::OMPD_assume})))
18561848

18571849
// Block Construct
18581850
#define MakeBlockConstruct(dir) \

flang/lib/Parser/unparse.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,20 +2580,11 @@ class UnparseVisitor {
25802580
Put("\n");
25812581
EndOpenMP();
25822582
}
2583-
void Unparse(const OpenMPAllocatorsConstruct &x) { //
2583+
void Unparse(const OpenMPAllocatorsConstruct &x) {
25842584
Unparse(static_cast<const OmpBlockConstruct &>(x));
25852585
}
2586-
void Unparse(const OmpAssumeDirective &x) {
2587-
BeginOpenMP();
2588-
Word("!$OMP ASSUME");
2589-
Walk(" ", std::get<OmpClauseList>(x.t).v);
2590-
Put("\n");
2591-
EndOpenMP();
2592-
}
2593-
void Unparse(const OmpEndAssumeDirective &x) {
2594-
BeginOpenMP();
2595-
Word("!$OMP END ASSUME\n");
2596-
EndOpenMP();
2586+
void Unparse(const OpenMPAssumeConstruct &x) {
2587+
Unparse(static_cast<const OmpBlockConstruct &>(x));
25972588
}
25982589
void Unparse(const OmpCriticalDirective &x) {
25992590
BeginOpenMP();

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,6 @@ template <typename Checker> struct DirectiveSpellingVisitor {
589589
checker_(GetDirName(x.t).source, Directive::OMPD_allocators);
590590
return false;
591591
}
592-
bool Pre(const parser::OmpAssumeDirective &x) {
593-
checker_(std::get<parser::Verbatim>(x.t).source, Directive::OMPD_assume);
594-
return false;
595-
}
596-
bool Pre(const parser::OmpEndAssumeDirective &x) {
597-
checker_(x.v.source, Directive::OMPD_assume);
598-
return false;
599-
}
600592
bool Pre(const parser::OmpMetadirectiveDirective &x) {
601593
checker_(
602594
std::get<parser::Verbatim>(x.t).source, Directive::OMPD_metadirective);

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
531531
bool Pre(const parser::OpenMPDeclarativeAllocate &);
532532
void Post(const parser::OpenMPDeclarativeAllocate &) { PopContext(); }
533533

534+
bool Pre(const parser::OpenMPAssumeConstruct &);
535+
void Post(const parser::OpenMPAssumeConstruct &) { PopContext(); }
536+
534537
bool Pre(const parser::OpenMPAtomicConstruct &);
535538
void Post(const parser::OpenMPAtomicConstruct &) { PopContext(); }
536539

@@ -2220,6 +2223,11 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPDeclarativeAllocate &x) {
22202223
return false;
22212224
}
22222225

2226+
bool OmpAttributeVisitor::Pre(const parser::OpenMPAssumeConstruct &x) {
2227+
PushContext(x.source, llvm::omp::Directive::OMPD_assume);
2228+
return true;
2229+
}
2230+
22232231
bool OmpAttributeVisitor::Pre(const parser::OpenMPAtomicConstruct &x) {
22242232
PushContext(x.source, llvm::omp::Directive::OMPD_atomic);
22252233
return true;
Lines changed: 121 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,141 @@
1-
! RUN: %flang_fc1 -fopenmp-version=51 -fopenmp -fdebug-unparse-no-sema %s 2>&1 | FileCheck %s
2-
! RUN: %flang_fc1 -fopenmp-version=51 -fopenmp -fdebug-dump-parse-tree-no-sema %s 2>&1 | FileCheck %s --check-prefix="PARSE-TREE"
1+
!RUN: %flang_fc1 -fopenmp-version=51 -fopenmp -fdebug-unparse-no-sema %s | FileCheck --check-prefix="UNPARSE" %s
2+
!RUN: %flang_fc1 -fopenmp-version=51 -fopenmp -fdebug-dump-parse-tree-no-sema %s | FileCheck --check-prefix="PARSE-TREE" %s
3+
34
subroutine sub1
45
integer :: r
5-
!CHECK: !$OMP ASSUME NO_OPENMP
6-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
7-
!PARSE-TREE: Verbatim
8-
!PARSE-TREE: OmpClauseList -> OmpClause -> NoOpenmp
96
!$omp assume no_openmp
10-
!CHECK: !$OMP ASSUME NO_PARALLELISM
11-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
12-
!PARSE-TREE: Verbatim
13-
!PARSE-TREE: OmpClauseList -> OmpClause -> NoParallelism
7+
!$omp end assume
8+
149
!$omp assume no_parallelism
15-
!CHECK: !$OMP ASSUME NO_OPENMP_ROUTINES
16-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
17-
!PARSE-TREE: Verbatim
18-
!PARSE-TREE: OmpClauseList -> OmpClause -> NoOpenmpRoutines
10+
!$omp end assume
11+
1912
!$omp assume no_openmp_routines
20-
!CHECK: !$OMP ASSUME ABSENT(ALLOCATE), CONTAINS(WORKSHARE,TASK)
21-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
22-
!PARSE-TREE: Verbatim
23-
!PARSE-TREE: OmpClauseList -> OmpClause -> Absent -> OmpAbsentClause -> llvm::omp::Directive = allocate
24-
!PARSE-TREE: OmpClause -> Contains -> OmpContainsClause -> llvm::omp::Directive = workshare
25-
!PARSE-TREE: llvm::omp::Directive = task
26-
!$omp assume absent(allocate), contains(workshare, task)
27-
!CHECK: !$OMP ASSUME HOLDS(1==1)
13+
!$omp end assume
14+
15+
!$omp assume absent(allocate), contains(workshare, task)
16+
!$omp end assume
17+
2818
!$omp assume holds(1.eq.1)
19+
!$omp end assume
2920
print *, r
3021
end subroutine sub1
3122

23+
!UNPARSE: SUBROUTINE sub1
24+
!UNPARSE: INTEGER r
25+
!UNPARSE: !$OMP ASSUME NO_OPENMP
26+
!UNPARSE: !$OMP END ASSUME
27+
!UNPARSE: !$OMP ASSUME NO_PARALLELISM
28+
!UNPARSE: !$OMP END ASSUME
29+
!UNPARSE: !$OMP ASSUME NO_OPENMP_ROUTINES
30+
!UNPARSE: !$OMP END ASSUME
31+
!UNPARSE: !$OMP ASSUME ABSENT(ALLOCATE) CONTAINS(WORKSHARE,TASK)
32+
!UNPARSE: !$OMP END ASSUME
33+
!UNPARSE: !$OMP ASSUME HOLDS(1==1)
34+
!UNPARSE: !$OMP END ASSUME
35+
!UNPARSE: PRINT *, r
36+
!UNPARSE: END SUBROUTINE sub1
37+
38+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
39+
!PARSE-TREE: | OmpBeginDirective
40+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
41+
!PARSE-TREE: | | OmpClauseList -> OmpClause -> NoOpenmp
42+
!PARSE-TREE: | | Flags = None
43+
!PARSE-TREE: | Block
44+
!PARSE-TREE: | OmpEndDirective
45+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
46+
!PARSE-TREE: | | OmpClauseList ->
47+
!PARSE-TREE: | | Flags = None
48+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
49+
!PARSE-TREE: | OmpBeginDirective
50+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
51+
!PARSE-TREE: | | OmpClauseList -> OmpClause -> NoParallelism
52+
!PARSE-TREE: | | Flags = None
53+
!PARSE-TREE: | Block
54+
!PARSE-TREE: | OmpEndDirective
55+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
56+
!PARSE-TREE: | | OmpClauseList ->
57+
!PARSE-TREE: | | Flags = None
58+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
59+
!PARSE-TREE: | OmpBeginDirective
60+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
61+
!PARSE-TREE: | | OmpClauseList -> OmpClause -> NoOpenmpRoutines
62+
!PARSE-TREE: | | Flags = None
63+
!PARSE-TREE: | Block
64+
!PARSE-TREE: | OmpEndDirective
65+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
66+
!PARSE-TREE: | | OmpClauseList ->
67+
!PARSE-TREE: | | Flags = None
68+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
69+
!PARSE-TREE: | OmpBeginDirective
70+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
71+
!PARSE-TREE: | | OmpClauseList -> OmpClause -> Absent -> OmpAbsentClause -> llvm::omp::Directive = allocate
72+
!PARSE-TREE: | | OmpClause -> Contains -> OmpContainsClause -> llvm::omp::Directive = workshare
73+
!PARSE-TREE: | | llvm::omp::Directive = task
74+
!PARSE-TREE: | | Flags = None
75+
!PARSE-TREE: | Block
76+
!PARSE-TREE: | OmpEndDirective
77+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
78+
!PARSE-TREE: | | OmpClauseList ->
79+
!PARSE-TREE: | | Flags = None
80+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
81+
!PARSE-TREE: | OmpBeginDirective
82+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
83+
!PARSE-TREE: | | OmpClauseList -> OmpClause -> Holds -> OmpHoldsClause -> Expr -> EQ
84+
!PARSE-TREE: | | | Expr -> LiteralConstant -> IntLiteralConstant = '1'
85+
!PARSE-TREE: | | | Expr -> LiteralConstant -> IntLiteralConstant = '1'
86+
!PARSE-TREE: | | Flags = None
87+
!PARSE-TREE: | Block
88+
!PARSE-TREE: | OmpEndDirective
89+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
90+
!PARSE-TREE: | | OmpClauseList ->
91+
!PARSE-TREE: | | Flags = None
92+
93+
3294
subroutine sub2
3395
integer :: r
3496
integer :: v
35-
!CHECK !$OMP ASSUME NO_OPENMP
36-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
37-
!PARSE-TREE: OmpAssumeDirective
38-
!PARSE-TREE: Verbatim
39-
!PARSE-TREE: OmpClauseList -> OmpClause -> NoOpenmp
40-
!PARSE-TREE: Block
41-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt
42-
!PARSE-TREE: Expr -> Add
43-
!PARSE-TREE: OmpEndAssumeDirective
4497
v = 87
4598
!$omp assume no_openmp
4699
r = r + 1
47-
!CHECK !$OMP END ASSUME
48100
!$omp end assume
49101
end subroutine sub2
50-
102+
103+
!UNPARSE: SUBROUTINE sub2
104+
!UNPARSE: INTEGER r
105+
!UNPARSE: INTEGER v
106+
!UNPARSE: v = 87
107+
!UNPARSE: !$OMP ASSUME NO_OPENMP
108+
!UNPARSE: r = r+1
109+
!UNPARSE: !$OMP END ASSUME
110+
!UNPARSE: END SUBROUTINE sub2
111+
112+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt
113+
!PARSE-TREE: | Variable -> Designator -> DataRef -> Name = 'v'
114+
!PARSE-TREE: | Expr -> LiteralConstant -> IntLiteralConstant = '87'
115+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
116+
!PARSE-TREE: | OmpBeginDirective
117+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
118+
!PARSE-TREE: | | OmpClauseList -> OmpClause -> NoOpenmp
119+
!PARSE-TREE: | | Flags = None
120+
!PARSE-TREE: | Block
121+
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt
122+
!PARSE-TREE: | | | Variable -> Designator -> DataRef -> Name = 'r'
123+
!PARSE-TREE: | | | Expr -> Add
124+
!PARSE-TREE: | | | | Expr -> Designator -> DataRef -> Name = 'r'
125+
!PARSE-TREE: | | | | Expr -> LiteralConstant -> IntLiteralConstant = '1'
126+
!PARSE-TREE: | OmpEndDirective
127+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = assume
128+
!PARSE-TREE: | | OmpClauseList ->
129+
!PARSE-TREE: | | Flags = None
130+
51131
program p
52-
!CHECK !$OMP ASSUMES NO_OPENMP
53-
!PARSE-TREE: SpecificationPart
54-
!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPDeclarativeAssumes
55-
!PARSE-TREE: Verbatim
56-
!PARSE-TREE: OmpClauseList -> OmpClause -> NoOpenmp
57132
!$omp assumes no_openmp
58133
end program p
59-
134+
135+
!UNPARSE: PROGRAM p
136+
!UNPARSE: !$OMP ASSUMES NO_OPENMP
137+
!UNPARSE: END PROGRAM p
138+
139+
!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPDeclarativeAssumes
140+
!PARSE-TREE: | Verbatim
141+
!PARSE-TREE: | OmpClauseList -> OmpClause -> NoOpenmp

0 commit comments

Comments
 (0)