Skip to content
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
11 changes: 9 additions & 2 deletions flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "FlangOmpReportVisitor.h"
#include "flang/Common/idioms.h"
#include "flang/Parser/openmp-utils.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Frontend/OpenMP/OMP.h"
Expand Down Expand Up @@ -58,9 +59,15 @@ SourcePosition OpenMPCounterVisitor::getLocation(const OmpWrapperType &w) {
}
SourcePosition OpenMPCounterVisitor::getLocation(
const OpenMPDeclarativeConstruct &c) {
const parser::AllCookedSources &allCooked{parsing->allCooked()};
return std::visit(
[&](const auto &o) -> SourcePosition {
return parsing->allCooked().GetSourcePositionRange(o.source)->first;
common::visitors{
[&](const parser::OmpMetadirectiveDirective &o) -> SourcePosition {
return allCooked.GetSourcePositionRange(o.v.source)->first;
},
[&](const auto &o) -> SourcePosition {
return allCooked.GetSourcePositionRange(o.source)->first;
},
},
c.u);
}
Expand Down
2 changes: 0 additions & 2 deletions flang/include/flang/Parser/openmp-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ struct ConstructId {

MAKE_CONSTR_ID(OmpDeclareVariantDirective, D::OMPD_declare_variant);
MAKE_CONSTR_ID(OmpErrorDirective, D::OMPD_error);
MAKE_CONSTR_ID(OmpMetadirectiveDirective, D::OMPD_metadirective);
MAKE_CONSTR_ID(OpenMPDeclarativeAllocate, D::OMPD_allocate);
MAKE_CONSTR_ID(OpenMPDeclarativeAssumes, D::OMPD_assumes);
MAKE_CONSTR_ID(OpenMPDeclareMapperConstruct, D::OMPD_declare_mapper);
Expand Down Expand Up @@ -102,7 +101,6 @@ struct DirectiveNameScope {
return std::get<OmpBeginDirective>(x.t).DirName();
} else if constexpr (std::is_same_v<T, OmpDeclareVariantDirective> ||
std::is_same_v<T, OmpErrorDirective> ||
std::is_same_v<T, OmpMetadirectiveDirective> ||
std::is_same_v<T, OpenMPDeclarativeAllocate> ||
std::is_same_v<T, OpenMPDeclarativeAssumes> ||
std::is_same_v<T, OpenMPDeclareMapperConstruct> ||
Expand Down
5 changes: 2 additions & 3 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4827,9 +4827,8 @@ struct OmpBlockConstruct {
};

struct OmpMetadirectiveDirective {
TUPLE_CLASS_BOILERPLATE(OmpMetadirectiveDirective);
std::tuple<Verbatim, OmpClauseList> t;
CharBlock source;
WRAPPER_CLASS_BOILERPLATE(
OmpMetadirectiveDirective, OmpDirectiveSpecification);
};

// Ref: [5.1:89-90], [5.2:216]
Expand Down
18 changes: 10 additions & 8 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,11 +1008,11 @@ TYPE_PARSER(construct<OmpMatchClause>(
Parser<traits::OmpContextSelectorSpecification>{}))

TYPE_PARSER(construct<OmpOtherwiseClause>(
maybe(indirect(sourced(Parser<OmpDirectiveSpecification>{})))))
maybe(indirect(Parser<OmpDirectiveSpecification>{}))))

TYPE_PARSER(construct<OmpWhenClause>(
maybe(nonemptyList(Parser<OmpWhenClause::Modifier>{}) / ":"),
maybe(indirect(sourced(Parser<OmpDirectiveSpecification>{})))))
maybe(indirect(Parser<OmpDirectiveSpecification>{}))))

