Skip to content

Commit aac1f85

Browse files
authored
[flang][OpenMP] Explicitly set Shared DSA in symbols (#142154)
Before this change, OmpShared was not always set in shared symbols. Instead, absence of private flags was interpreted as shared DSA. The problem was that symbols with no flags, with only a host association, could also mean "has same DSA as in the enclosing context". Now shared symbols behave the same as private and can be treated the same way. Because of the host association symbols with no flags mentioned above, it was also incorrect to simply test the flags of a given symbol to find out if it was private or shared. The function GetSymbolDSA() was added to fix this. It would be better to avoid the need of these special symbols, but this would require changes to how symbols are collected in lowering. Besides that, some semantic checks need to know if a DSA clause was used or not. To avoid confusing implicit symbols with DSA clauses a new flag was added: OmpExplicit. It is now set for all symbols with explicitly determined data-sharing attributes. With the changes above, AddToContextObjectWithDSA() and the symbol to DSA map could probably be removed and the DSA could be obtained directly from the symbol, but this was not attempted. Some debug messages were also added, with the "omp" DEBUG_TYPE, to make it easier to debug the creation of implicit symbols and to visualize all associations of a given symbol. Fixes #130533 Fixes #140882
1 parent b1703ad commit aac1f85

26 files changed

+383
-171
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- include/flang/Semantics/openmp-dsa.h --------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_SEMANTICS_OPENMP_DSA_H_
10+
#define FORTRAN_SEMANTICS_OPENMP_DSA_H_
11+
12+
#include "flang/Semantics/symbol.h"
13+
14+
namespace Fortran::semantics {
15+
16+
Symbol::Flags GetSymbolDSA(const Symbol &symbol);
17+
18+
} // namespace Fortran::semantics
19+
20+
#endif // FORTRAN_SEMANTICS_OPENMP_DSA_H_

flang/include/flang/Semantics/symbol.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,9 @@ class Symbol {
785785
OmpAllocate, OmpDeclarativeAllocateDirective,
786786
OmpExecutableAllocateDirective, OmpDeclareSimd, OmpDeclareTarget,
787787
OmpThreadprivate, OmpDeclareReduction, OmpFlushed, OmpCriticalLock,
788-
OmpIfSpecified, OmpNone, OmpPreDetermined, OmpImplicit, OmpDependObject,
789-
OmpInclusiveScan, OmpExclusiveScan, OmpInScanReduction, OmpUniform);
788+
OmpIfSpecified, OmpNone, OmpPreDetermined, OmpExplicit, OmpImplicit,
789+
OmpDependObject, OmpInclusiveScan, OmpExclusiveScan, OmpInScanReduction,
790+
OmpUniform);
790791
using Flags = common::EnumSet<Flag, Flag_enumSize>;
791792

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

flang/lib/Lower/Bridge.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "flang/Optimizer/Transforms/Passes.h"
6060
#include "flang/Parser/parse-tree.h"
6161
#include "flang/Runtime/iostat-consts.h"
62+
#include "flang/Semantics/openmp-dsa.h"
6263
#include "flang/Semantics/runtime-type-info.h"
6364
#include "flang/Semantics/symbol.h"
6465
#include "flang/Semantics/tools.h"
@@ -1387,7 +1388,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
13871388
if (isUnordered || sym.has<Fortran::semantics::HostAssocDetails>() ||
13881389
sym.has<Fortran::semantics::UseDetails>()) {
13891390
if (!shallowLookupSymbol(sym) &&
1390-
!sym.test(Fortran::semantics::Symbol::Flag::OmpShared)) {
1391+
!GetSymbolDSA(sym).test(
1392+
Fortran::semantics::Symbol::Flag::OmpShared)) {
13911393
// Do concurrent loop variables are not mapped yet since they are local
13921394
// to the Do concurrent scope (same for OpenMP loops).
13931395
mlir::OpBuilder::InsertPoint insPt = builder->saveInsertionPoint();

flang/lib/Semantics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ add_flang_library(FortranSemantics
3232
dump-expr.cpp
3333
expression.cpp
3434
mod-file.cpp
35+
openmp-dsa.cpp
3536
openmp-modifiers.cpp
3637
pointer-assignment.cpp
3738
program-tree.cpp

flang/lib/Semantics/openmp-dsa.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===-- flang/lib/Semantics/openmp-dsa.cpp ----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "flang/Semantics/openmp-dsa.h"
10+
11+
namespace Fortran::semantics {
12+
13+
Symbol::Flags GetSymbolDSA(const Symbol &symbol) {
14+
Symbol::Flags dsaFlags{Symbol::Flag::OmpPrivate,
15+
Symbol::Flag::OmpFirstPrivate, Symbol::Flag::OmpLastPrivate,
16+
Symbol::Flag::OmpShared, Symbol::Flag::OmpLinear,
17+
Symbol::Flag::OmpReduction};
18+
Symbol::Flags dsa{symbol.flags() & dsaFlags};
19+
if (dsa.any()) {
20+
return dsa;
21+
}
22+
// If no DSA are set use those from the host associated symbol, if any.
23+
if (const auto *details{symbol.detailsIf<HostAssocDetails>()}) {
24+
return GetSymbolDSA(details->symbol());
25+
}
26+
return {};
27+
}
28+
29+
} // namespace Fortran::semantics

0 commit comments

Comments
 (0)