Skip to content

Commit 42350f4

Browse files
authored
[flang][OpenMP] Parse GROUPPRIVATE directive (#153807)
No semantic checks or lowering yet.
1 parent 292faf6 commit 42350f4

File tree

11 files changed

+93
-19
lines changed

11 files changed

+93
-19
lines changed

flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,8 @@ std::string OpenMPCounterVisitor::getName(const OmpWrapperType &w) {
101101
return getName(*std::get<const OpenMPDeclarativeConstruct *>(w));
102102
}
103103
std::string OpenMPCounterVisitor::getName(const OpenMPDeclarativeConstruct &c) {
104-
return std::visit( //
105-
Fortran::common::visitors{
106-
[&](const OpenMPUtilityConstruct &o) -> std::string {
107-
const CharBlock &source{o.source};
108-
return normalize_construct_name(source.ToString());
109-
},
110-
[&](const OmpMetadirectiveDirective &o) -> std::string {
111-
const CharBlock &source{o.source};
112-
return normalize_construct_name(source.ToString());
113-
},
114-
[&](const auto &o) -> std::string {
115-
const CharBlock &source{std::get<Verbatim>(o.t).source};
116-
return normalize_construct_name(source.ToString());
117-
},
118-
},
119-
c.u);
104+
return normalize_construct_name(
105+
omp::GetOmpDirectiveName(c).source.ToString());
120106
}
121107
std::string OpenMPCounterVisitor::getName(const OpenMPConstruct &c) {
122108
return normalize_construct_name(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ class ParseTreeDumper {
733733
NODE(parser, OpenMPLoopConstruct)
734734
NODE(parser, OpenMPExecutableAllocate)
735735
NODE(parser, OpenMPAllocatorsConstruct)
736+
NODE(parser, OpenMPGroupprivate)
736737
NODE(parser, OpenMPRequiresConstruct)
737738
NODE(parser, OpenMPSimpleStandaloneConstruct)
738739
NODE(parser, OpenMPStandaloneConstruct)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ struct DirectiveNameScope {
9595
std::is_same_v<T, OpenMPDepobjConstruct> ||
9696
std::is_same_v<T, OpenMPFlushConstruct> ||
9797
std::is_same_v<T, OpenMPInteropConstruct> ||
98-
std::is_same_v<T, OpenMPSimpleStandaloneConstruct>) {
98+
std::is_same_v<T, OpenMPSimpleStandaloneConstruct> ||
99+
std::is_same_v<T, OpenMPGroupprivate>) {
99100
return x.v.DirName();
100101
} else {
101102
return GetOmpDirectiveName(x.v);

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4955,6 +4955,15 @@ struct OpenMPDeclareSimdConstruct {
49554955
std::tuple<Verbatim, std::optional<Name>, OmpClauseList> t;
49564956
};
49574957

4958+
// ref: [6.0:301-303]
4959+
//
4960+
// groupprivate-directive ->
4961+
// GROUPPRIVATE (variable-list-item...) // since 6.0
4962+
struct OpenMPGroupprivate {
4963+
WRAPPER_CLASS_BOILERPLATE(OpenMPGroupprivate, OmpDirectiveSpecification);
4964+
CharBlock source;
4965+
};
4966+
49584967
// 2.4 requires -> REQUIRES requires-clause[ [ [,] requires-clause]...]
49594968
struct OpenMPRequiresConstruct {
49604969
TUPLE_CLASS_BOILERPLATE(OpenMPRequiresConstruct);
@@ -4982,8 +4991,9 @@ struct OpenMPDeclarativeConstruct {
49824991
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclarativeAssumes,
49834992
OpenMPDeclareMapperConstruct, OpenMPDeclareReductionConstruct,
49844993
OpenMPDeclareSimdConstruct, OpenMPDeclareTargetConstruct,
4985-
OmpDeclareVariantDirective, OpenMPThreadprivate, OpenMPRequiresConstruct,
4986-
OpenMPUtilityConstruct, OmpMetadirectiveDirective>
4994+
OmpDeclareVariantDirective, OpenMPGroupprivate, OpenMPThreadprivate,
4995+
OpenMPRequiresConstruct, OpenMPUtilityConstruct,
4996+
OmpMetadirectiveDirective>
49874997
u;
49884998
};
49894999

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,6 +3593,13 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
35933593
}
35943594
}
35953595

3596+
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
3597+
semantics::SemanticsContext &semaCtx,
3598+
lower::pft::Evaluation &eval,
3599+
const parser::OpenMPGroupprivate &directive) {
3600+
TODO(converter.getCurrentLocation(), "GROUPPRIVATE");
3601+
}
3602+
35963603
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
35973604
semantics::SemanticsContext &semaCtx,
35983605
lower::pft::Evaluation &eval,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,12 @@ TYPE_PARSER(sourced(construct<OpenMPDeclareSimdConstruct>(
17901790
verbatim("DECLARE SIMD"_tok) || verbatim("DECLARE_SIMD"_tok),
17911791
maybe(parenthesized(name)), Parser<OmpClauseList>{})))
17921792

1793+
TYPE_PARSER(sourced( //
1794+
construct<OpenMPGroupprivate>(
1795+
predicated(OmpDirectiveNameParser{},
1796+
IsDirective(llvm::omp::Directive::OMPD_groupprivate)) >=
1797+
Parser<OmpDirectiveSpecification>{})))
1798+
17931799
// 2.4 Requires construct
17941800
TYPE_PARSER(sourced(construct<OpenMPRequiresConstruct>(
17951801
verbatim("REQUIRES"_tok), Parser<OmpClauseList>{})))
@@ -1825,6 +1831,8 @@ TYPE_PARSER(
18251831
Parser<OmpDeclareVariantDirective>{}) ||
18261832
construct<OpenMPDeclarativeConstruct>(
18271833
Parser<OpenMPDeclarativeAllocate>{}) ||
1834+
construct<OpenMPDeclarativeConstruct>(
1835+
Parser<OpenMPGroupprivate>{}) ||
18281836
construct<OpenMPDeclarativeConstruct>(
18291837
Parser<OpenMPRequiresConstruct>{}) ||
18301838
construct<OpenMPDeclarativeConstruct>(

flang/lib/Parser/unparse.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,13 @@ class UnparseVisitor {
27212721
void Unparse(const OpenMPDispatchConstruct &x) { //
27222722
Unparse(static_cast<const OmpBlockConstruct &>(x));
27232723
}
2724+
void Unparse(const OpenMPGroupprivate &x) {
2725+
BeginOpenMP();
2726+
Word("!$OMP ");
2727+
Walk(x.v);
2728+
Put("\n");
2729+
EndOpenMP();
2730+
}
27242731
void Unparse(const OpenMPRequiresConstruct &y) {
27252732
BeginOpenMP();
27262733
Word("!$OMP REQUIRES ");

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ template <typename Checker> struct DirectiveSpellingVisitor {
571571
Directive::OMPD_declare_variant);
572572
return false;
573573
}
574+
bool Pre(const parser::OpenMPGroupprivate &x) {
575+
checker_(x.v.DirName().source, Directive::OMPD_groupprivate);
576+
return false;
577+
}
574578
bool Pre(const parser::OpenMPThreadprivate &x) {
575579
checker_(
576580
std::get<parser::Verbatim>(x.t).source, Directive::OMPD_threadprivate);
@@ -1175,6 +1179,15 @@ void OmpStructureChecker::CheckThreadprivateOrDeclareTargetVar(
11751179
}
11761180
}
11771181

1182+
void OmpStructureChecker::Enter(const parser::OpenMPGroupprivate &x) {
1183+
PushContextAndClauseSets(
1184+
x.v.DirName().source, llvm::omp::Directive::OMPD_groupprivate);
1185+
}
1186+
1187+
void OmpStructureChecker::Leave(const parser::OpenMPGroupprivate &x) {
1188+
dirContext_.pop_back();
1189+
}
1190+
11781191
void OmpStructureChecker::Enter(const parser::OpenMPThreadprivate &c) {
11791192
const auto &dir{std::get<parser::Verbatim>(c.t)};
11801193
PushContextAndClauseSets(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class OmpStructureChecker
126126
void Leave(const parser::OpenMPAllocatorsConstruct &);
127127
void Enter(const parser::OpenMPRequiresConstruct &);
128128
void Leave(const parser::OpenMPRequiresConstruct &);
129+
void Enter(const parser::OpenMPGroupprivate &);
130+
void Leave(const parser::OpenMPGroupprivate &);
129131
void Enter(const parser::OpenMPThreadprivate &);
130132
void Leave(const parser::OpenMPThreadprivate &);
131133

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=60 -o - %s 2>&1 | FileCheck %s
2+
3+
!CHECK: not yet implemented: GROUPPRIVATE
4+
5+
module m
6+
implicit none
7+
integer :: x
8+
!$omp groupprivate(x)
9+
end module

0 commit comments

Comments
 (0)