// OMP 5.2 12.6.1 grainsize([ prescriptiveness :] scalar-integer-expression)
TYPE_PARSER(construct<OmpGrainsizeClause>(
Expand Down Expand Up @@ -1301,9 +1301,9 @@ OmpDirectiveSpecification static makeFlushFromOldSyntax(Verbatim &&text,
std::move(clauses), std::move(flags)};
}

TYPE_PARSER(sourced(
TYPE_PARSER(
// Parse the old syntax: FLUSH [clauses] [(objects)]
construct<OmpDirectiveSpecification>(
sourced(construct<OmpDirectiveSpecification>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this already inside of a sourced parser?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. Let me fix this...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Force this old-syntax parser to fail for FLUSH followed by '('.
// Otherwise it could succeed on the new syntax but have one of
// lists absent in the parsed result.
Expand All @@ -1313,9 +1313,9 @@ TYPE_PARSER(sourced(
verbatim("FLUSH"_tok) / !lookAhead("("_tok),
maybe(Parser<OmpClauseList>{}),
maybe(parenthesized(Parser<OmpArgumentList>{})),
pure(OmpDirectiveSpecification::Flags::DeprecatedSyntax))) ||
pure(OmpDirectiveSpecification::Flags::DeprecatedSyntax)))) ||
// Parse the standard syntax: directive [(arguments)] [clauses]
construct<OmpDirectiveSpecification>( //
sourced(construct<OmpDirectiveSpecification>( //
sourced(OmpDirectiveNameParser{}),
maybe(parenthesized(Parser<OmpArgumentList>{})),
maybe(Parser<OmpClauseList>{}),
Expand Down Expand Up @@ -1373,8 +1373,10 @@ TYPE_PARSER(sourced(construct<OpenMPUtilityConstruct>(
sourced(construct<OpenMPUtilityConstruct>(
sourced(Parser<OmpNothingDirective>{}))))))

TYPE_PARSER(sourced(construct<OmpMetadirectiveDirective>(
verbatim("METADIRECTIVE"_tok), Parser<OmpClauseList>{})))
TYPE_PARSER(construct<OmpMetadirectiveDirective>(
predicated(Parser<OmpDirectiveName>{},
IsDirective(llvm::omp::Directive::OMPD_metadirective)) >=
Parser<OmpDirectiveSpecification>{}))

struct OmpBeginDirectiveParser {
using resultType = OmpDirectiveSpecification;
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2661,8 +2661,8 @@ class UnparseVisitor {
void Unparse(const OmpFailClause &x) { Walk(x.v); }
void Unparse(const OmpMetadirectiveDirective &x) {
BeginOpenMP();
Word("!$OMP METADIRECTIVE ");
Walk(std::get<OmpClauseList>(x.t));
Word("!$OMP ");
Walk(x.v);
Put("\n");
EndOpenMP();
}
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Semantics/check-omp-metadirective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@ void OmpStructureChecker::CheckTraitSimd(

void OmpStructureChecker::Enter(const parser::OmpMetadirectiveDirective &x) {
EnterDirectiveNest(MetadirectiveNest);
PushContextAndClauseSets(x.source, llvm::omp::Directive::OMPD_metadirective);
PushContextAndClauseSets(
x.v.source, llvm::omp::Directive::OMPD_metadirective);
}

void OmpStructureChecker::Leave(const parser::OmpMetadirectiveDirective &) {
Expand Down
5 changes: 0 additions & 5 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,6 @@ template <typename Checker> struct DirectiveSpellingVisitor {
checker_(GetDirName(x.t).source, Directive::OMPD_allocators);
return false;
}
bool Pre(const parser::OmpMetadirectiveDirective &x) {
checker_(
std::get<parser::Verbatim>(x.t).source, Directive::OMPD_metadirective);
return false;
}
bool Pre(const parser::OpenMPDeclarativeAssumes &x) {
checker_(std::get<parser::Verbatim>(x.t).source, Directive::OMPD_assumes);
return false;
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
}

bool Pre(const parser::OmpMetadirectiveDirective &x) {
PushContext(x.source, llvm::omp::Directive::OMPD_metadirective);
PushContext(x.v.source, llvm::omp::Directive::OMPD_metadirective);
return true;
}
void Post(const parser::OmpMetadirectiveDirective &) { PopContext(); }
Expand Down
18 changes: 9 additions & 9 deletions flang/test/Parser/OpenMP/metadirective-dirspec.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ subroutine f00(x)

!UNPARSE: SUBROUTINE f00 (x)
!UNPARSE: INTEGER x(10_4)
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: ALLOCATE(x))
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: ALLOCATE(x))
!UNPARSE: END SUBROUTINE

!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
Expand All @@ -37,7 +37,7 @@ subroutine f01(x)

!UNPARSE: SUBROUTINE f01 (x)
!UNPARSE: INTEGER x
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: CRITICAL(x))
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: CRITICAL(x))
!UNPARSE: END SUBROUTINE

!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
Expand All @@ -61,8 +61,8 @@ subroutine f02
end

!UNPARSE: SUBROUTINE f02
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE MAPPER(mymapper:INTEGER:&
!UNPARSE: !$OMP&:v) MAP(TOFROM: v))
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE MAPPER(mymapper:INTEGER::&
!UNPARSE: !$OMP&v) MAP(TOFROM: v))
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
Expand Down Expand Up @@ -105,7 +105,7 @@ subroutine f03
!UNPARSE: TYPE :: tt2
!UNPARSE: REAL :: x
!UNPARSE: END TYPE
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE REDUCTION(+:tt1,tt2: omp_out%x=omp_in%x+omp_out%x
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE REDUCTION(+:tt1,tt2: omp_out%x=omp_in%x+omp_out%x
!UNPARSE: ))
!UNPARSE: END SUBROUTINE

Expand Down Expand Up @@ -149,7 +149,7 @@ subroutine f04
end

!UNPARSE: SUBROUTINE f04
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE SIMD(f04))
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE SIMD(f04))
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
Expand All @@ -174,7 +174,7 @@ subroutine f05
end

!UNPARSE: SUBROUTINE f05
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE TARGET(f05))
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: DECLARE TARGET(f05))
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
Expand All @@ -201,7 +201,7 @@ subroutine f06(x, y)

