Skip to content

[flang][OpenMP] Explicitly set Shared DSA in symbols #142154

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 2 commits into from
Jun 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
20 changes: 20 additions & 0 deletions flang/include/flang/Semantics/openmp-dsa.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- include/flang/Semantics/openmp-dsa.h --------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_SEMANTICS_OPENMP_DSA_H_
#define FORTRAN_SEMANTICS_OPENMP_DSA_H_

#include "flang/Semantics/symbol.h"

namespace Fortran::semantics {

Symbol::Flags GetSymbolDSA(const Symbol &symbol);

} // namespace Fortran::semantics

#endif // FORTRAN_SEMANTICS_OPENMP_DSA_H_
5 changes: 3 additions & 2 deletions flang/include/flang/Semantics/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,9 @@ class Symbol {
OmpAllocate, OmpDeclarativeAllocateDirective,
OmpExecutableAllocateDirective, OmpDeclareSimd, OmpDeclareTarget,
OmpThreadprivate, OmpDeclareReduction, OmpFlushed, OmpCriticalLock,
OmpIfSpecified, OmpNone, OmpPreDetermined, OmpImplicit, OmpDependObject,
OmpInclusiveScan, OmpExclusiveScan, OmpInScanReduction, OmpUniform);
OmpIfSpecified, OmpNone, OmpPreDetermined, OmpExplicit, OmpImplicit,
OmpDependObject, OmpInclusiveScan, OmpExclusiveScan, OmpInScanReduction,
OmpUniform);
using Flags = common::EnumSet<Flag, Flag_enumSize>;

const Scope &owner() const { return *owner_; }
Expand Down
4 changes: 3 additions & 1 deletion flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "flang/Optimizer/Transforms/Passes.h"
#include "flang/Parser/parse-tree.h"
#include "flang/Runtime/iostat-consts.h"
#include "flang/Semantics/openmp-dsa.h"
#include "flang/Semantics/runtime-type-info.h"
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
Expand Down Expand Up @@ -1387,7 +1388,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
if (isUnordered || sym.has<Fortran::semantics::HostAssocDetails>() ||
sym.has<Fortran::semantics::UseDetails>()) {
if (!shallowLookupSymbol(sym) &&
!sym.test(Fortran::semantics::Symbol::Flag::OmpShared)) {
!GetSymbolDSA(sym).test(
Fortran::semantics::Symbol::Flag::OmpShared)) {
// Do concurrent loop variables are not mapped yet since they are local
// to the Do concurrent scope (same for OpenMP loops).
mlir::OpBuilder::InsertPoint insPt = builder->saveInsertionPoint();
Expand Down
1 change: 1 addition & 0 deletions flang/lib/Semantics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_flang_library(FortranSemantics
dump-expr.cpp
expression.cpp
mod-file.cpp
openmp-dsa.cpp
openmp-modifiers.cpp
pointer-assignment.cpp
program-tree.cpp
Expand Down
29 changes: 29 additions & 0 deletions flang/lib/Semantics/openmp-dsa.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===-- flang/lib/Semantics/openmp-dsa.cpp ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "flang/Semantics/openmp-dsa.h"

namespace Fortran::semantics {

Symbol::Flags GetSymbolDSA(const Symbol &symbol) {
Symbol::Flags dsaFlags{Symbol::Flag::OmpPrivate,
Symbol::Flag::OmpFirstPrivate, Symbol::Flag::OmpLastPrivate,
Symbol::Flag::OmpShared, Symbol::Flag::OmpLinear,
Symbol::Flag::OmpReduction};
Symbol::Flags dsa{symbol.flags() & dsaFlags};
if (dsa.any()) {
return dsa;
}
// If no DSA are set use those from the host associated symbol, if any.
if (const auto *details{symbol.detailsIf<HostAssocDetails>()}) {
return GetSymbolDSA(details->symbol());
}
return {};
}

} // namespace Fortran::semantics
Loading
Loading