Skip to content

Commit 6dfe20d

Browse files
authored
[flang][OpenMP] Parse METADIRECTIVE in specification part (#123397)
Add METADIRECTIVE to the OpenMP declarative constructs as well. Emit a TODO error for both declarative and executable cases.
1 parent c7c7eab commit 6dfe20d

File tree

8 files changed

+89
-8
lines changed

8 files changed

+89
-8
lines changed

flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ std::string OpenMPCounterVisitor::getName(const OpenMPDeclarativeConstruct &c) {
112112
const CharBlock &source{o.source};
113113
return normalize_construct_name(source.ToString());
114114
},
115+
[&](const OmpMetadirectiveDirective &o) -> std::string {
116+
const CharBlock &source{o.source};
117+
return normalize_construct_name(source.ToString());
118+
},
115119
[&](const auto &o) -> std::string {
116120
const CharBlock &source{std::get<Verbatim>(o.t).source};
117121
return normalize_construct_name(source.ToString());

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4540,8 +4540,8 @@ struct OpenMPDeclarativeConstruct {
45404540
CharBlock source;
45414541
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclareMapperConstruct,
45424542
OpenMPDeclareReductionConstruct, OpenMPDeclareSimdConstruct,
4543-
OpenMPDeclareTargetConstruct, OpenMPThreadprivate,
4544-
OpenMPRequiresConstruct, OpenMPUtilityConstruct>
4543+
OpenMPThreadprivate, OpenMPRequiresConstruct, OpenMPUtilityConstruct,
4544+
OpenMPDeclareTargetConstruct, OmpMetadirectiveDirective>
45454545
u;
45464546
};
45474547

flang/lib/Lower/OpenMP/OpenMP.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -3142,6 +3142,13 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
31423142
// support the case of threadprivate variable declared in module.
31433143
}
31443144

3145+
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
3146+
semantics::SemanticsContext &semaCtx,
3147+
lower::pft::Evaluation &eval,
3148+
const parser::OmpMetadirectiveDirective &meta) {
3149+
TODO(converter.getCurrentLocation(), "METADIRECTIVE");
3150+
}
3151+
31453152
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
31463153
semantics::SemanticsContext &semaCtx,
31473154
lower::pft::Evaluation &eval,
@@ -3234,11 +3241,6 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
32343241
TODO(converter.getCurrentLocation(), "OpenMPDepobjConstruct");
32353242
}
32363243

3237-
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
3238-
semantics::SemanticsContext &semaCtx,
3239-
lower::pft::Evaluation &eval,
3240-
const parser::OmpMetadirectiveDirective &construct) {}
3241-
32423244
static void
32433245
genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
32443246
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,

flang/lib/Parser/openmp-parsers.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,9 @@ TYPE_PARSER(startOmpLine >>
12971297
construct<OpenMPDeclarativeConstruct>(
12981298
Parser<OpenMPThreadprivate>{}) ||
12991299
construct<OpenMPDeclarativeConstruct>(
1300-
Parser<OpenMPUtilityConstruct>{})) /
1300+
Parser<OpenMPUtilityConstruct>{}) ||
1301+
construct<OpenMPDeclarativeConstruct>(
1302+
Parser<OmpMetadirectiveDirective>{})) /
13011303
endOmpLine))
13021304

13031305
// Block Construct
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!RUN: %not_todo_cmd bbc -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s
2+
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s
3+
4+
!CHECK: not yet implemented: METADIRECTIVE
5+
subroutine f00
6+
continue
7+
!Executable
8+
!$omp metadirective when(user={condition(.true.)}: nothing)
9+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!RUN: %not_todo_cmd bbc -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s
2+
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s
3+
4+
!CHECK: not yet implemented: METADIRECTIVE
5+
subroutine f00
6+
!Specification
7+
!$omp metadirective when(user={condition(.true.)}: nothing)
8+
implicit none
9+
end

flang/test/Parser/OpenMP/metadirective-v50.f90

+2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=50 %s | FileCheck --check-prefix="PARSE-TREE" %s
33

