Skip to content

[flang][OpenMP] Parse METADIRECTIVE in specification part #123397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ std::string OpenMPCounterVisitor::getName(const OpenMPDeclarativeConstruct &c) {
const CharBlock &source{o.source};
return normalize_construct_name(source.ToString());
},
[&](const OmpMetadirectiveDirective &o) -> std::string {
const CharBlock &source{o.source};
return normalize_construct_name(source.ToString());
},
[&](const auto &o) -> std::string {
const CharBlock &source{std::get<Verbatim>(o.t).source};
return normalize_construct_name(source.ToString());
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4540,8 +4540,8 @@ struct OpenMPDeclarativeConstruct {
CharBlock source;
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclareMapperConstruct,
OpenMPDeclareReductionConstruct, OpenMPDeclareSimdConstruct,
OpenMPDeclareTargetConstruct, OpenMPThreadprivate,
OpenMPRequiresConstruct, OpenMPUtilityConstruct>
OpenMPThreadprivate, OpenMPRequiresConstruct, OpenMPUtilityConstruct,
OpenMPDeclareTargetConstruct, OmpMetadirectiveDirective>
u;
};

Expand Down
12 changes: 7 additions & 5 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3142,6 +3142,13 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
// support the case of threadprivate variable declared in module.
}

static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OmpMetadirectiveDirective &meta) {
TODO(converter.getCurrentLocation(), "METADIRECTIVE");
}

static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
Expand Down Expand Up @@ -3234,11 +3241,6 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
TODO(converter.getCurrentLocation(), "OpenMPDepobjConstruct");
}

static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OmpMetadirectiveDirective &construct) {}

static void
genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
Expand Down
4 changes: 3 additions & 1 deletion flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,9 @@ TYPE_PARSER(startOmpLine >>
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPThreadprivate>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPUtilityConstruct>{})) /
Parser<OpenMPUtilityConstruct>{}) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OmpMetadirectiveDirective>{})) /
endOmpLine))

// Block Construct
Expand Down
9 changes: 9 additions & 0 deletions flang/test/Lower/OpenMP/Todo/metadirective-exec.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!RUN: %not_todo_cmd bbc -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s

!CHECK: not yet implemented: METADIRECTIVE
subroutine f00
continue
!Executable
!$omp metadirective when(user={condition(.true.)}: nothing)
end
9 changes: 9 additions & 0 deletions flang/test/Lower/OpenMP/Todo/metadirective-spec.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!RUN: %not_todo_cmd bbc -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s
!RUN: %not_todo_cmd %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=52 -o - %s 2>&1 | FileCheck %s

!CHECK: not yet implemented: METADIRECTIVE
subroutine f00
!Specification
!$omp metadirective when(user={condition(.true.)}: nothing)
implicit none
end
2 changes: 2 additions & 0 deletions flang/test/Parser/OpenMP/metadirective-v50.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=50 %s | FileCheck --check-prefix="PARSE-TREE" %s

subroutine f01
continue
!$omp metadirective &
!$omp & when(user={condition(.true.)}: nothing) &
!$omp & default(nothing)
end

!UNPARSE: SUBROUTINE f01
!UNPARSE: CONTINUE
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: NOTHING) DEFAULT(NOTHING)
!UNPARSE: END SUBROUTINE

Expand Down
53 changes: 53 additions & 0 deletions flang/test/Parser/OpenMP/metadirective.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=52 %s | FileCheck --check-prefix="PARSE-TREE" %s

subroutine f00
continue
!$omp metadirective when(construct={target, parallel}: nothing)
end

!UNPARSE: SUBROUTINE f00
!UNPARSE: CONTINUE
!UNPARSE: !$OMP METADIRECTIVE WHEN(CONSTRUCT={TARGET, PARALLEL}: NOTHING)
!UNPARSE: END SUBROUTINE

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

subroutine f01
continue
!$omp metadirective when(target_device={kind(host), device_num(1)}: nothing)
end

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

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

subroutine f02
continue
!$omp metadirective when(target_device={kind(any), device_num(7)}: nothing)
end

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

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

