Skip to content

Commit e258558

Browse files
authored
[flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_SIMD (#160390)
1 parent 78428ce commit e258558

File tree

9 files changed

+86
-45
lines changed

9 files changed

+86
-45
lines changed

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

Lines changed: 4 additions & 2 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(OpenMPDeclarativeAssumes, D::OMPD_assumes);
4343
MAKE_CONSTR_ID(OpenMPDeclareReductionConstruct, D::OMPD_declare_reduction);
44-
MAKE_CONSTR_ID(OpenMPDeclareSimdConstruct, D::OMPD_declare_simd);
4544
MAKE_CONSTR_ID(OpenMPDeclareTargetConstruct, D::OMPD_declare_target);
4645
MAKE_CONSTR_ID(OpenMPExecutableAllocate, D::OMPD_allocate);
4746
MAKE_CONSTR_ID(OpenMPRequiresConstruct, D::OMPD_requires);
@@ -57,6 +56,10 @@ struct DirectiveNameScope {
5756
return name;
5857
}
5958

59+
static OmpDirectiveName GetOmpDirectiveName(const OmpDirectiveName &x) {
60+
return x;
61+
}
62+
6063
static OmpDirectiveName GetOmpDirectiveName(const OmpBeginLoopDirective &x) {
6164
return x.DirName();
6265
}
@@ -94,7 +97,6 @@ struct DirectiveNameScope {
9497
} else if constexpr (std::is_same_v<T, OpenMPDeclarativeAllocate> ||
9598
std::is_same_v<T, OpenMPDeclarativeAssumes> ||
9699
std::is_same_v<T, OpenMPDeclareReductionConstruct> ||
97-
std::is_same_v<T, OpenMPDeclareSimdConstruct> ||
98100
std::is_same_v<T, OpenMPDeclareTargetConstruct> ||
99101
std::is_same_v<T, OpenMPExecutableAllocate> ||
100102
std::is_same_v<T, OpenMPRequiresConstruct>) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4987,9 +4987,9 @@ struct OpenMPDeclareReductionConstruct {
49874987
// 2.8.2 declare-simd -> DECLARE SIMD [(proc-name)] [declare-simd-clause[ [,]
49884988
// declare-simd-clause]...]
49894989
struct OpenMPDeclareSimdConstruct {
4990-
TUPLE_CLASS_BOILERPLATE(OpenMPDeclareSimdConstruct);
4990+
WRAPPER_CLASS_BOILERPLATE(
4991+
OpenMPDeclareSimdConstruct, OmpDirectiveSpecification);
49914992
CharBlock source;
4992-
std::tuple<Verbatim, std::optional<Name>, OmpClauseList> t;
49934993
};
49944994

49954995
// ref: [6.0:301-303]

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,8 +1836,9 @@ TYPE_PARSER(
18361836

18371837
// 2.8.2 Declare Simd construct
18381838
TYPE_PARSER(sourced(construct<OpenMPDeclareSimdConstruct>(
1839-
verbatim("DECLARE SIMD"_tok) || verbatim("DECLARE_SIMD"_tok),
1840-
maybe(parenthesized(name)), Parser<OmpClauseList>{})))
1839+
predicated(Parser<OmpDirectiveName>{},
1840+
IsDirective(llvm::omp::Directive::OMPD_declare_simd)) >=
1841+
Parser<OmpDirectiveSpecification>{})))
18411842

18421843
TYPE_PARSER(sourced( //
18431844
construct<OpenMPGroupprivate>(

flang/lib/Parser/unparse.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,11 +2573,10 @@ class UnparseVisitor {
25732573
Put("\n");
25742574
EndOpenMP();
25752575
}
2576-
void Unparse(const OpenMPDeclareSimdConstruct &y) {
2576+
void Unparse(const OpenMPDeclareSimdConstruct &x) {
25772577
BeginOpenMP();
2578-
Word("!$OMP DECLARE SIMD ");
2579-
Walk("(", std::get<std::optional<Name>>(y.t), ")");
2580-
Walk(std::get<OmpClauseList>(y.t));
2578+
Word("!$OMP ");
2579+
Walk(x.v);
25812580
Put("\n");
25822581
EndOpenMP();
25832582
}

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,11 +624,6 @@ template <typename Checker> struct DirectiveSpellingVisitor {
624624
checker_(std::get<parser::Verbatim>(x.t).source, Directive::OMPD_assumes);
625625
return false;
626626
}
627-
bool Pre(const parser::OpenMPDeclareSimdConstruct &x) {
628-
checker_(
629-
std::get<parser::Verbatim>(x.t).source, Directive::OMPD_declare_simd);
630-
return false;
631-
}
632627
bool Pre(const parser::OpenMPDeclareTargetConstruct &x) {
633628
checker_(
634629
std::get<parser::Verbatim>(x.t).source, Directive::OMPD_declare_target);
@@ -1356,8 +1351,32 @@ void OmpStructureChecker::Leave(const parser::OpenMPThreadprivate &x) {
13561351
}
13571352

13581353
void OmpStructureChecker::Enter(const parser::OpenMPDeclareSimdConstruct &x) {
1359-
const auto &dir{std::get<parser::Verbatim>(x.t)};
1360-
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_declare_simd);
1354+
const parser::OmpDirectiveName &dirName{x.v.DirName()};
1355+
PushContextAndClauseSets(dirName.source, dirName.v);
1356+
1357+
const parser::OmpArgumentList &args{x.v.Arguments()};
1358+
if (args.v.empty()) {
1359+
return;
1360+
} else if (args.v.size() > 1) {
1361+
context_.Say(args.source,
1362+
"DECLARE_SIMD directive should have at most one argument"_err_en_US);
1363+
return;
1364+
}
1365+
1366+
const parser::OmpArgument &arg{args.v.front()};
1367+
if (auto *sym{GetArgumentSymbol(arg)}) {
1368+
if (!IsProcedure(*sym) && !IsFunction(*sym)) {
1369+
auto &msg{context_.Say(arg.source,
1370+
"The name '%s' should refer to a procedure"_err_en_US, sym->name())};
1371+
if (sym->test(Symbol::Flag::Implicit)) {
1372+
msg.Attach(arg.source,
1373+
"The name '%s' has been implicitly declared"_en_US, sym->name());
1374+
}
1375+
}
1376+
} else {
1377+
context_.Say(arg.source,
1378+
"The argument to the DECLARE_SIMD directive should be a procedure name"_err_en_US);
1379+
}
13611380
}
13621381

13631382
void OmpStructureChecker::Leave(const parser::OpenMPDeclareSimdConstruct &) {

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,10 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
473473

474474
bool Pre(const parser::OpenMPDeclareSimdConstruct &x) {
475475
PushContext(x.source, llvm::omp::Directive::OMPD_declare_simd);
476-
const auto &name{std::get<std::optional<parser::Name>>(x.t)};
477-
if (name) {
478-
ResolveOmpName(*name, Symbol::Flag::OmpDeclareSimd);
476+
for (const parser::OmpArgument &arg : x.v.Arguments().v) {
477+
if (auto *object{omp::GetArgumentObject(arg)}) {
478+
ResolveOmpObject(*object, Symbol::Flag::OmpDeclareSimd);
479+
}
479480
}
480481
return true;
481482
}

flang/test/Parser/OpenMP/linear-clause.f90

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,16 @@ subroutine f03(x)
8484

8585
!UNPARSE: SUBROUTINE f03 (x)
8686
!UNPARSE: INTEGER x
87-
!UNPARSE: !$OMP DECLARE SIMD LINEAR(x: UVAL)
87+
!UNPARSE: !$OMP DECLARE SIMD LINEAR(x: UVAL)
8888
!UNPARSE: END SUBROUTINE
8989

90-
!PARSE-TREE: SpecificationPart
91-
![...]
92-
!PARSE-TREE: | DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct
93-
!PARSE-TREE: | | Verbatim
94-
!PARSE-TREE: | | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause
95-
!PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x'
96-
!PARSE-TREE: | | | Modifier -> OmpLinearModifier -> Value = Uval
97-
!PARSE-TREE: | | | bool = 'true'
98-
!PARSE-TREE: ExecutionPart -> Block
90+
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct -> OmpDirectiveSpecification
91+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare simd
92+
!PARSE-TREE: | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause
93+
!PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x'
94+
!PARSE-TREE: | | Modifier -> OmpLinearModifier -> Value = Uval
95+
!PARSE-TREE: | | bool = 'true'
96+
!PARSE-TREE: | Flags = None
9997

10098
subroutine f04(x)
10199
integer :: x
@@ -104,17 +102,15 @@ subroutine f04(x)
104102

105103
!UNPARSE: SUBROUTINE f04 (x)
106104
!UNPARSE: INTEGER x
107-
!UNPARSE: !$OMP DECLARE SIMD LINEAR(x: UVAL, STEP(3_4))
105+
!UNPARSE: !$OMP DECLARE SIMD LINEAR(x: UVAL, STEP(3_4))
108106
!UNPARSE: END SUBROUTINE
109107

110-
!PARSE-TREE: SpecificationPart
111-
![...]
112-
!PARSE-TREE: | DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct
113-
!PARSE-TREE: | | Verbatim
114-
!PARSE-TREE: | | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause
115-
!PARSE-TREE: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x'
116-
!PARSE-TREE: | | | Modifier -> OmpLinearModifier -> Value = Uval
117-
!PARSE-TREE: | | | Modifier -> OmpStepComplexModifier -> Scalar -> Integer -> Expr = '3_4'
118-
!PARSE-TREE: | | | | LiteralConstant -> IntLiteralConstant = '3'
119-
!PARSE-TREE: | | | bool = 'true'
120-
!PARSE-TREE: ExecutionPart -> Block
108+
!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct -> OmpDirectiveSpecification
109+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare simd
110+
!PARSE-TREE: | OmpClauseList -> OmpClause -> Linear -> OmpLinearClause
111+
!PARSE-TREE: | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x'
112+
!PARSE-TREE: | | Modifier -> OmpLinearModifier -> Value = Uval
113+
!PARSE-TREE: | | Modifier -> OmpStepComplexModifier -> Scalar -> Integer -> Expr = '3_4'
114+
!PARSE-TREE: | | | LiteralConstant -> IntLiteralConstant = '3'
115+
!PARSE-TREE: | | bool = 'true'
116+
!PARSE-TREE: | Flags = None

flang/test/Parser/OpenMP/openmp6-directive-spellings.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,13 @@ subroutine f03
111111
end
112112

113113
!UNPARSE: SUBROUTINE f03
114-
!UNPARSE: !$OMP DECLARE SIMD
114+
!UNPARSE: !$OMP DECLARE_SIMD
115115
!UNPARSE: END SUBROUTINE
116116

117-
!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct
118-
!PARSE-TREE: | Verbatim
117+
!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPDeclareSimdConstruct -> OmpDirectiveSpecification
118+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = declare simd
119119
!PARSE-TREE: | OmpClauseList ->
120+
!PARSE-TREE: | Flags = None
120121

121122
subroutine f04
122123
!$omp declare_target
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=60
2+
3+
module m
4+
5+
!ERROR: The name 'x' should refer to a procedure
6+
!$omp declare_simd(x)
7+
8+
!ERROR: DECLARE_SIMD directive should have at most one argument
9+
!$omp declare_simd(f00, f01)
10+
11+
!ERROR: The argument to the DECLARE_SIMD directive should be a procedure name
12+
!$omp declare_simd(v : integer)
13+
14+
contains
15+
16+
subroutine f00
17+
end
18+
19+
subroutine f01
20+
end
21+
22+
end module

0 commit comments

Comments
 (0)