Skip to content

Commit 17a400b

Browse files
Improve support for metadirective + declare reduction
1 parent 1b08d9c commit 17a400b

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

flang/include/flang/Semantics/symbol.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class raw_ostream;
3030
namespace Fortran::parser {
3131
struct Expr;
3232
struct OpenMPDeclareReductionConstruct;
33-
struct OmpDirectiveSpecification;
33+
struct OmpMetadirectiveDirective;
3434
}
3535

3636
namespace Fortran::semantics {
@@ -710,7 +710,7 @@ class UserReductionDetails {
710710
public:
711711
using TypeVector = std::vector<const DeclTypeSpec *>;
712712
using DeclInfo = std::variant<const parser::OpenMPDeclareReductionConstruct *,
713-
const parser::OmpDirectiveSpecification *>;
713+
const parser::OmpMetadirectiveDirective *>;
714714
using DeclVector = std::vector<DeclInfo>;
715715

716716
UserReductionDetails() = default;

flang/lib/Parser/unparse.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3329,7 +3329,7 @@ template void Unparse<Expr>(llvm::raw_ostream &, const Expr &, Encoding, bool,
33293329
template void Unparse<parser::OpenMPDeclareReductionConstruct>(
33303330
llvm::raw_ostream &, const parser::OpenMPDeclareReductionConstruct &,
33313331
Encoding, bool, bool, preStatementType *, AnalyzedObjectsAsFortran *);
3332-
template void Unparse<parser::OmpDirectiveSpecification>(llvm::raw_ostream &,
3333-
const parser::OmpDirectiveSpecification &, Encoding, bool, bool,
3332+
template void Unparse<parser::OmpMetadirectiveDirective>(llvm::raw_ostream &,
3333+
const parser::OmpMetadirectiveDirective &, Encoding, bool, bool,
33343334
preStatementType *, AnalyzedObjectsAsFortran *);
33353335
} // namespace Fortran::parser

flang/lib/Semantics/mod-file.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,7 @@ void ModFileWriter::PutUserReduction(
10471047
if (auto d = std::get_if<const parser::OpenMPDeclareReductionConstruct *>(
10481048
&decl)) {
10491049
Unparse(os, **d);
1050-
} else if (auto s = std::get_if<const parser::OmpDirectiveSpecification *>(
1050+
} else if (auto s = std::get_if<const parser::OmpMetadirectiveDirective *>(
10511051
&decl)) {
10521052
Unparse(os, **s);
10531053
} else {

flang/lib/Semantics/resolve-names.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,14 @@ class OmpVisitor : public virtual DeclarationVisitor {
16551655
EndDeclTypeSpec();
16561656
}
16571657

1658+
bool Pre(const parser::OmpMetadirectiveDirective &x) { //
1659+
metaDirective_ = &x;
1660+
return true;
1661+
}
1662+
void Post(const parser::OmpMetadirectiveDirective &) { //
1663+
metaDirective_ = nullptr;
1664+
}
1665+
16581666
private:
16591667
void ProcessMapperSpecifier(const parser::OmpMapperSpecifier &spec,
16601668
const parser::OmpClauseList &clauses);
@@ -1666,6 +1674,7 @@ class OmpVisitor : public virtual DeclarationVisitor {
16661674
parser::CharBlock MangleDefinedOperator(const parser::CharBlock &name);
16671675

16681676
int metaLevel_{0};
1677+
const parser::OmpMetadirectiveDirective *metaDirective_{nullptr};
16691678
};
16701679

16711680
bool OmpVisitor::NeedsScope(const parser::OpenMPBlockConstruct &x) {
@@ -1930,7 +1939,8 @@ bool OmpVisitor::Pre(const parser::OmpDirectiveSpecification &x) {
19301939
if (maybeArgs && maybeClauses) {
19311940
const parser::OmpArgument &first{maybeArgs->v.front()};
19321941
if (auto *spec{std::get_if<parser::OmpReductionSpecifier>(&first.u)}) {
1933-
ProcessReductionSpecifier(*spec, maybeClauses, x);
1942+
CHECK(metaDirective_);
1943+
ProcessReductionSpecifier(*spec, maybeClauses, *metaDirective_);
19341944
}
19351945
}
19361946
break;

flang/test/Semantics/OpenMP/declare-reduction-modfile.f90

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/../test_modfile.py %s %flang_fc1 -fopenmp
1+
! RUN: %python %S/../test_modfile.py %s %flang_fc1 -fopenmp -fopenmp-version=52
22
! Check correct modfile generation for OpenMP DECLARE REDUCTION construct.
33

44
!Expect: drm.mod
@@ -8,6 +8,7 @@
88
!endtype
99
!!$OMP DECLARE REDUCTION (*:t1:omp_out = omp_out*omp_in) INITIALIZER(omp_priv=t&
1010
!!$OMP&1(1))
11+
!!$OMP METADIRECTIVE OTHERWISE(DECLARE REDUCTION(+:INTEGER))
1112
!!$OMP DECLARE REDUCTION (.fluffy.:t1:omp_out = omp_out.fluffy.omp_in) INITIALI&
1213
!!$OMP&ZER(omp_priv=t1(0))
1314
!!$OMP DECLARE REDUCTION (.mul.:t1:omp_out = omp_out.mul.omp_in) INITIALIZER(om&
@@ -50,6 +51,7 @@ module drm
5051
!$omp declare reduction(*:t1:omp_out=omp_out*omp_in) initializer(omp_priv=t1(1))
5152
!$omp declare reduction(.mul.:t1:omp_out=omp_out.mul.omp_in) initializer(omp_priv=t1(1))
5253
!$omp declare reduction(.fluffy.:t1:omp_out=omp_out.fluffy.omp_in) initializer(omp_priv=t1(0))
54+
!$omp metadirective otherwise(declare reduction(+: integer))
5355
contains
5456
type(t1) function mul(v1, v2)
5557
type(t1), intent (in):: v1, v2

0 commit comments

Comments
 (0)