subroutine f03
continue
!$omp metadirective &
!$omp & when(implementation={atomic_default_mem_order(acq_rel)}: nothing)
end

!UNPARSE: SUBROUTINE f03
!UNPARSE: CONTINUE
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={ATOMIC_DEFAULT_MEM_ORDER(ACQ_REL)}: &
!UNPARSE: !$OMP&NOTHING)
!UNPARSE: END SUBROUTINE
Expand All @@ -94,11 +102,13 @@ subroutine f03
!PARSE-TREE: | | | OmpClauseList ->

subroutine f04
continue
!$omp metadirective &
!$omp when(implementation={extension_trait(haha(1), foo(baz, "bar"(1)))}: nothing)
end

!UNPARSE: SUBROUTINE f04
!UNPARSE: CONTINUE
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={extension_trait(haha(1_4), foo(baz,bar(1_4&
!UNPARSE: !$OMP&)))}: NOTHING)
!UNPARSE: END SUBROUTINE
Expand Down Expand Up @@ -127,6 +137,7 @@ subroutine f04

subroutine f05(x)
integer :: x
continue
!$omp metadirective &
!$omp & when(user={condition(score(100): .true.)}: &
!$omp & parallel do reduction(+: x)) &
Expand All @@ -137,6 +148,7 @@ subroutine f05(x)

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

subroutine f06
continue
! Two trait set selectors
!$omp metadirective &
!$omp & when(implementation={vendor("amd")}, &
!$omp & user={condition(.true.)}: nothing)
end

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

subroutine f07
! Declarative metadirective
!$omp metadirective &
!$omp & when(implementation={vendor("amd")}: declare simd) &
!$omp & when(user={condition(.true.)}: declare target) &
!$omp & otherwise(nothing)
end

!UNPARSE: SUBROUTINE f07
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={VENDOR(amd)}: DECLARE SIMD) WHEN(USE&
!UNPARSE: !$OMP&R={CONDITION(.true._4)}: DECLARE TARGET) OTHERWISE(NOTHING)
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
!PARSE-TREE: | OmpClauseList -> OmpClause -> When -> OmpWhenClause
!PARSE-TREE: | | Modifier -> OmpContextSelectorSpecification -> OmpTraitSetSelector
!PARSE-TREE: | | | OmpTraitSetSelectorName -> Value = Implementation
!PARSE-TREE: | | | OmpTraitSelector
!PARSE-TREE: | | | | OmpTraitSelectorName -> Value = Vendor
!PARSE-TREE: | | | | Properties
!PARSE-TREE: | | | | | OmpTraitProperty -> OmpTraitPropertyName -> string = 'amd'
!PARSE-TREE: | | OmpDirectiveSpecification
!PARSE-TREE: | | | llvm::omp::Directive = declare simd
!PARSE-TREE: | | | OmpClauseList ->
!PARSE-TREE: | OmpClause -> When -> OmpWhenClause
!PARSE-TREE: | | Modifier -> OmpContextSelectorSpecification -> OmpTraitSetSelector
!PARSE-TREE: | | | OmpTraitSetSelectorName -> Value = User
!PARSE-TREE: | | | OmpTraitSelector
!PARSE-TREE: | | | | OmpTraitSelectorName -> Value = Condition
!PARSE-TREE: | | | | Properties
!PARSE-TREE: | | | | | OmpTraitProperty -> Scalar -> Expr = '.true._4'
!PARSE-TREE: | | | | | | LiteralConstant -> LogicalLiteralConstant
!PARSE-TREE: | | | | | | | bool = 'true'
!PARSE-TREE: | | OmpDirectiveSpecification
!PARSE-TREE: | | | llvm::omp::Directive = declare target
!PARSE-TREE: | | | OmpClauseList ->
!PARSE-TREE: | OmpClause -> Otherwise -> OmpOtherwiseClause -> OmpDirectiveSpecification
!PARSE-TREE: | | llvm::omp::Directive = nothing
!PARSE-TREE: | | OmpClauseList ->