llvm-project/flang/lib/Semantics/openmp-dsa.cpp
Leandro Lupori aac1f85393
[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
2025-06-03 10:58:23 -03:00

30 lines
1.0 KiB
C++

//===-- 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