Skip to content

Commit bbb62d3

Browse files
committed
[flang][OpenMP] Parase bind clause for loop direcitve.
Adds parsing for the `bind` clause. The clause was already part of the `loop` direcitve's definition but parsing was still missing.
1 parent 8be860d commit bbb62d3

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ class ParseTreeDumper {
547547
NODE_ENUM(OmpOrderClause, Type)
548548
NODE(parser, OmpOrderModifier)
549549
NODE_ENUM(OmpOrderModifier, Kind)
550+
NODE(parser, OmpBindClause)
551+
NODE_ENUM(OmpBindClause, Type)
550552
NODE(parser, OmpProcBindClause)
551553
NODE_ENUM(OmpProcBindClause, Type)
552554
NODE_ENUM(OmpReductionClause, ReductionModifier)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3688,6 +3688,13 @@ struct OmpScheduleClause {
36883688
t;
36893689
};
36903690

3691+
// OMP 5.2 11.7.1 bind-clause ->
3692+
// BIND( PARALLEL | TEAMS | THREAD )
3693+
struct OmpBindClause {
3694+
ENUM_CLASS(Type, Parallel, Teams, Thread)
3695+
WRAPPER_CLASS_BOILERPLATE(OmpBindClause, Type);
3696+
};
3697+
36913698
// OpenMP Clauses
36923699
struct OmpClause {
36933700
UNION_CLASS_BOILERPLATE(OmpClause);

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,12 @@ TYPE_PARSER(construct<OmpLastprivateClause>(
417417
pure(OmpLastprivateClause::LastprivateModifier::Conditional) / ":"),
418418
Parser<OmpObjectList>{}))
419419

420+
// OMP 5.2 11.7.1 BIND ( PARALLEL | TEAMS | THREAD )
421+
TYPE_PARSER(construct<OmpBindClause>(
422+
"PARALLEL" >> pure(OmpBindClause::Type::Parallel) ||
423+
"TEAMS" >> pure(OmpBindClause::Type::Teams) ||
424+
"THREAD" >> pure(OmpBindClause::Type::Thread)))
425+
420426
TYPE_PARSER(
421427
"ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) ||
422428
"ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) ||
@@ -431,6 +437,8 @@ TYPE_PARSER(
431437
"ATOMIC_DEFAULT_MEM_ORDER" >>
432438
construct<OmpClause>(construct<OmpClause::AtomicDefaultMemOrder>(
433439
parenthesized(Parser<OmpAtomicDefaultMemOrderClause>{}))) ||
440+
"BIND" >> construct<OmpClause>(construct<OmpClause::Bind>(
441+
parenthesized(Parser<OmpBindClause>{}))) ||
434442
"COLLAPSE" >> construct<OmpClause>(construct<OmpClause::Collapse>(
435443
parenthesized(scalarIntConstantExpr))) ||
436444
"COPYIN" >> construct<OmpClause>(construct<OmpClause::Copyin>(

flang/test/Parser/OpenMP/target-loop-unparse.f90

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
! RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=50 %s | \
2+
! RUN: FileCheck --ignore-case %s
13

2-
! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck --ignore-case %s
3-
! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s
4+
! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=50 %s | \
5+
! RUN: FileCheck --check-prefix="PARSE-TREE" %s
46

57
! Check for parsing of loop directive
68

@@ -14,6 +16,16 @@ subroutine test_loop
1416
j = j + 1
1517
end do
1618
!$omp end loop
19+
20+
!PARSE-TREE: OmpBeginLoopDirective
21+
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = loop
22+
!PARSE-TREE-NEXT: OmpClauseList -> OmpClause -> Bind -> OmpBindClause -> Type = Thread
23+
!CHECK: !$omp loop
24+
!$omp loop bind(thread)
25+
do i=1,10
26+
j = j + 1
27+
end do
28+
!$omp end loop
1729
end subroutine
1830

1931
subroutine test_target_loop

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def OMPC_AtomicDefaultMemOrder : Clause<"atomic_default_mem_order"> {
7373
}
7474
def OMPC_Bind : Clause<"bind"> {
7575
let clangClass = "OMPBindClause";
76+
let flangClass = "OmpBindClause";
7677
}
7778
def OMP_CANCELLATION_CONSTRUCT_Parallel : ClauseVal<"parallel", 1, 1> {}
7879
def OMP_CANCELLATION_CONSTRUCT_Loop : ClauseVal<"loop", 2, 1> {}

0 commit comments

Comments
 (0)