Skip to content

Add parser+semantics support for scope construct #113700

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 1 commit into from
Oct 25, 2024
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
2 changes: 2 additions & 0 deletions flang/include/flang/Semantics/openmp-directive-sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ static const OmpDirectiveSet blockConstructSet{
Directive::OMPD_parallel,
Directive::OMPD_parallel_masked,
Directive::OMPD_parallel_workshare,
Directive::OMPD_scope,
Directive::OMPD_single,
Directive::OMPD_target,
Directive::OMPD_target_data,
Expand Down Expand Up @@ -281,6 +282,7 @@ static const OmpDirectiveSet workShareSet{
Directive::OMPD_workshare,
Directive::OMPD_parallel_workshare,
Directive::OMPD_parallel_sections,
Directive::OMPD_scope,
Directive::OMPD_sections,
Directive::OMPD_single,
} | allDoSet,
Expand Down
12 changes: 12 additions & 0 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,15 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
return sectionsOp;
}

static void genScopeOp(lower::AbstractConverter &converter,
lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval, mlir::Location loc,
const ConstructQueue &queue,
ConstructQueue::const_iterator item) {
TODO(loc, "Scope construct");
}

static mlir::omp::SingleOp
genSingleOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
Expand Down Expand Up @@ -2478,6 +2487,9 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
case llvm::omp::Directive::OMPD_simd:
genStandaloneSimd(converter, symTable, semaCtx, eval, loc, queue, item);
break;
case llvm::omp::Directive::OMPD_scope:
genScopeOp(converter, symTable, semaCtx, eval, loc, queue, item);
break;
case llvm::omp::Directive::OMPD_single:
genSingleOp(converter, symTable, semaCtx, eval, loc, queue, item);
break;
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Parser/openmp-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ TYPE_PARSER(construct<OmpBlockDirective>(first(
"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked),
"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare),
"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel),
"SCOPE" >> pure(llvm::omp::Directive::OMPD_scope),
"SINGLE" >> pure(llvm::omp::Directive::OMPD_single),
"TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data),
"TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel),
Expand Down
3 changes: 3 additions & 0 deletions flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,9 @@ class UnparseVisitor {
case llvm::omp::Directive::OMPD_parallel:
Word("PARALLEL ");
break;
case llvm::omp::Directive::OMPD_scope:
Word("SCOPE ");
break;
case llvm::omp::Directive::OMPD_single:
Word("SINGLE ");
break;
Expand Down
7 changes: 6 additions & 1 deletion flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
HasInvalidWorksharingNesting(
beginDir.source, llvm::omp::nestedWorkshareErrSet);
break;
case llvm::omp::Directive::OMPD_scope:
case llvm::omp::Directive::OMPD_single:
// TODO: This check needs to be extended while implementing nesting of
// regions checks.
Expand Down Expand Up @@ -1864,6 +1865,9 @@ void OmpStructureChecker::Enter(const parser::OmpEndBlockDirective &x) {
const auto &dir{std::get<parser::OmpBlockDirective>(x.t)};
ResetPartialContext(dir.source);
switch (dir.v) {
case llvm::omp::Directive::OMPD_scope:
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_end_scope);
break;
// 2.7.3 end-single-clause -> copyprivate-clause |
// nowait-clause
case llvm::omp::Directive::OMPD_single:
Expand All @@ -1886,7 +1890,8 @@ void OmpStructureChecker::Enter(const parser::OmpEndBlockDirective &x) {
// end_workshareare popped as they are pushed while entering the
// EndBlockDirective.
void OmpStructureChecker::Leave(const parser::OmpEndBlockDirective &x) {
if ((GetContext().directive == llvm::omp::Directive::OMPD_end_single) ||
if ((GetContext().directive == llvm::omp::Directive::OMPD_end_scope) ||
(GetContext().directive == llvm::omp::Directive::OMPD_end_single) ||
(GetContext().directive == llvm::omp::Directive::OMPD_end_workshare)) {
dirContext_.pop_back();
}
Expand Down
2 changes: 2 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
case llvm::omp::Directive::OMPD_master:
case llvm::omp::Directive::OMPD_ordered:
case llvm::omp::Directive::OMPD_parallel:
case llvm::omp::Directive::OMPD_scope:
case llvm::omp::Directive::OMPD_single:
case llvm::omp::Directive::OMPD_target:
case llvm::omp::Directive::OMPD_target_data:
Expand Down Expand Up @@ -1557,6 +1558,7 @@ void OmpAttributeVisitor::Post(const parser::OpenMPBlockConstruct &x) {
case llvm::omp::Directive::OMPD_masked:
case llvm::omp::Directive::OMPD_parallel_masked:
case llvm::omp::Directive::OMPD_parallel:
case llvm::omp::Directive::OMPD_scope:
case llvm::omp::Directive::OMPD_single:
case llvm::omp::Directive::OMPD_target:
case llvm::omp::Directive::OMPD_task:
Expand Down
13 changes: 13 additions & 0 deletions flang/test/Lower/OpenMP/Todo/scope.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s -fopenmp-version=51 2>&1 | FileCheck %s
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s -fopenmp-version=51 2>&1 | FileCheck %s

! CHECK: not yet implemented: Scope construct
program omp_scope
integer i
i = 10

!$omp scope private(i)
print *, "omp scope", i
!$omp end scope

end program omp_scope
24 changes: 24 additions & 0 deletions flang/test/Parser/OpenMP/scope.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
! RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=51 %s | FileCheck --ignore-case %s
! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=51 %s | FileCheck --check-prefix="PARSE-TREE" %s

program omp_scope
integer i
i = 10

!CHECK: !$OMP SCOPE PRIVATE(i)
!CHECK: !$OMP END SCOPE

!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct
!PARSE-TREE: OmpBeginBlockDirective
!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = scope
!PARSE-TREE: OmpClauseList -> OmpClause -> Private -> OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'i'
!PARSE-TREE: Block
!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> PrintStmt
!PARSE-TREE: OmpEndBlockDirective
!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = scope
!PARSE-TREE: OmpClauseList -> OmpClause -> Nowait

!$omp scope private(i)
print *, "omp scope", i
!$omp end scope nowait
end program omp_scope
8 changes: 8 additions & 0 deletions flang/test/Semantics/OpenMP/invalid-branch.f90
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,12 @@ program omp_invalid_branch
!$omp end parallel
9 print *, "2nd alternate return"

!CHECK: invalid branch into an OpenMP structured block
goto 100
!$omp scope
100 continue
!CHECK: invalid branch leaving an OpenMP structured block
goto 200
!$omp end scope
200 continue
end program
7 changes: 7 additions & 0 deletions flang/test/Semantics/OpenMP/nested01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
!$omp end target
enddo

!$omp do
do i = 1, N
!ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
!$omp scope
!$omp end scope
end do
!$omp end do

!$omp do
do i = 1, N
Expand Down
10 changes: 9 additions & 1 deletion llvm/include/llvm/Frontend/OpenMP/OMP.td
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def OMP_Scan : Directive<"scan"> {
let association = AS_Separating;
let category = CA_Subsidiary;
}
def OMP_scope : Directive<"scope"> {
def OMP_Scope : Directive<"scope"> {
let allowedClauses = [
VersionedClause<OMPC_Private, 51>,
VersionedClause<OMPC_Reduction, 51>,
Expand All @@ -905,6 +905,14 @@ def OMP_scope : Directive<"scope"> {
let association = AS_Block;
let category = CA_Executable;
}
def OMP_EndScope : Directive<"end scope"> {
let allowedOnceClauses = [
VersionedClause<OMPC_NoWait>,
];
let leafConstructs = OMP_Scope.leafConstructs;
let association = OMP_Scope.association;
let category = OMP_Scope.category;
}
def OMP_Section : Directive<"section"> {
let association = AS_Separating;
let category = CA_Subsidiary;
Expand Down
Loading