!UNPARSE: SUBROUTINE f06 (x, y)
!UNPARSE: INTEGER x, y
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: FLUSH(x, y))
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: FLUSH(x, y))
!UNPARSE: END SUBROUTINE

!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
Expand All @@ -228,7 +228,7 @@ subroutine f07

!UNPARSE: SUBROUTINE f07
!UNPARSE: INTEGER t
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: THREADPRIVATE(t))
!UNPARSE: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: THREADPRIVATE(t))
!UNPARSE: END SUBROUTINE

!PARSE-TREE: DeclarationConstruct -> SpecificationConstruct -> OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
Expand Down
26 changes: 13 additions & 13 deletions flang/test/Parser/OpenMP/metadirective.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ subroutine f00

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

!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OmpMetadirectiveDirective
Expand All @@ -30,7 +30,7 @@ subroutine f01

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

!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OmpMetadirectiveDirective
Expand All @@ -57,7 +57,7 @@ subroutine f02

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

!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OmpMetadirectiveDirective
Expand Down Expand Up @@ -85,8 +85,8 @@ subroutine f03

!UNPARSE: SUBROUTINE f03
!UNPARSE: CONTINUE
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={ATOMIC_DEFAULT_MEM_ORDER(ACQ_REL)}: &
!UNPARSE: !$OMP&NOTHING)
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={ATOMIC_DEFAULT_MEM_ORDER(ACQ_REL)}: N&
!UNPARSE: !$OMP&OTHING)
!UNPARSE: END SUBROUTINE

!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OmpMetadirectiveDirective
Expand All @@ -109,8 +109,8 @@ subroutine f04

!UNPARSE: SUBROUTINE f04
!UNPARSE: CONTINUE
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={extension_trait(haha(1_4), foo(baz,bar(1_4&
!UNPARSE: !$OMP&)))}: NOTHING)
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={extension_trait(haha(1_4), foo(baz,bar(1_4)&
!UNPARSE: !$OMP&))}: NOTHING)
!UNPARSE: END SUBROUTINE

!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OmpMetadirectiveDirective
Expand Down Expand Up @@ -149,8 +149,8 @@ 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: !$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
!UNPARSE: END DO
!UNPARSE: END SUBROUTINE
Expand Down Expand Up @@ -186,8 +186,8 @@ subroutine f06

!UNPARSE: SUBROUTINE f06
!UNPARSE: CONTINUE
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={VENDOR(amd)}, USER={CONDITION(.true._4)}: NO&
!UNPARSE: !$OMP&THING)
!UNPARSE: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={VENDOR(amd)}, USER={CONDITION(.true._4)}: NOT&
!UNPARSE: !$OMP&HING)
!UNPARSE: END SUBROUTINE

!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPStandaloneConstruct -> OmpMetadirectiveDirective
Expand Down Expand Up @@ -219,8 +219,8 @@ subroutine f07
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: !$OMP METADIRECTIVE WHEN(IMPLEMENTATION={VENDOR(amd)}: DECLARE SIMD) WHEN(USER&
!UNPARSE: !$OMP&={CONDITION(.true._4)}: DECLARE TARGET) OTHERWISE(NOTHING)
!UNPARSE: END SUBROUTINE

!PARSE-TREE: OpenMPDeclarativeConstruct -> OmpMetadirectiveDirective
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Preprocessing/omp-sentinel-fixed-form.F
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ program test
implicit none
integer i,j,n
n = 100
! CHECK: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: TARGET TEAMS DISTRIBUTE PARALLEL&
! CHECK: !$OMP& DO) DEFAULT(TARGET TEAMS LOOP)
! CHECK: !$OMP METADIRECTIVE WHEN(USER={CONDITION(.true._4)}: TARGET TEAMS DISTRIBUTE PARALLEL &
! CHECK: !$OMP&DO) DEFAULT(TARGET TEAMS LOOP)
!$omp metadirective
!$omp& when(user={condition(OMP_TARGET.or.OMP_SIMD)}:
!$omp& target teams distribute parallel do )
Expand Down