Skip to content

Commit 0dbea52

Browse files
authored
[flang][OpenMP] Parse TASKGRAPH, GRAPH_ID, and GRAPH_RESET (#157926)
This is parsing only, no semantic check are performed.
1 parent 9641399 commit 0dbea52

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,8 @@ class ParseTreeDumper {
583583
NODE(OmpFromClause, Modifier)
584584
NODE(parser, OmpGrainsizeClause)
585585
NODE(OmpGrainsizeClause, Modifier)
586+
NODE(parser, OmpGraphIdClause)
587+
NODE(parser, OmpGraphResetClause)
586588
NODE(parser, OmpHintClause)
587589
NODE(parser, OmpHoldsClause)
588590
NODE(parser, OmpIfClause)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,6 +4430,22 @@ struct OmpGrainsizeClause {
44304430
std::tuple<MODIFIERS(), ScalarIntExpr> t;
44314431
};
44324432

4433+
// Ref: [6.0:438]
4434+
//
4435+
// graph_id-clause ->
4436+
// GRAPH_ID(graph-id-value) // since 6.0
4437+
struct OmpGraphIdClause {
4438+
WRAPPER_CLASS_BOILERPLATE(OmpGraphIdClause, common::Indirection<Expr>);
4439+
};
4440+
4441+
// Ref: [6.0:438-439]
4442+
//
4443+
// graph_reset-clause ->
4444+
// GRAPH_RESET[(graph-reset-expression)] // since 6.0
4445+
struct OmpGraphResetClause {
4446+
WRAPPER_CLASS_BOILERPLATE(OmpGraphResetClause, common::Indirection<Expr>);
4447+
};
4448+
44334449
// Ref: [5.0:234-242], [5.1:266-275], [5.2:299], [6.0:472-473]
44344450
struct OmpHintClause {
44354451
WRAPPER_CLASS_BOILERPLATE(OmpHintClause, ScalarIntConstantExpr);

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,10 @@ TYPE_PARSER(construct<OmpFailClause>(
802802
"RELEASE" >> pure(common::OmpMemoryOrderType::Release) ||
803803
"SEQ_CST" >> pure(common::OmpMemoryOrderType::Seq_Cst)))
804804

805+
TYPE_PARSER(construct<OmpGraphIdClause>(expr))
806+
807+
TYPE_PARSER(construct<OmpGraphResetClause>(expr))
808+
805809
// 2.5 PROC_BIND (MASTER | CLOSE | PRIMARY | SPREAD)
806810
TYPE_PARSER(construct<OmpProcBindClause>(
807811
"CLOSE" >> pure(OmpProcBindClause::AffinityPolicy::Close) ||
@@ -1102,6 +1106,11 @@ TYPE_PARSER( //
11021106
"FULL" >> construct<OmpClause>(construct<OmpClause::Full>()) ||
11031107
"GRAINSIZE" >> construct<OmpClause>(construct<OmpClause::Grainsize>(
11041108
parenthesized(Parser<OmpGrainsizeClause>{}))) ||
1109+
"GRAPH_ID" >> construct<OmpClause>(construct<OmpClause::GraphId>(
1110+
parenthesized(Parser<OmpGraphIdClause>{}))) ||
1111+
"GRAPH_RESET" >>
1112+
construct<OmpClause>(construct<OmpClause::GraphReset>(
1113+
maybe(parenthesized(Parser<OmpGraphResetClause>{})))) ||
11051114
"HAS_DEVICE_ADDR" >>
11061115
construct<OmpClause>(construct<OmpClause::HasDeviceAddr>(
11071116
parenthesized(Parser<OmpObjectList>{}))) ||
@@ -1872,6 +1881,7 @@ TYPE_PARSER( //
18721881
llvm::omp::Directive::OMPD_target_teams_workdistribute) ||
18731882
MakeBlockConstruct(llvm::omp::Directive::OMPD_target) ||
18741883
MakeBlockConstruct(llvm::omp::Directive::OMPD_task) ||
1884+
MakeBlockConstruct(llvm::omp::Directive::OMPD_taskgraph) ||
18751885
MakeBlockConstruct(llvm::omp::Directive::OMPD_taskgroup) ||
18761886
MakeBlockConstruct(llvm::omp::Directive::OMPD_teams) ||
18771887
MakeBlockConstruct(llvm::omp::Directive::OMPD_teams_workdistribute) ||

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "flang/Evaluate/fold.h"
1616
#include "flang/Evaluate/tools.h"
1717
#include "flang/Evaluate/type.h"
18+
#include "flang/Parser/openmp-utils.h"
1819
#include "flang/Parser/parse-tree-visitor.h"
1920
#include "flang/Parser/parse-tree.h"
2021
#include "flang/Parser/tools.h"
@@ -579,6 +580,12 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
579580
bool Pre(const parser::OpenMPAllocatorsConstruct &);
580581
void Post(const parser::OpenMPAllocatorsConstruct &);
581582

583+
bool Pre(const parser::OpenMPUtilityConstruct &x) {
584+
PushContext(x.source, parser::omp::GetOmpDirectiveName(x).v);
585+
return true;
586+
}
587+
void Post(const parser::OpenMPUtilityConstruct &) { PopContext(); }
588+
582589
bool Pre(const parser::OmpDeclareVariantDirective &x) {
583590
PushContext(x.source, llvm::omp::Directive::OMPD_declare_variant);
584591
return true;
@@ -1790,6 +1797,7 @@ bool OmpAttributeVisitor::Pre(const parser::OmpBlockConstruct &x) {
17901797
case llvm::omp::Directive::OMPD_target:
17911798
case llvm::omp::Directive::OMPD_target_data:
17921799
case llvm::omp::Directive::OMPD_task:
1800+
case llvm::omp::Directive::OMPD_taskgraph:
17931801
case llvm::omp::Directive::OMPD_taskgroup:
17941802
case llvm::omp::Directive::OMPD_teams:
17951803
case llvm::omp::Directive::OMPD_workdistribute:
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
!RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=60 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
2+
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=60 %s | FileCheck --check-prefix="PARSE-TREE" %s
3+
4+
subroutine f00
5+
!$omp taskgraph
6+
block
7+
end block
8+
end
9+
10+
!UNPARSE: SUBROUTINE f00
11+
!UNPARSE: !$OMP TASKGRAPH
12+
!UNPARSE: BLOCK
13+
!UNPARSE: END BLOCK
14+
!UNPARSE: END SUBROUTINE
15+
16+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpBlockConstruct
17+
!PARSE-TREE: | OmpBeginDirective
18+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = taskgraph
19+
!PARSE-TREE: | | OmpClauseList ->
20+
!PARSE-TREE: | | Flags = None
21+
!PARSE-TREE: | Block
22+
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> BlockConstruct
23+
!PARSE-TREE: | | | BlockStmt ->
24+
!PARSE-TREE: | | | BlockSpecificationPart -> SpecificationPart
25+
!PARSE-TREE: | | | | ImplicitPart ->
26+
!PARSE-TREE: | | | Block
27+
!PARSE-TREE: | | | EndBlockStmt ->
28+
29+
30+
subroutine f01(x, y)
31+
integer :: x
32+
logical :: y
33+
!$omp taskgraph graph_id(x) graph_reset(y)
34+
!$omp task
35+
continue
36+
!$omp end task
37+
!$omp end taskgraph
38+
end
39+
40+
!UNPARSE: SUBROUTINE f01 (x, y)
41+
!UNPARSE: INTEGER x
42+
!UNPARSE: LOGICAL y
43+
!UNPARSE: !$OMP TASKGRAPH GRAPH_ID(x) GRAPH_RESET(y)
44+
!UNPARSE: !$OMP TASK
45+
!UNPARSE: CONTINUE
46+
!UNPARSE: !$OMP END TASK
47+
!UNPARSE: !$OMP END TASKGRAPH
48+
!UNPARSE: END SUBROUTINE
49+
50+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpBlockConstruct
51+
!PARSE-TREE: | OmpBeginDirective
52+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = taskgraph
53+
!PARSE-TREE: | | OmpClauseList -> OmpClause -> GraphId -> OmpGraphIdClause -> Expr = 'x'
54+
!PARSE-TREE: | | | Designator -> DataRef -> Name = 'x'
55+
!PARSE-TREE: | | OmpClause -> GraphReset -> OmpGraphResetClause -> Expr = 'y'
56+
!PARSE-TREE: | | | Designator -> DataRef -> Name = 'y'
57+
!PARSE-TREE: | | Flags = None
58+
!PARSE-TREE: | Block
59+
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpBlockConstruct
60+
!PARSE-TREE: | | | OmpBeginDirective
61+
!PARSE-TREE: | | | | OmpDirectiveName -> llvm::omp::Directive = task
62+
!PARSE-TREE: | | | | OmpClauseList ->
63+
!PARSE-TREE: | | | | Flags = None
64+
!PARSE-TREE: | | | Block
65+
!PARSE-TREE: | | | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> ContinueStmt
66+
!PARSE-TREE: | | | OmpEndDirective
67+
!PARSE-TREE: | | | | OmpDirectiveName -> llvm::omp::Directive = task
68+
!PARSE-TREE: | | | | OmpClauseList ->
69+
!PARSE-TREE: | | | | Flags = None
70+
!PARSE-TREE: | OmpEndDirective
71+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = taskgraph
72+
!PARSE-TREE: | | OmpClauseList ->
73+
!PARSE-TREE: | | Flags = None
74+
75+
76+
subroutine f02
77+
!$omp taskgraph graph_reset
78+
!$omp end taskgraph
79+
end
80+
81+
!UNPARSE: SUBROUTINE f02
82+
!UNPARSE: !$OMP TASKGRAPH GRAPH_RESET
83+
!UNPARSE: !$OMP END TASKGRAPH
84+
!UNPARSE: END SUBROUTINE
85+
86+
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OmpBlockConstruct
87+
!PARSE-TREE: | OmpBeginDirective
88+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = taskgraph
89+
!PARSE-TREE: | | OmpClauseList -> OmpClause -> GraphReset ->
90+
!PARSE-TREE: | | Flags = None
91+
!PARSE-TREE: | Block
92+
!PARSE-TREE: | OmpEndDirective
93+
!PARSE-TREE: | | OmpDirectiveName -> llvm::omp::Directive = taskgraph
94+
!PARSE-TREE: | | OmpClauseList ->
95+
!PARSE-TREE: | | Flags = None

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,11 @@ def OMPC_GrainSize : Clause<[Spelling<"grainsize">]> {
227227
];
228228
}
229229
def OMPC_GraphId : Clause<[Spelling<"graph_id">]> {
230+
let flangClass = "OmpGraphIdClause";
230231
}
231232
def OMPC_GraphReset : Clause<[Spelling<"graph_reset">]> {
233+
let flangClass = "OmpGraphResetClause";
234+
let isValueOptional = true;
232235
}
233236
def OMPC_HasDeviceAddr : Clause<[Spelling<"has_device_addr">]> {
234237
let clangClass = "OMPHasDeviceAddrClause";

0 commit comments

Comments
 (0)