1212
1313#include " flang/Lower/Bridge.h"
1414
15+ #include " OpenMP/DataSharingProcessor.h"
16+ #include " OpenMP/Utils.h"
1517#include " flang/Lower/Allocatable.h"
1618#include " flang/Lower/CallInterface.h"
1719#include " flang/Lower/Coarray.h"
@@ -1136,6 +1138,14 @@ class FirConverter : public Fortran::lower::AbstractConverter {
11361138 return name;
11371139 }
11381140
1141+ // / Find the symbol in the inner-most level of the local map or return null.
1142+ Fortran::lower::SymbolBox
1143+ shallowLookupSymbol (const Fortran::semantics::Symbol &sym) override {
1144+ if (Fortran::lower::SymbolBox v = localSymbols.shallowLookupSymbol (sym))
1145+ return v;
1146+ return {};
1147+ }
1148+
11391149private:
11401150 FirConverter () = delete ;
11411151 FirConverter (const FirConverter &) = delete ;
@@ -1210,14 +1220,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
12101220 return {};
12111221 }
12121222
1213- // / Find the symbol in the inner-most level of the local map or return null.
1214- Fortran::lower::SymbolBox
1215- shallowLookupSymbol (const Fortran::semantics::Symbol &sym) {
1216- if (Fortran::lower::SymbolBox v = localSymbols.shallowLookupSymbol (sym))
1217- return v;
1218- return {};
1219- }
1220-
12211223 // / Find the symbol in one level up of symbol map such as for host-association
12221224 // / in OpenMP code or return null.
12231225 Fortran::lower::SymbolBox
@@ -2017,12 +2019,29 @@ class FirConverter : public Fortran::lower::AbstractConverter {
20172019
20182020 // / Create DO CONCURRENT construct symbol bindings and generate LOCAL_INIT
20192021 // / assignments.
2020- void handleLocalitySpecs (const IncrementLoopInfo &info) {
2022+ void handleLocalitySpecs (IncrementLoopInfo &info) {
20212023 Fortran::semantics::SemanticsContext &semanticsContext =
20222024 bridge.getSemanticsContext ();
2023- for (const Fortran::semantics::Symbol *sym : info.localSymList )
2025+ Fortran::lower::omp::DataSharingProcessor dsp (
2026+ *this , semanticsContext, getEval (),
2027+ /* useDelayedPrivatization=*/ true , localSymbols);
2028+ mlir::omp::PrivateClauseOps privateClauseOps;
2029+
2030+ for (const Fortran::semantics::Symbol *sym : info.localSymList ) {
2031+ if (enableDelayedPrivatizationStaging) {
2032+ dsp.doPrivatize (sym, &privateClauseOps);
2033+ continue ;
2034+ }
2035+
20242036 createHostAssociateVarClone (*sym, /* skipDefaultInit=*/ false );
2037+ }
2038+
20252039 for (const Fortran::semantics::Symbol *sym : info.localInitSymList ) {
2040+ if (enableDelayedPrivatizationStaging) {
2041+ dsp.doPrivatize (sym, &privateClauseOps);
2042+ continue ;
2043+ }
2044+
20262045 createHostAssociateVarClone (*sym, /* skipDefaultInit=*/ true );
20272046 const auto *hostDetails =
20282047 sym->detailsIf <Fortran::semantics::HostAssocDetails>();
@@ -2036,11 +2055,27 @@ class FirConverter : public Fortran::lower::AbstractConverter {
20362055 assign.u = Fortran::evaluate::Assignment::BoundsSpec{};
20372056 genAssignment (assign);
20382057 }
2058+
20392059 for (const Fortran::semantics::Symbol *sym : info.sharedSymList ) {
20402060 const auto *hostDetails =
20412061 sym->detailsIf <Fortran::semantics::HostAssocDetails>();
20422062 copySymbolBinding (hostDetails->symbol (), *sym);
20432063 }
2064+
2065+ info.doLoop .getPrivateVarsMutable ().assign (privateClauseOps.privateVars );
2066+ info.doLoop .setPrivateSymsAttr (
2067+ builder->getArrayAttr (privateClauseOps.privateSyms ));
2068+
2069+ for (auto [sym, privateVar] : llvm::zip_equal (
2070+ dsp.getAllSymbolsToPrivatize (), privateClauseOps.privateVars )) {
2071+ auto arg = info.doLoop .getRegion ().begin ()->addArgument (
2072+ privateVar.getType (), info.doLoop .getLoc ());
2073+ bindSymbol (*sym, hlfir::translateToExtendedValue (
2074+ privateVar.getLoc (), *builder, hlfir::Entity{arg},
2075+ /* contiguousHint=*/ true )
2076+ .first );
2077+ }
2078+
20442079 // Note that allocatable, types with ultimate components, and type
20452080 // requiring finalization are forbidden in LOCAL/LOCAL_INIT (F2023 C1130),
20462081 // so no clean-up needs to be generated for these entities.
0 commit comments