44
subroutine f01
5+
continue
56
!$omp metadirective &
67
!$omp & when(user={condition(.true.)}: nothing) &
78
!$omp & default(nothing)
89
end
910

1011
!UNPARSE: SUBROUTINE f01
12+
!UNPARSE: CONTINUE
1113
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: NOTHING) DEFAULT(NOTHING)
1214
!UNPARSE: END SUBROUTINE
1315

flang/test/Parser/OpenMP/metadirective.f90

+53
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=52 %s | FileCheck --check-prefix="PARSE-TREE" %s
33

44
subroutine f00
5+
continue
56
!$omp metadirective when(construct={target, parallel}: nothing)
67
end
78

89
!UNPARSE: SUBROUTINE f00
10+
!UNPARSE: CONTINUE
911
!UNPARSE: !$OMP METADIRECTIVE WHEN(CONSTRUCT={TARGET, PARALLEL}: NOTHING)
1012
!UNPARSE: END SUBROUTINE
1113

@@ -22,10 +24,12 @@ subroutine f00
2224
!PARSE-TREE: | | | OmpClauseList ->
2325

2426
subroutine f01
27+
continue
2528
!$omp metadirective when(target_device={kind(host), device_num(1)}: nothing)
2629
end
2730

2831
!UNPARSE: SUBROUTINE f01
32+
!UNPARSE: CONTINUE
2933
!UNPARSE: !$OMP METADIRECTIVE WHEN(TARGET_DEVICE={KIND(host), DEVICE_NUM(1_4)}: NOTHING)
3034
!UNPARSE: END SUBROUTINE
3135

@@ -47,10 +51,12 @@ subroutine f01
4751
!PARSE-TREE: | | | OmpClauseList ->
4852

4953
subroutine f02
54+
continue
5055
!$omp metadirective when(target_device={kind(any), device_num(7)}: nothing)
5156
end
5257

5358
!UNPARSE: SUBROUTINE f02
59+
!UNPARSE: CONTINUE
5460
!UNPARSE: !$OMP METADIRECTIVE WHEN(TARGET_DEVICE={KIND(any), DEVICE_NUM(7_4)}: NOTHING)
5561
!UNPARSE: END SUBROUTINE
5662

@@ -72,11 +78,13 @@ subroutine f02
7278
!PARSE-TREE: | | | OmpClauseList ->
7379

7480
subroutine f03
81+
continue
7582
!$omp metadirective &
7683
!$omp & when(implementation={atomic_default_mem_order(acq_rel)}: nothing)
7784
end
7885

7986
!UNPARSE: SUBROUTINE f03
87+
!UNPARSE: CONTINUE
8088
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={ATOMIC_DEFAULT_MEM_ORDER(ACQ_REL)}: &
8189
!UNPARSE: !$OMP&NOTHING)
8290
!UNPARSE: END SUBROUTINE
@@ -94,11 +102,13 @@ subroutine f03
94102
!PARSE-TREE: | | | OmpClauseList ->
95103

96104
subroutine f04
105+
continue
97106
!$omp metadirective &
98107
!$omp when(implementation={extension_trait(haha(1), foo(baz, "bar"(1)))}: nothing)
99108
end
100109

101110
!UNPARSE: SUBROUTINE f04
111+
!UNPARSE: CONTINUE
102112
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={extension_trait(haha(1_4), foo(baz,bar(1_4&
103113
!UNPARSE: !$OMP&)))}: NOTHING)
104114
!UNPARSE: END SUBROUTINE
@@ -127,6 +137,7 @@ subroutine f04
127137

128138
subroutine f05(x)
129139
integer :: x
140+
continue
130141
!$omp metadirective &
131142
!$omp & when(user={condition(score(100): .true.)}: &
132143
!$omp & parallel do reduction(+: x)) &
@@ -137,6 +148,7 @@ subroutine f05(x)
137148

