Skip to content

Commit 8464253

Browse files
committed
R9: Addressing review comments
1 parent 9facbf7 commit 8464253

File tree

6 files changed

+70
-32
lines changed

6 files changed

+70
-32
lines changed

flang/include/flang/Semantics/symbol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ class Symbol {
755755
OmpDeclarativeAllocateDirective, OmpExecutableAllocateDirective,
756756
OmpDeclareSimd, OmpDeclareTarget, OmpThreadprivate, OmpDeclareReduction,
757757
OmpFlushed, OmpCriticalLock, OmpIfSpecified, OmpNone, OmpPreDetermined,
758-
OmpImplicit, OmpDependObject);
758+
OmpImplicit, OmpDependObject, OmpInclusiveScan, OmpExclusiveScan);
759759
using Flags = common::EnumSet<Flag, Flag_enumSize>;
760760

761761
const Scope &owner() const { return *owner_; }

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,14 +981,12 @@ void OmpStructureChecker::Leave(const parser::OpenMPLoopConstruct &x) {
981981
// constructs inside LOOP may add the relevant information. Scan reduction is
982982
// supported only in loop constructs, so same checks are not applicable to
983983
// other directives.
984-
985984
for (const auto &clause : clauseList.v) {
986985
if (const auto *reductionClause{
987986
std::get_if<parser::OmpClause::Reduction>(&clause.u)}) {
988987
const auto &maybeModifier{
989988
std::get<std::optional<ReductionModifier>>(reductionClause->v.t)};
990989
if (maybeModifier && *maybeModifier == ReductionModifier::Inscan) {
991-
992990
const auto &objectList{
993991
std::get<parser::OmpObjectList>(reductionClause->v.t)};
994992
auto checkReductionSymbolInScan = [&](const parser::Name *name) {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ class OmpStructureChecker
7575
using ReductionModifier = parser::OmpReductionClause::ReductionModifier;
7676
using Symbol = Fortran::semantics::Symbol;
7777
class ScanReductionInfo {
78-
79-
public:
80-
std::set<Symbol *> usedInScanDirective;
78+
std::set<Symbol *> usedInScan;
8179
std::map<Symbol *, ReductionModifier> reductionMod;
8280

81+
public:
8382
void mapSymbolsToReductionModifiers(
8483
const parser::OmpObjectList &x, const ReductionModifier &modifier) {
8584
for (const auto &ompObject : x.v) {
@@ -92,11 +91,11 @@ class OmpStructureChecker
9291
}
9392

9493
void markSymbolAsUsedInScanConstruct(Symbol *sym) {
95-
usedInScanDirective.insert(sym);
94+
usedInScan.insert(sym);
9695
}
9796

9897
bool findSymbolInScanConstruct(Symbol *sym) {
99-
if (usedInScanDirective.find(sym) != usedInScanDirective.end()) {
98+
if (usedInScan.find(sym) != usedInScan.end()) {
10099
return true;
101100
}
102101
return false;

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "flang/Semantics/expression.h"
2222
#include "flang/Semantics/symbol.h"
2323
#include "flang/Semantics/tools.h"
24-
#include <iostream>
2524
#include <list>
2625
#include <map>
2726
#include <sstream>
@@ -459,16 +458,12 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
459458
}
460459

461460
// 2.15.3 Data-Sharing Attribute Clauses
462-
void ResolveNames(const parser::OmpObjectList &objList);
463-
464461
bool Pre(const parser::OmpClause::Inclusive &x) {
465-
const auto &objectList{x.v};
466-
ResolveNames(objectList);
462+
ResolveOmpObjectList(x.v, Symbol::Flag::OmpInclusiveScan);
467463
return false;
468464
}
469465
bool Pre(const parser::OmpClause::Exclusive &x) {
470-
const auto &objectList{x.v};
471-
ResolveNames(objectList);
466+
ResolveOmpObjectList(x.v, Symbol::Flag::OmpExclusiveScan);
472467
return false;
473468
}
474469
void Post(const parser::OmpDefaultClause &);
@@ -705,8 +700,9 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
705700
Symbol::Flag::OmpUseDevicePtr, Symbol::Flag::OmpUseDeviceAddr,
706701
Symbol::Flag::OmpIsDevicePtr, Symbol::Flag::OmpHasDeviceAddr};
707702

708-
Symbol::Flags ompFlagsRequireMark{
709-
Symbol::Flag::OmpThreadprivate, Symbol::Flag::OmpDeclareTarget};
703+
Symbol::Flags ompFlagsRequireMark{Symbol::Flag::OmpThreadprivate,
704+
Symbol::Flag::OmpDeclareTarget, Symbol::Flag::OmpExclusiveScan,
705+
Symbol::Flag::OmpInclusiveScan};
710706

711707
Symbol::Flags dataCopyingAttributeFlags{
712708
Symbol::Flag::OmpCopyIn, Symbol::Flag::OmpCopyPrivate};
@@ -2970,19 +2966,4 @@ void OmpAttributeVisitor::IssueNonConformanceWarning(
29702966
context_.Warn(common::UsageWarning::OpenMPUsage, source, "%s"_warn_en_US,
29712967
warnStrOS.str());
29722968
}
2973-
void OmpAttributeVisitor::ResolveNames(const parser::OmpObjectList &objList) {
2974-
for (const auto &ompObj : objList.v) {
2975-
common::visit(
2976-
common::visitors{
2977-
[&](const parser::Designator &designator) {
2978-
if (const auto *name{
2979-
semantics::getDesignatorNameIfDataRef(designator)}) {
2980-
ResolveName(name);
2981-
}
2982-
},
2983-
[&](const auto &name) { ResolveName(&name); },
2984-
},
2985-
ompObj.u);
2986-
}
2987-
}
29882969
} // namespace Fortran::semantics

flang/test/Semantics/OpenMP/scan1.f90

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
3+
subroutine test_scan()
4+
integer x, y, k, z
5+
6+
!ERROR: Orphaned SCAN directives are prohibited; perhaps you forgot to enclose the directive in to a WORKSHARING LOOP, a WORKSHARING LOOP SIMD or a SIMD directive.
7+
!$omp scan inclusive(x)
8+
!$omp parallel do simd
9+
do k = 1, n
10+
!ERROR: UNTIED clause is not allowed on the SCAN directive
11+
!$omp scan untied
12+
end do
13+
14+
!$omp parallel do simd
15+
do k = 1, n
16+
!ERROR: Exactly one of EXCLUSIVE or INCLUSIVE clause is expected
17+
!$omp scan
18+
end do
19+
20+
!$omp parallel do simd reduction(inscan,+: x, y)
21+
do k = 1, n
22+
!ERROR: Exactly one of EXCLUSIVE or INCLUSIVE clause is expected
23+
!$omp scan inclusive(x) exclusive(y)
24+
end do
25+
26+
!ERROR: List item y must appear in EXCLUSIVE or INCLUSIVE clause of an enclosed SCAN directive
27+
!$omp parallel do simd reduction(inscan,+: x, y)
28+
do k = 1, n
29+
!ERROR: Exactly one of EXCLUSIVE or INCLUSIVE clause is expected
30+
!ERROR: List item z must appear in REDUCTION clause with the INSCAN modifier of the parent directive
31+
!$omp scan inclusive(x) exclusive(z)
32+
end do
33+
end subroutine

flang/test/Semantics/OpenMP/scan2.f90

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
! RUN: %flang_fc1 -fopenmp -fdebug-dump-symbols -o - %s 2>&1 | FileCheck %s
2+
! Check scan reduction
3+
4+
! CHECK: MainProgram scope: omp_reduction
5+
program omp_reduction
6+
! CHECK: i size=4 offset=0: ObjectEntity type: INTEGER(4)
7+
integer i
8+
! CHECK: k size=4 offset=4: ObjectEntity type: INTEGER(4) init:10_4
9+
integer :: k = 10
10+
! CHECK: m size=4 offset=8: ObjectEntity type: INTEGER(4) init:12_4
11+
integer :: m = 12
12+
13+
! CHECK: OtherConstruct scope
14+
! CHECK: i (OmpPrivate, OmpPreDetermined): HostAssoc
15+
! CHECK: k (OmpReduction, OmpInclusiveScan): HostAssoc
16+
!$omp parallel do reduction(inscan, +:k)
17+
do i=1,10
18+
!$omp scan inclusive(k)
19+
end do
20+
!$omp end parallel do
21+
! CHECK: m (OmpReduction, OmpExclusiveScan): HostAssoc
22+
!$omp parallel do reduction(inscan, +:m)
23+
do i=1,10
24+
!$omp scan exclusive(m)
25+
end do
26+
!$omp end parallel do
27+
end program omp_reduction

0 commit comments

Comments
 (0)