Skip to content

Commit 6e08397

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 d3f70db commit 6e08397

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
@@ -551,6 +551,8 @@ class ParseTreeDumper {
551551
NODE_ENUM(OmpGrainsizeClause, Prescriptiveness)
552552
NODE(parser, OmpNumTasksClause)
553553
NODE_ENUM(OmpNumTasksClause, Prescriptiveness)
554+
NODE(parser, OmpBindClause)
555+
NODE_ENUM(OmpBindClause, Type)
554556
NODE(parser, OmpProcBindClause)
555557
NODE_ENUM(OmpProcBindClause, Type)
556558
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
@@ -3702,6 +3702,13 @@ struct OmpNumTasksClause {
37023702
std::tuple<std::optional<Prescriptiveness>, ScalarIntExpr> t;
37033703
};
37043704

3705+
// OMP 5.2 11.7.1 bind-clause ->
3706+
// BIND( PARALLEL | TEAMS | THREAD )
3707+
struct OmpBindClause {
3708+
ENUM_CLASS(Type, Parallel, Teams, Thread)
3709+
WRAPPER_CLASS_BOILERPLATE(OmpBindClause, Type);
3710+
};
3711+
37053712
// OpenMP Clauses
37063713
struct OmpClause {
37073714
UNION_CLASS_BOILERPLATE(OmpClause);

flang/lib/Parser/openmp-parsers.cpp

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

430+
// OMP 5.2 11.7.1 BIND ( PARALLEL | TEAMS | THREAD )
431+
TYPE_PARSER(construct<OmpBindClause>(
432+
"PARALLEL" >> pure(OmpBindClause::Type::Parallel) ||
433+
"TEAMS" >> pure(OmpBindClause::Type::Teams) ||
434+
"THREAD" >> pure(OmpBindClause::Type::Thread)))
435+
430436
TYPE_PARSER(
431437
"ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) ||
432438
"ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) ||
@@ -441,6 +447,8 @@ TYPE_PARSER(
441447
"ATOMIC_DEFAULT_MEM_ORDER" >>
442448
construct<OmpClause>(construct<OmpClause::AtomicDefaultMemOrder>(
443449
parenthesized(Parser<OmpAtomicDefaultMemOrderClause>{}))) ||
450+
"BIND" >> construct<OmpClause>(construct<OmpClause::Bind>(
451+
parenthesized(Parser<OmpBindClause>{}))) ||
444452
"COLLAPSE" >> construct<OmpClause>(construct<OmpClause::Collapse>(
445453
parenthesized(scalarIntConstantExpr))) ||
446454
"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)