Skip to content

Commit 6d4beb3

Browse files
Leporacanthicuskiranchandramohan
authored andcommitted
Review comments
1 parent 3dcf7fc commit 6d4beb3

File tree

10 files changed

+105
-63
lines changed

10 files changed

+105
-63
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,6 @@ class ParseTreeDumper {
580580
NODE(parser, OmpExpectation)
581581
NODE_ENUM(OmpExpectation, Value)
582582
NODE(parser, OmpDirectiveNameModifier)
583-
NODE(parser, OmpDirectiveNameEntry)
584583
NODE(parser, OmpHoldsClause)
585584
NODE(parser, OmpIfClause)
586585
NODE(OmpIfClause, Modifier)
@@ -676,7 +675,8 @@ class ParseTreeDumper {
676675
NODE(parser, OpenMPAssumeConstruct)
677676
NODE(parser, OpenMPAssumesConstruct)
678677
NODE(parser, OpenMPAssumesPartConstruct)
679-
NODE(parser, OmpAssumesDirective)
678+
NODE(parser, OmpBeginAssumesDirective)
679+
NODE(parser, OpenMPBeginAssumesConstruct)
680680
NODE(parser, OmpEndAssumesDirective)
681681
NODE(parser, OpenMPAtomicConstruct)
682682
NODE(parser, OpenMPBlockConstruct)

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,10 +3895,7 @@ using OmpContextSelector = traits::OmpContextSelectorSpecification;
38953895

38963896
// --- Clauses
38973897

3898-
struct OmpDirectiveNameEntry {
3899-
WRAPPER_CLASS_BOILERPLATE(OmpDirectiveNameEntry, llvm::omp::Directive);
3900-
};
3901-
using OmpDirectiveList = std::list<OmpDirectiveNameEntry>;
3898+
using OmpDirectiveList = std::list<llvm::omp::Directive>;
39023899

39033900
// Ref: [5.2:214]
39043901
//
@@ -4162,10 +4159,9 @@ struct OmpGrainsizeClause {
41624159
// Ref: [5.2: 214]
41634160
//
41644161
// holds-clause ->
4165-
// HOLDS(expr[, expr])
4162+
// HOLDS(expr)
41664163
struct OmpHoldsClause {
4167-
using ExprList = std::list<common::Indirection<Expr>>;
4168-
WRAPPER_CLASS_BOILERPLATE(OmpHoldsClause, ExprList);
4164+
WRAPPER_CLASS_BOILERPLATE(OmpHoldsClause, common::Indirection<Expr>);
41694165
};
41704166

41714167
// Ref: [5.2:72-73], in 4.5-5.1 it's scattered over individual directives
@@ -4459,15 +4455,20 @@ struct OpenMPAssumeConstruct {
44594455
CharBlock source;
44604456
};
44614457

4462-
struct OmpAssumesDirective {
4463-
TUPLE_CLASS_BOILERPLATE(OmpAssumesDirective);
4458+
struct OpenMPAssumesConstruct {
4459+
TUPLE_CLASS_BOILERPLATE(OpenMPAssumesConstruct);
4460+
std::tuple<Verbatim, OmpClauseList> t;
4461+
CharBlock source;
4462+
};
4463+
4464+
struct OmpBeginAssumesDirective {
4465+
TUPLE_CLASS_BOILERPLATE(OmpBeginAssumesDirective);
44644466
std::tuple<Verbatim, OmpClauseList> t;
44654467
CharBlock source;
44664468
};
44674469

44684470
struct OmpEndAssumesDirective {
4469-
TUPLE_CLASS_BOILERPLATE(OmpEndAssumesDirective);
4470-
std::tuple<Verbatim> t;
4471+
WRAPPER_CLASS_BOILERPLATE(OmpEndAssumesDirective, Verbatim);
44714472
CharBlock source;
44724473
};
44734474

@@ -4478,9 +4479,9 @@ struct OpenMPAssumesPartConstruct {
44784479
CharBlock source;
44794480
};
44804481

4481-
struct OpenMPAssumesConstruct {
4482-
TUPLE_CLASS_BOILERPLATE(OpenMPAssumesConstruct);
4483-
std::tuple<OmpAssumesDirective, OpenMPAssumesPartConstruct,
4482+
struct OpenMPBeginAssumesConstruct {
4483+
TUPLE_CLASS_BOILERPLATE(OpenMPBeginAssumesConstruct);
4484+
std::tuple<OmpBeginAssumesDirective, OpenMPAssumesPartConstruct,
44844485
OmpEndAssumesDirective>
44854486
t;
44864487
CharBlock source;
@@ -4619,7 +4620,7 @@ struct OpenMPDeclarativeAllocate {
46194620
struct OpenMPDeclarativeConstruct {
46204621
UNION_CLASS_BOILERPLATE(OpenMPDeclarativeConstruct);
46214622
CharBlock source;
4622-
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclareMapperConstruct,
4623+
std::variant<OpenMPDeclarativeAllocate, OpenMPAssumesConstruct, OpenMPDeclareMapperConstruct,
46234624
OpenMPDeclareReductionConstruct, OpenMPDeclareSimdConstruct,
46244625
OpenMPDeclareTargetConstruct, OpenMPThreadprivate,
46254626
OpenMPRequiresConstruct, OpenMPUtilityConstruct>
@@ -4909,7 +4910,7 @@ struct OpenMPConstruct {
49094910
OpenMPSectionConstruct, OpenMPLoopConstruct, OpenMPBlockConstruct,
49104911
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPDispatchConstruct,
49114912
OpenMPUtilityConstruct, OpenMPExecutableAllocate,
4912-
OpenMPAllocatorsConstruct,OpenMPAssumeConstruct, OpenMPAssumesConstruct, OpenMPCriticalConstruct>
4913+
OpenMPAllocatorsConstruct, OpenMPAssumeConstruct, OpenMPBeginAssumesConstruct, OpenMPCriticalConstruct>
49134914
u;
49144915
};
49154916

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,6 +3076,13 @@ genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
30763076
TODO(converter.getCurrentLocation(), "OpenMPDeclarativeAllocate");
30773077
}
30783078

3079+
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
3080+
semantics::SemanticsContext &semaCtx,
3081+
lower::pft::Evaluation &eval,
3082+
const parser::OpenMPAssumesConstruct &assumesConstruct) {
3083+
TODO(converter.getCurrentLocation(), "OpenMP ASSUMES declaration");
3084+
}
3085+
30793086
static void genOMP(
30803087
lower::AbstractConverter &converter, lower::SymMap &symTable,
30813088
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
@@ -3383,13 +3390,13 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
33833390
TODO(clauseLocation, "OpenMP ASSUME construct");
33843391
}
33853392

3386-
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
3387-
semantics::SemanticsContext &semaCtx,
3388-
lower::pft::Evaluation &eval,
3389-
const parser::OpenMPAssumesConstruct &assumesConstruct) {
3393+
static void
3394+
genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
3395+
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
3396+
const parser::OpenMPBeginAssumesConstruct &beginAssumesConstruct) {
33903397
mlir::Location clauseLocation =
3391-
converter.genLocation(assumesConstruct.source);
3392-
TODO(clauseLocation, "OpenMP ASSUMES construct");
3398+
converter.genLocation(beginAssumesConstruct.source);
3399+
TODO(clauseLocation, "OpenMP BEGIN ASSUMES construct");
33933400
}
33943401

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

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,11 @@ TYPE_PARSER(construct<OmpSeverityClause>(
755755

756756
TYPE_PARSER(construct<OmpMessageClause>(expr))
757757

758-
TYPE_PARSER(construct<OmpHoldsClause>(many(maybe(","_tok) >> indirect(expr))))
758+
TYPE_PARSER(construct<OmpHoldsClause>(indirect(expr)))
759759
TYPE_PARSER(construct<OmpAbsentClause>(many(maybe(","_tok) >>
760-
construct<OmpDirectiveNameEntry>(OmpDirectiveNameParser{}))))
760+
construct<llvm::omp::Directive>(OmpDirectiveNameParser{}))))
761761
TYPE_PARSER(construct<OmpContainsClause>(many(maybe(","_tok) >>
762-
construct<OmpDirectiveNameEntry>(OmpDirectiveNameParser{}))))
762+
construct<llvm::omp::Directive>(OmpDirectiveNameParser{}))))
763763

764764
TYPE_PARSER("ABSENT" >> construct<OmpClause>(construct<OmpClause::Absent>(
765765
parenthesized(Parser<OmpAbsentClause>{}))) ||
@@ -1295,11 +1295,17 @@ TYPE_PARSER(
12951295
parenthesized(Parser<OmpObjectList>{}), Parser<OmpClauseList>{})) /
12961296
lookAhead(endOmpLine / !statement(allocateStmt)))
12971297

