Skip to content

Commit 8efec33

Browse files
committed
Refactored the Interop Construct and modified the testcases.
1 parent 7b1fca9 commit 8efec33

File tree

5 files changed

+38
-24
lines changed

5 files changed

+38
-24
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4985,9 +4985,8 @@ struct OpenMPFlushConstruct {
49854985
//
49864986
// interop -> INTEROP clause[ [ [,] clause]...]
49874987
struct OpenMPInteropConstruct {
4988-
TUPLE_CLASS_BOILERPLATE(OpenMPInteropConstruct);
4988+
WRAPPER_CLASS_BOILERPLATE(OpenMPInteropConstruct, OmpDirectiveSpecification);
49894989
CharBlock source;
4990-
std::tuple<Verbatim, OmpClauseList> t;
49914990
};
49924991

49934992
struct OpenMPSimpleStandaloneConstruct {

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,11 @@ TYPE_PARSER(sourced( //
12771277
Parser<OmpDirectiveSpecification>{})))
12781278

12791279
// OMP 5.2 14.1 Interop construct
1280-
TYPE_PARSER(sourced(construct<OpenMPInteropConstruct>(
1281-
verbatim("INTEROP"_tok), sourced(Parser<OmpClauseList>{}))))
1280+
TYPE_PARSER(sourced( //
1281+
construct<OpenMPInteropConstruct>(
1282+
predicated(OmpDirectiveNameParser{},
1283+
IsDirective(llvm::omp::Directive::OMPD_interop)) >=
1284+
Parser<OmpDirectiveSpecification>{})))
12821285

12831286
// Standalone Constructs
12841287
TYPE_PARSER(

flang/lib/Parser/unparse.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,14 @@ class UnparseVisitor {
27382738
void Unparse(const OpenMPInteropConstruct &x) {
27392739
BeginOpenMP();
27402740
Word("!$OMP INTEROP");
2741-
Walk(std::get<OmpClauseList>(x.t));
2741+
using Flags = OmpDirectiveSpecification::Flags;
2742+
if (std::get<Flags>(x.v.t) == Flags::DeprecatedSyntax) {
2743+
Walk("(", std::get<std::optional<OmpArgumentList>>(x.v.t), ")");
2744+
Walk(" ", std::get<std::optional<OmpClauseList>>(x.v.t));
2745+
} else {
2746+
Walk(" ", std::get<std::optional<OmpClauseList>>(x.v.t));
2747+
Walk(" (", std::get<std::optional<OmpArgumentList>>(x.v.t), ")");
2748+
}
27422749
Put("\n");
27432750
EndOpenMP();
27442751
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5733,11 +5733,11 @@ void OmpStructureChecker::Leave(const parser::DoConstruct &x) {
57335733
void OmpStructureChecker::Enter(const parser::OpenMPInteropConstruct &x) {
57345734
bool isDependClauseOccured{false};
57355735
int targetCount{0}, targetSyncCount{0};
5736-
const auto &dir{std::get<parser::Verbatim>(x.t)};
5736+
const auto &dir{std::get<parser::OmpDirectiveName>(x.v.t)};
57375737
std::set<const Symbol *> objectSymbolList;
57385738
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_interop);
5739-
const auto &clauseList{std::get<parser::OmpClauseList>(x.t)};
5740-
for (const auto &clause : clauseList.v) {
5739+
const auto &clauseList{std::get<std::optional<parser::OmpClauseList>>(x.v.t)};
5740+
for (const auto &clause : clauseList->v) {
57415741
common::visit(
57425742
common::visitors{
57435743
[&](const parser::OmpClause::Init &initClause) {

flang/test/Parser/OpenMP/interop-construct.f90

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SUBROUTINE test_interop_01()
88
END SUBROUTINE test_interop_01
99

1010
!UNPARSE: SUBROUTINE test_interop_01
11-
!UNPARSE: !$OMP INTEROP DEVICE(1_4)
11+
!UNPARSE: !$OMP INTEROP DEVICE(1_4)
1212
!UNPARSE: PRINT *, "pass"
1313
!UNPARSE: END SUBROUTINE test_interop_01
1414

@@ -17,10 +17,11 @@ END SUBROUTINE test_interop_01
1717
!PARSE-TREE: | SpecificationPart
1818
!PARSE-TREE: | | ImplicitPart ->
1919
!PARSE-TREE: | ExecutionPart -> Block
20-
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct
21-
!PARSE-TREE: | | | Verbatim
20+
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct -> OmpDirectiveSpecification
21+
!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = interop
2222
!PARSE-TREE: | | | OmpClauseList -> OmpClause -> Device -> OmpDeviceClause
2323
!PARSE-TREE: | | | | Scalar -> Integer -> Expr -> LiteralConstant -> IntLiteralConstant = '1'
24+
!PARSE-TREE: | | | Flags = None
2425
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> PrintStmt
2526
!PARSE-TREE: | | | Format -> Star
2627
!PARSE-TREE: | | | OutputItem -> Expr -> LiteralConstant -> CharLiteralConstant
@@ -37,7 +38,7 @@ END SUBROUTINE test_interop_02
3738
!UNPARSE: SUBROUTINE test_interop_02
3839
!UNPARSE: USE :: omp_lib
3940
!UNPARSE: INTEGER(KIND=8_4) obj1, obj2, obj3
40-
!UNPARSE: !$OMP INTEROP INIT(TARGETSYNC: obj) USE(obj1) DESTROY(obj3)
41+
!UNPARSE: !$OMP INTEROP INIT(TARGETSYNC: obj) USE(obj1) DESTROY(obj3)
4142
!UNPARSE: PRINT *, "pass"
4243
!UNPARSE: END SUBROUTINE test_interop_02
4344

@@ -56,13 +57,14 @@ END SUBROUTINE test_interop_02
5657
!PARSE-TREE: | | | EntityDecl
5758
!PARSE-TREE: | | | | Name = 'obj3'
5859
!PARSE-TREE: | ExecutionPart -> Block
59-
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct
60-
!PARSE-TREE: | | | Verbatim
60+
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct -> OmpDirectiveSpecification
61+
!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = interop
6162
!PARSE-TREE: | | | OmpClauseList -> OmpClause -> Init -> OmpInitClause
6263
!PARSE-TREE: | | | | Modifier -> OmpInteropType -> Value = TargetSync
6364
!PARSE-TREE: | | | | OmpObject -> Designator -> DataRef -> Name = 'obj'
6465
!PARSE-TREE: | | | OmpClause -> Use -> OmpUseClause -> OmpObject -> Designator -> DataRef -> Name = 'obj1'
6566
!PARSE-TREE: | | | OmpClause -> Destroy -> OmpDestroyClause -> OmpObject -> Designator -> DataRef -> Name = 'obj3'
67+
!PARSE-TREE: | | | Flags = None
6668
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> PrintStmt
6769
!PARSE-TREE: | | | Format -> Star
6870
!PARSE-TREE: | | | OutputItem -> Expr -> LiteralConstant -> CharLiteralConstant
@@ -79,7 +81,7 @@ END SUBROUTINE test_interop_03
7981
!UNPARSE: SUBROUTINE test_interop_03
8082
!UNPARSE: USE :: omp_lib
8183
!UNPARSE: INTEGER(KIND=8_4) obj
82-
!UNPARSE: !$OMP INTEROP INIT(TARGETSYNC: obj) DEPEND(INOUT: obj)
84+
!UNPARSE: !$OMP INTEROP INIT(TARGETSYNC: obj) DEPEND(INOUT: obj)
8385
!UNPARSE: PRINT *, "pass"
8486
!UNPARSE: END SUBROUTINE test_interop_03
8587

@@ -94,14 +96,15 @@ END SUBROUTINE test_interop_03
9496
!PARSE-TREE: | | | EntityDecl
9597
!PARSE-TREE: | | | | Name = 'obj'
9698
!PARSE-TREE: | ExecutionPart -> Block
97-
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct
98-
!PARSE-TREE: | | | Verbatim
99+
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct -> OmpDirectiveSpecification
100+
!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = interop
99101
!PARSE-TREE: | | | OmpClauseList -> OmpClause -> Init -> OmpInitClause
100102
!PARSE-TREE: | | | | Modifier -> OmpInteropType -> Value = TargetSync
101103
!PARSE-TREE: | | | | OmpObject -> Designator -> DataRef -> Name = 'obj'
102104
!PARSE-TREE: | | | OmpClause -> Depend -> OmpDependClause -> TaskDep
103105
!PARSE-TREE: | | | | Modifier -> OmpTaskDependenceType -> Value = Inout
104106
!PARSE-TREE: | | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'obj'
107+
!PARSE-TREE: | | | Flags = None
105108
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> PrintStmt
106109
!PARSE-TREE: | | | Format -> Star
107110
!PARSE-TREE: | | | OutputItem -> Expr -> LiteralConstant -> CharLiteralConstant
@@ -120,8 +123,8 @@ END SUBROUTINE test_interop_04
120123
!UNPARSE: USE :: omp_lib
121124
!UNPARSE: INTEGER(KIND=8_4) obj
122125
!UNPARSE: INTEGER, DIMENSION(1_4,10_4) :: arr
123-
!UNPARSE: !$OMP INTEROP INIT(PREFER_TYPE("cuda"),TARGETSYNC,TARGET: obj) DEPEND(INOUT: a&
124-
!UNPARSE: !$OMP&rr) NOWAIT
126+
!UNPARSE: !$OMP INTEROP INIT(PREFER_TYPE("cuda"),TARGETSYNC,TARGET: obj) DEPEND(INOUT: &
127+
!UNPARSE: !$OMP&arr) NOWAIT
125128
!UNPARSE: PRINT *, "pass"
126129
!UNPARSE: END SUBROUTINE test_interop_04
127130

@@ -144,8 +147,8 @@ END SUBROUTINE test_interop_04
144147
!PARSE-TREE: | | | EntityDecl
145148
!PARSE-TREE: | | | | Name = 'arr'
146149
!PARSE-TREE: | ExecutionPart -> Block
147-
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct
148-
!PARSE-TREE: | | | Verbatim
150+
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct -> OmpDirectiveSpecification
151+
!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = interop
149152
!PARSE-TREE: | | | OmpClauseList -> OmpClause -> Init -> OmpInitClause
150153
!PARSE-TREE: | | | | Modifier -> OmpInteropPreference -> OmpInteropRuntimeIdentifier -> CharLiteralConstant
151154
!PARSE-TREE: | | | | | string = 'cuda'
@@ -156,6 +159,7 @@ END SUBROUTINE test_interop_04
156159
!PARSE-TREE: | | | | Modifier -> OmpTaskDependenceType -> Value = Inout
157160
!PARSE-TREE: | | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'arr'
158161
!PARSE-TREE: | | | OmpClause -> Nowait
162+
!PARSE-TREE: | | | Flags = None
159163
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> PrintStmt
160164
!PARSE-TREE: | | | Format -> Star
161165
!PARSE-TREE: | | | OutputItem -> Expr -> LiteralConstant -> CharLiteralConstant
@@ -172,7 +176,7 @@ END SUBROUTINE test_interop_05
172176
!UNPARSE: SUBROUTINE test_interop_05
173177
!UNPARSE: USE :: omp_lib
174178
!UNPARSE: INTEGER(KIND=8_4) obj
175-
!UNPARSE: !$OMP INTEROP INIT(PREFER_TYPE(4_4),TARGETSYNC: obj) DEVICE(DEVICE_NUM: 0_4)
179+
!UNPARSE: !$OMP INTEROP INIT(PREFER_TYPE(4_4),TARGETSYNC: obj) DEVICE(DEVICE_NUM: 0_4)
176180
!UNPARSE: PRINT *, "pass"
177181
!UNPARSE: END SUBROUTINE test_interop_05
178182

@@ -187,15 +191,16 @@ END SUBROUTINE test_interop_05
187191
!PARSE-TREE: | | | EntityDecl
188192
!PARSE-TREE: | | | | Name = 'obj'
189193
!PARSE-TREE: | ExecutionPart -> Block
190-
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct
191-
!PARSE-TREE: | | | Verbatim
194+
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OpenMPInteropConstruct -> OmpDirectiveSpecification
195+
!PARSE-TREE: | | | OmpDirectiveName -> llvm::omp::Directive = interop
192196
!PARSE-TREE: | | | OmpClauseList -> OmpClause -> Init -> OmpInitClause
193197
!PARSE-TREE: | | | | Modifier -> OmpInteropPreference -> OmpInteropRuntimeIdentifier -> Scalar -> Integer -> Constant -> Expr -> Designator -> DataRef -> Name = 'omp_ifr_sycl'
194198
!PARSE-TREE: | | | | Modifier -> OmpInteropType -> Value = TargetSync
195199
!PARSE-TREE: | | | | OmpObject -> Designator -> DataRef -> Name = 'obj'
196200
!PARSE-TREE: | | | OmpClause -> Device -> OmpDeviceClause
197201
!PARSE-TREE: | | | | Modifier -> OmpDeviceModifier -> Value = Device_Num
198202
!PARSE-TREE: | | | | Scalar -> Integer -> Expr -> LiteralConstant -> IntLiteralConstant = '0'
203+
!PARSE-TREE: | | | Flags = None
199204
!PARSE-TREE: | | ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> PrintStmt
200205
!PARSE-TREE: | | | Format -> Star
201206
!PARSE-TREE: | | | OutputItem -> Expr -> LiteralConstant -> CharLiteralConstant

0 commit comments

Comments
 (0)