Skip to content

Commit df859f9

Browse files
authored
[flang][OpenMP] Frontend support for NOTHING directive (#120606)
Create OpenMPUtilityConstruct and put the two utility directives in it (error and nothing). Rename OpenMPErrorConstruct to OmpErrorDirective.
1 parent e576c5b commit df859f9

File tree

11 files changed

+75
-28
lines changed

11 files changed

+75
-28
lines changed

flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ SourcePosition OpenMPCounterVisitor::getLocation(const OpenMPConstruct &c) {
9090
const CharBlock &source{c.source};
9191
return (parsing->allCooked().GetSourcePositionRange(source))->first;
9292
},
93+
[&](const OpenMPUtilityConstruct &c) -> SourcePosition {
94+
const CharBlock &source{c.source};
95+
return (parsing->allCooked().GetSourcePositionRange(source))->first;
96+
},
9397
},
9498
c.u);
9599
}
@@ -143,8 +147,8 @@ std::string OpenMPCounterVisitor::getName(const OpenMPConstruct &c) {
143147
},
144148
c.u);
145149
},
146-
[&](const OpenMPErrorConstruct &c) -> std::string {
147-
const CharBlock &source{std::get<0>(c.t).source};
150+
[&](const OpenMPUtilityConstruct &c) -> std::string {
151+
const CharBlock &source{c.source};
148152
return normalize_construct_name(source.ToString());
149153
},
150154
[&](const OpenMPSectionConstruct &c) -> std::string {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ class ParseTreeDumper {
516516
#include "llvm/Frontend/OpenMP/OMP.inc"
517517
NODE(parser, OmpClauseList)
518518
NODE(parser, OmpCriticalDirective)
519+
NODE(parser, OmpErrorDirective)
520+
NODE(parser, OmpNothingDirective)
519521
NODE(parser, OmpDeclareTargetSpecifier)
520522
NODE(parser, OmpDeclareTargetWithClause)
521523
NODE(parser, OmpDeclareTargetWithList)
@@ -662,7 +664,7 @@ class ParseTreeDumper {
662664
NODE(parser, OmpAtomicDefaultMemOrderClause)
663665
NODE_ENUM(common, OmpAtomicDefaultMemOrderType)
664666
NODE(parser, OpenMPDepobjConstruct)
665-
NODE(parser, OpenMPErrorConstruct)
667+
NODE(parser, OpenMPUtilityConstruct)
666668
NODE(parser, OpenMPFlushConstruct)
667669
NODE(parser, OpenMPLoopConstruct)
668670
NODE(parser, OpenMPExecutableAllocate)

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4182,6 +4182,30 @@ struct OmpClauseList {
41824182

41834183
// --- Directives and constructs
41844184

4185+
// Ref: [5.1:89-90], [5.2:216]
4186+
//
4187+
// nothing-directive ->
4188+
// NOTHING // since 5.1
4189+
struct OmpNothingDirective {
4190+
using EmptyTrait = std::true_type;
4191+
COPY_AND_ASSIGN_BOILERPLATE(OmpNothingDirective);
4192+
CharBlock source;
4193+
};
4194+
4195+
// Ref: OpenMP [5.2:216-218]
4196+
// ERROR AT(compilation|execution) SEVERITY(fatal|warning) MESSAGE("msg-str)
4197+
struct OmpErrorDirective {
4198+
TUPLE_CLASS_BOILERPLATE(OmpErrorDirective);
4199+
CharBlock source;
4200+
std::tuple<Verbatim, OmpClauseList> t;
4201+
};
4202+
4203+
struct OpenMPUtilityConstruct {
4204+
UNION_CLASS_BOILERPLATE(OpenMPUtilityConstruct);
4205+
CharBlock source;
4206+
std::variant<OmpErrorDirective, OmpNothingDirective> u;
4207+
};
4208+
41854209
// 2.7.2 SECTIONS
41864210
// 2.11.2 PARALLEL SECTIONS
41874211
struct OmpSectionsDirective {
@@ -4506,14 +4530,6 @@ struct OpenMPDepobjConstruct {
45064530
std::tuple<Verbatim, OmpObject, OmpClause> t;
45074531
};
45084532

4509-
// Ref: OpenMP [5.2:216-218]
4510-
// ERROR AT(compilation|execution) SEVERITY(fatal|warning) MESSAGE("msg-str)
4511-
struct OpenMPErrorConstruct {
4512-
TUPLE_CLASS_BOILERPLATE(OpenMPErrorConstruct);
4513-
CharBlock source;
4514-
std::tuple<Verbatim, OmpClauseList> t;
4515-
};
4516-
45174533
// 2.17.8 flush -> FLUSH [memory-order-clause] [(variable-name-list)]
45184534
struct OpenMPFlushConstruct {
45194535
TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
@@ -4586,7 +4602,7 @@ struct OpenMPConstruct {
45864602
UNION_CLASS_BOILERPLATE(OpenMPConstruct);
45874603
std::variant<OpenMPStandaloneConstruct, OpenMPSectionsConstruct,
45884604
OpenMPSectionConstruct, OpenMPLoopConstruct, OpenMPBlockConstruct,
4589-
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPErrorConstruct,
4605+
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPUtilityConstruct,
45904606
OpenMPExecutableAllocate, OpenMPAllocatorsConstruct,
45914607
OpenMPCriticalConstruct>
45924608
u;

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,8 +2907,8 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
29072907
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
29082908
semantics::SemanticsContext &semaCtx,
29092909
lower::pft::Evaluation &eval,
2910-
const parser::OpenMPErrorConstruct &) {
2911-
TODO(converter.getCurrentLocation(), "OpenMPErrorConstruct");
2910+
const parser::OpenMPUtilityConstruct &) {
2911+
TODO(converter.getCurrentLocation(), "OpenMPUtilityConstruct");
29122912
}
29132913

29142914
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,20 @@ TYPE_PARSER(
737737
TYPE_PARSER(sourced(construct<OmpClauseList>(
738738
many(maybe(","_tok) >> sourced(Parser<OmpClause>{})))))
739739

740-
// 2.1 (variable | /common-block | array-sections)
740+
// 2.1 (variable | /common-block/ | array-sections)
741741
TYPE_PARSER(construct<OmpObjectList>(nonemptyList(Parser<OmpObject>{})))
742742

743+
TYPE_PARSER(sourced(construct<OmpErrorDirective>(
744+
verbatim("ERROR"_tok), Parser<OmpClauseList>{})))
745+
746+
TYPE_PARSER(sourced(construct<OmpNothingDirective>("NOTHING" >> ok)))
747+
748+
TYPE_PARSER(sourced(construct<OpenMPUtilityConstruct>(
749+
sourced(construct<OpenMPUtilityConstruct>(
750+
sourced(Parser<OmpErrorDirective>{}))) ||
751+
sourced(construct<OpenMPUtilityConstruct>(
752+
sourced(Parser<OmpNothingDirective>{}))))))
753+
743754
// Omp directives enclosing do loop
744755
TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
745756
"DISTRIBUTE PARALLEL DO SIMD" >>
@@ -1027,9 +1038,6 @@ TYPE_PARSER(sourced(construct<OmpCriticalDirective>(verbatim("CRITICAL"_tok),
10271038
TYPE_PARSER(construct<OpenMPCriticalConstruct>(
10281039
Parser<OmpCriticalDirective>{}, block, Parser<OmpEndCriticalDirective>{}))
10291040

1030-
TYPE_PARSER(sourced(construct<OpenMPErrorConstruct>(
1031-
verbatim("ERROR"_tok), Parser<OmpClauseList>{})))
1032-
10331041
// 2.11.3 Executable Allocate directive
10341042
TYPE_PARSER(
10351043
sourced(construct<OpenMPExecutableAllocate>(verbatim("ALLOCATE"_tok),
@@ -1127,7 +1135,7 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
11271135
// OpenMPStandaloneConstruct to resolve !$OMP ORDERED
11281136
construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}),
11291137
construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}),
1130-
construct<OpenMPConstruct>(Parser<OpenMPErrorConstruct>{}),
1138+
construct<OpenMPConstruct>(Parser<OpenMPUtilityConstruct>{}),
11311139
construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
11321140
construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
11331141
construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),

flang/lib/Parser/unparse.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2710,11 +2710,15 @@ class UnparseVisitor {
27102710
Walk(x.v);
27112711
return false;
27122712
}
2713-
void Unparse(const OpenMPErrorConstruct &x) {
2713+
void Unparse(const OmpErrorDirective &x) {
27142714
Word("!$OMP ERROR ");
27152715
Walk(x.t);
27162716
Put("\n");
27172717
}
2718+
void Unparse(const OmpNothingDirective &x) {
2719+
Word("!$OMP NOTHING");
2720+
Put("\n");
2721+
}
27182722
void Unparse(const OmpSectionsDirective &x) {
27192723
switch (x.v) {
27202724
case llvm::omp::Directive::OMPD_sections:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,12 +1688,12 @@ void OmpStructureChecker::Leave(const parser::OpenMPDeclareTargetConstruct &x) {
16881688
dirContext_.pop_back();
16891689
}
16901690

1691-
void OmpStructureChecker::Enter(const parser::OpenMPErrorConstruct &x) {
1691+
void OmpStructureChecker::Enter(const parser::OmpErrorDirective &x) {
16921692
const auto &dir{std::get<parser::Verbatim>(x.t)};
16931693
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_error);
16941694
}
16951695

1696-
void OmpStructureChecker::Leave(const parser::OpenMPErrorConstruct &x) {
1696+
void OmpStructureChecker::Leave(const parser::OmpErrorDirective &x) {
16971697
dirContext_.pop_back();
16981698
}
16991699

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ class OmpStructureChecker
102102
void Enter(const parser::OmpDeclareTargetWithList &);
103103
void Enter(const parser::OmpDeclareTargetWithClause &);
104104
void Leave(const parser::OmpDeclareTargetWithClause &);
105-
void Enter(const parser::OpenMPErrorConstruct &);
106-
void Leave(const parser::OpenMPErrorConstruct &);
105+
void Enter(const parser::OmpErrorDirective &);
106+
void Leave(const parser::OmpErrorDirective &);
107107
void Enter(const parser::OpenMPExecutableAllocate &);
108108
void Leave(const parser::OpenMPExecutableAllocate &);
109109
void Enter(const parser::OpenMPAllocatorsConstruct &);

flang/test/Lower/OpenMP/Todo/error.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -fopenmp-version=51 -o - %s 2>&1 | FileCheck %s
22

3-
! CHECK: not yet implemented: OpenMPErrorConstruct
3+
! CHECK: not yet implemented: OpenMPUtilityConstruct
44
program p
55
integer, allocatable :: x
66
!$omp error at(compilation) severity(warning) message("an error")

flang/test/Parser/OpenMP/error-unparse.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
program main
44
character(*), parameter :: message = "This is an error"
55
!CHECK: !$OMP ERROR AT(COMPILATION) SEVERITY(WARNING) MESSAGE("some message here")
6-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPErrorConstruct
6+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPUtilityConstruct -> OmpErrorDirective
77
!PARSE-TREE: OmpClauseList -> OmpClause -> At -> OmpAtClause -> ActionTime = Compilation
88
!PARSE-TREE: OmpClause -> Severity -> OmpSeverityClause -> Severity = Warning
99
!PARSE-TREE: OmpClause -> Message -> OmpMessageClause -> Expr -> LiteralConstant -> CharLiteralConstant
1010
!$omp error at(compilation) severity(warning) message("some message here")
1111
!CHECK: !$OMP ERROR AT(COMPILATION) SEVERITY(FATAL) MESSAGE(message)
12-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPErrorConstruct
12+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPUtilityConstruct -> OmpErrorDirective
1313
!PARSE-TREE: OmpClauseList -> OmpClause -> At -> OmpAtClause -> ActionTime = Compilation
1414
!PARSE-TREE: OmpClause -> Severity -> OmpSeverityClause -> Severity = Fatal
1515
!PARSE-TREE: OmpClause -> Message -> OmpMessageClause -> Expr -> Designator -> DataRef -> Name = 'message'
1616
!$omp error at(compilation) severity(fatal) message(message)
1717
!CHECK: !$OMP ERROR AT(EXECUTION) SEVERITY(FATAL) MESSAGE(message)
18-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPErrorConstruct
18+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPUtilityConstruct -> OmpErrorDirective
1919
!PARSE-TREE: OmpClauseList -> OmpClause -> At -> OmpAtClause -> ActionTime = Execution
2020
!PARSE-TREE: OmpClause -> Severity -> OmpSeverityClause -> Severity = Fatal
2121
!PARSE-TREE: OmpClause -> Message -> OmpMessageClause -> Expr -> Designator -> DataRef -> Name = 'message'

flang/test/Parser/OpenMP/nothing.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
!RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=51 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
2+
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=51 %s | FileCheck --check-prefix="PARSE-TREE" %s
3+
4+
subroutine f00
5+
!$omp nothing
6+
end
7+
8+
!UNPARSE: SUBROUTINE f00
9+
!UNPARSE: !$OMP NOTHING
10+
!UNPARSE: END SUBROUTINE
11+
12+
!PARSE-TREE: ExecutionPart -> Block
13+
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPUtilityConstruct -> OmpNothingDirective

0 commit comments

Comments
 (0)