1298+
// Assumes Construct
1299+
TYPE_PARSER(sourced(construct<OpenMPAssumesConstruct>(
1300+
verbatim("ASSUMES"_tok), Parser<OmpClauseList>{})))
1301+
12981302
// Declarative constructs
12991303
TYPE_PARSER(startOmpLine >>
13001304
withMessage("expected OpenMP construct"_err_en_US,
13011305
sourced(construct<OpenMPDeclarativeConstruct>(
1302-
Parser<OpenMPDeclareReductionConstruct>{}) ||
1306+
Parser<OpenMPAssumesConstruct>{}) ||
1307+
construct<OpenMPDeclarativeConstruct>(
1308+
Parser<OpenMPDeclareReductionConstruct>{}) ||
13031309
construct<OpenMPDeclarativeConstruct>(
13041310
Parser<OpenMPDeclareMapperConstruct>{}) ||
13051311
construct<OpenMPDeclarativeConstruct>(
@@ -1320,17 +1326,17 @@ TYPE_PARSER(startOmpLine >>
13201326
TYPE_PARSER(sourced(construct<OpenMPAssumeConstruct>(
13211327
verbatim("ASSUME"_tok), Parser<OmpClauseList>{}) /
13221328
endOmpLine))
1323-
// Assumes Construct
1324-
TYPE_PARSER(sourced(construct<OmpAssumesDirective>(
1325-
verbatim("ASSUMES"_tok), Parser<OmpClauseList>{})))
1329+
1330+
TYPE_PARSER(sourced(construct<OmpBeginAssumesDirective>(
1331+
"BEGIN"_tok >> verbatim("ASSUMES"_tok), Parser<OmpClauseList>{})))
13261332

13271333
TYPE_PARSER(sourced(construct<OmpEndAssumesDirective>(
13281334
verbatim(startOmpLine >> "END ASSUMES"_tok))))
13291335

13301336
TYPE_PARSER(construct<OpenMPAssumesPartConstruct>(block))
13311337

1332-
TYPE_PARSER(sourced(construct<OpenMPAssumesConstruct>(
1333-
maybe("BEGIN"_tok) >> Parser<OmpAssumesDirective>{} / endOmpLine,
1338+
TYPE_PARSER(sourced(construct<OpenMPBeginAssumesConstruct>(
1339+
Parser<OmpBeginAssumesDirective>{} / endOmpLine,
13341340
Parser<OpenMPAssumesPartConstruct>{},
13351341
Parser<OmpEndAssumesDirective>{} / endOmpLine)))
13361342

@@ -1381,7 +1387,8 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
13811387
construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
13821388
construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
13831389
construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),
1384-
construct<OpenMPConstruct>(Parser<OpenMPAssumesConstruct>{}),
1390+
construct<OpenMPConstruct>(
1391+
Parser<OpenMPBeginAssumesConstruct>{}),
13851392
construct<OpenMPConstruct>(Parser<OpenMPAssumeConstruct>{}),
13861393
construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{}))))
13871394

flang/lib/Parser/unparse.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,10 +2115,10 @@ class UnparseVisitor {
21152115
},
21162116
x.u);
21172117
}
2118-
void Unparse(const OmpDirectiveNameModifier &x) {
2119-
Word(llvm::omp::getOpenMPDirectiveName(x.v));
2118+
void Unparse(const llvm::omp::Directive &x) {
2119+
Word(llvm::omp::getOpenMPDirectiveName(x));
21202120
}
2121-
void Unparse(const OmpDirectiveNameEntry &x) {
2121+
void Unparse(const OmpDirectiveNameModifier &x) {
21222122
Word(llvm::omp::getOpenMPDirectiveName(x.v));
21232123
}
21242124
void Unparse(const OmpIteratorSpecifier &x) {
@@ -2648,6 +2648,18 @@ class UnparseVisitor {
26482648
Put("\n");
26492649
EndOpenMP();
26502650
}
2651+
void Unparse(const OmpBeginAssumesDirective &x) {
2652+
BeginOpenMP();
2653+
Word("!$OMP BEGIN ASSUMES");
2654+
Walk(std::get<OmpClauseList>(x.t), ", ");
2655+
Put("\n");
2656+
EndOpenMP();
2657+
}
2658+
void Unparse(const OmpEndAssumesDirective &x) {
2659+
BeginOpenMP();
2660+
Word("!$OMP END ASSUMES\n");
2661+
EndOpenMP();
2662+
}
26512663
void Unparse(const OmpCriticalDirective &x) {
26522664
BeginOpenMP();
26532665
Word("!$OMP CRITICAL");
@@ -2699,7 +2711,13 @@ class UnparseVisitor {
26992711
Walk(std::get<std::optional<OmpReductionInitializerClause>>(x.t));
27002712
EndOpenMP();
27012713
}
2702-
2714+
bool Pre(const OpenMPAssumesConstruct &x) {
2715+
BeginOpenMP();
2716+
Word("!$OMP ASSUMES ");
2717+
Walk(std::get<OmpClauseList>(x.t));
2718+
Put("\n");
2719+
EndOpenMP();
2720+
}
27032721
void Unparse(const OpenMPDeclareMapperConstruct &z) {
27042722
BeginOpenMP();
27052723
Word("!$OMP DECLARE MAPPER (");

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,14 @@ void OmpStructureChecker::Leave(const parser::OpenMPAssumesConstruct &) {
12681268
dirContext_.pop_back();
12691269
}
12701270

1271+
void OmpStructureChecker::Enter(const parser::OpenMPBeginAssumesConstruct &x) {
1272+
PushContextAndClauseSets(x.source, llvm::omp::Directive::OMPD_assumes);
1273+
}
1274+
1275+
void OmpStructureChecker::Leave(const parser::OpenMPBeginAssumesConstruct &) {
1276+
dirContext_.pop_back();
1277+
}
1278+
12711279
void OmpStructureChecker::Leave(const parser::OpenMPBlockConstruct &) {
12721280
if (GetDirectiveNest(TargetBlockOnlyTeams)) {
12731281
ExitDirectiveNest(TargetBlockOnlyTeams);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class OmpStructureChecker
8585
void Leave(const parser::OpenMPAssumeConstruct &);
8686
void Enter(const parser::OpenMPAssumesConstruct &);
8787
void Leave(const parser::OpenMPAssumesConstruct &);
88+
void Enter(const parser::OpenMPBeginAssumesConstruct &);
89+
void Leave(const parser::OpenMPBeginAssumesConstruct &);
8890
void Enter(const parser::OpenMPBlockConstruct &);
8991
void Leave(const parser::OpenMPBlockConstruct &);
9092
void Leave(const parser::OmpBeginBlockDirective &);
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
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: OpenMP ASSUMES construct
3+
! CHECK: not yet implemented: OpenMP ASSUMES declaration
44
program p
5+
!$omp assumes no_openmp
56
integer r
6-
!$omp assumes no_openmp
77
print *,r
8-
!$omp end assumes
98
end program p
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-fir -fopenmp -fopenmp-version=51 -o - %s 2>&1 | FileCheck %s
2+
3+
! CHECK: not yet implemented: OpenMP BEGIN ASSUMES construct
4+
program p
5+
integer r
6+
!$omp begin assumes no_parallelism
7+
print *,r
8+
!$omp end assumes
9+
end program p
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
! RUN: %flang_fc1 -fopenmp-version=51 -fopenmp -fdebug-unparse-no-sema %s 2>&1 | FileCheck %s
22
!!! RUN: %flang_fc1 -fopenmp-version=51 -fopenmp -fdebug-dump-parse-tree-no-sema %s 2>&1 | FileCheck %s --check-prefix="PARSE-TREE"
3-
43
subroutine sub1
54
integer :: r
65
!CHECK: !$OMP ASSUME NO_OPENMP
@@ -21,9 +20,9 @@ subroutine sub1
2120
!CHECK: !$OMP ASSUME ABSENT(ALLOCATE), CONTAINS(WORKSHARE,TASK)
2221
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumeConstruct
2322
!PARSE-TREE: Verbatim
24-
!PARSE-TREE: OmpClauseList -> OmpClause -> Absent -> OmpAbsentClause -> OmpDirectiveNameEntry -> llvm::omp::Directive = allocate
25-
!PARSE-TREE: OmpClause -> Contains -> OmpContainsClause -> OmpDirectiveNameEntry -> llvm::omp::Directive = workshare
26-
!PARSE-TREE: OmpDirectiveNameEntry -> llvm::omp::Directive = task
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
2726
!$omp assume absent(allocate), contains(workshare, task)
2827
!CHECK: !$OMP ASSUME HOLDS(1==1)
2928
!$omp assume holds(1.eq.1)
@@ -32,35 +31,27 @@ end subroutine sub1
3231

3332
subroutine sub2
3433
integer :: r
35-
!CHECK !$OMP ASSUMES NO_OPENMP
36-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumesConstruct
37-
!PARSE-TREE: OmpAssumesDirective
34+
!CHECK !$OMP BEGIN ASSUMES NO_OPENMP
35+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBeginAssumesConstruct
36+
!PARSE-TREE: OmpBeginAssumesDirective
3837
!PARSE-TREE: Verbatim
3938
!PARSE-TREE: OmpClauseList -> OmpClause -> NoOpenmp
4039
!PARSE-TREE: OpenMPAssumesPartConstruct -> Block
4140
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt
4241
!PARSE-TREE: Expr -> Add
4342
!PARSE-TREE: OmpEndAssumesDirective
44-
!$omp assumes no_openmp
43+
!$omp begin assumes no_openmp
4544
r = r + 1
4645
!CHECK !$OMP END ASSUMES
4746
!$omp end assumes
4847
end subroutine sub2
49-
50-
subroutine sub3
51-
integer :: r
48+
49+
program p
5250
!CHECK !$OMP ASSUMES NO_OPENMP
53-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPAssumesConstruct
54-
!PARSE-TREE: OmpAssumesDirective
51+
!PARSE-TREE: SpecificationPart
52+
!PARSE-TREE: OpenMPDeclarativeConstruct -> OpenMPAssumesConstruct
5553
!PARSE-TREE: Verbatim
5654
!PARSE-TREE: OmpClauseList -> OmpClause -> NoOpenmp
57-
!PARSE-TREE: OpenMPAssumesPartConstruct -> Block
58-
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt
59-
!PARSE-TREE: Expr -> Add
60-
!PARSE-TREE: OmpEndAssumesDirective
61-
!$omp begin assumes no_openmp
62-
r = r + 1
63-
!CHECK !$OMP END ASSUMES
64-
!$omp end assumes
65-
end subroutine sub3
55+
!$omp assumes no_openmp
56+
end program p
6657

0 commit comments

Comments
 (0)