138149
!UNPARSE: SUBROUTINE f05 (x)
139150
!UNPARSE: INTEGER x
151+
!UNPARSE: CONTINUE
140152
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(SCORE(100_4): .true._4)}: PARALLEL DO REDUCTION(+&
141153
!UNPARSE: !$OMP&: x)) OTHERWISE(NOTHING)
142154
!UNPARSE: DO i=1_4,10_4
@@ -165,13 +177,15 @@ subroutine f05(x)
165177
!PARSE-TREE: | | OmpClauseList ->
166178

167179
subroutine f06
180+
continue
168181
! Two trait set selectors
169182
!$omp metadirective &
170183
!$omp & when(implementation={vendor("amd")}, &
171184
!$omp & user={condition(.true.)}: nothing)
172185
end
173186

174187
!UNPARSE: SUBROUTINE f06
188+
!UNPARSE: CONTINUE
175189
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={VENDOR(amd)}, USER={CONDITION(.true._4)}: NO&
176190
!UNPARSE: !$OMP&THING)
177191
!UNPARSE: END SUBROUTINE
@@ -196,3 +210,42 @@ subroutine f06
196210
!PARSE-TREE: | | | llvm::omp::Directive = nothing
197211
!PARSE-TREE: | | | OmpClauseList ->
198212

213+
subroutine f07
214+
! Declarative metadirective
215+
!$omp metadirective &
216+
!$omp & when(implementation={vendor("amd")}: declare simd) &
217+
!$omp & when(user={condition(.true.)}: declare target) &
218+
!$omp & otherwise(nothing)
219+
end
220+
221+
!UNPARSE: SUBROUTINE f07
222+
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={VENDOR(amd)}: DECLARE SIMD) WHEN(USE&
223+
!UNPARSE: !$OMP&R={CONDITION(.true._4)}: DECLARE TARGET) OTHERWISE(NOTHING)
224+
!UNPARSE: END SUBROUTINE
225+
226+
!PARSE-TREE: OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
227+
!PARSE-TREE: | OmpClauseList -> OmpClause -> When -> OmpWhenClause
228+
!PARSE-TREE: | | Modifier -> OmpContextSelectorSpecification -> OmpTraitSetSelector
229+
!PARSE-TREE: | | | OmpTraitSetSelectorName -> Value = Implementation
230+
!PARSE-TREE: | | | OmpTraitSelector
231+
!PARSE-TREE: | | | | OmpTraitSelectorName -> Value = Vendor
232+
!PARSE-TREE: | | | | Properties
233+
!PARSE-TREE: | | | | | OmpTraitProperty -> OmpTraitPropertyName -> string = 'amd'
234+
!PARSE-TREE: | | OmpDirectiveSpecification
235+
!PARSE-TREE: | | | llvm::omp::Directive = declare simd
236+
!PARSE-TREE: | | | OmpClauseList ->
237+
!PARSE-TREE: | OmpClause -> When -> OmpWhenClause
238+
!PARSE-TREE: | | Modifier -> OmpContextSelectorSpecification -> OmpTraitSetSelector
239+
!PARSE-TREE: | | | OmpTraitSetSelectorName -> Value = User
240+
!PARSE-TREE: | | | OmpTraitSelector
241+
!PARSE-TREE: | | | | OmpTraitSelectorName -> Value = Condition
242+
!PARSE-TREE: | | | | Properties
243+
!PARSE-TREE: | | | | | OmpTraitProperty -> Scalar -> Expr = '.true._4'
244+
!PARSE-TREE: | | | | | | LiteralConstant -> LogicalLiteralConstant
245+
!PARSE-TREE: | | | | | | | bool = 'true'
246+
!PARSE-TREE: | | OmpDirectiveSpecification
247+
!PARSE-TREE: | | | llvm::omp::Directive = declare target
248+
!PARSE-TREE: | | | OmpClauseList ->
249+
!PARSE-TREE: | OmpClause -> Otherwise -> OmpOtherwiseClause -> OmpDirectiveSpecification
250+
!PARSE-TREE: | | llvm::omp::Directive = nothing
251+
!PARSE-TREE: | | OmpClauseList ->

0 commit comments

Comments
 (0)