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
@@ -2014,12 +2016,29 @@ class FirConverter : public Fortran::lower::AbstractConverter {
20142016
20152017 // / Create DO CONCURRENT construct symbol bindings and generate LOCAL_INIT
20162018 // / assignments.
2017- void handleLocalitySpecs (const IncrementLoopInfo &info) {
2019+ void handleLocalitySpecs (IncrementLoopInfo &info) {
20182020 Fortran::semantics::SemanticsContext &semanticsContext =
20192021 bridge.getSemanticsContext ();
2020- for (const Fortran::semantics::Symbol *sym : info.localSymList )
2022+ Fortran::lower::omp::DataSharingProcessor dsp (
2023+ *this , semanticsContext, getEval (),
2024+ /* useDelayedPrivatization=*/ true , localSymbols);
2025+ mlir::omp::PrivateClauseOps privateClauseOps;
2026+
2027+ for (const Fortran::semantics::Symbol *sym : info.localSymList ) {
2028+ if (enableDelayedPrivatizationStaging) {
2029+ dsp.doPrivatize (sym, &privateClauseOps);
2030+ continue ;
2031+ }
2032+
20212033 createHostAssociateVarClone (*sym, /* skipDefaultInit=*/ false );
2034+ }
2035+
20222036 for (const Fortran::semantics::Symbol *sym : info.localInitSymList ) {
2037+ if (enableDelayedPrivatizationStaging) {
2038+ dsp.doPrivatize (sym, &privateClauseOps);
2039+ continue ;
2040+ }
2041+
20232042 createHostAssociateVarClone (*sym, /* skipDefaultInit=*/ true );
20242043 const auto *hostDetails =
20252044 sym->detailsIf <Fortran::semantics::HostAssocDetails>();
@@ -2033,11 +2052,27 @@ class FirConverter : public Fortran::lower::AbstractConverter {
20332052 assign.u = Fortran::evaluate::Assignment::BoundsSpec{};
20342053 genAssignment (assign);
20352054 }
2055+
20362056 for (const Fortran::semantics::Symbol *sym : info.sharedSymList ) {
20372057 const auto *hostDetails =
20382058 sym->detailsIf <Fortran::semantics::HostAssocDetails>();
20392059 copySymbolBinding (hostDetails->symbol (), *sym);
20402060 }
2061+
2062+ info.doLoop .getPrivateVarsMutable ().assign (privateClauseOps.privateVars );
2063+ info.doLoop .setPrivateSymsAttr (
2064+ builder->getArrayAttr (privateClauseOps.privateSyms ));
2065+
2066+ for (auto [sym, privateVar] : llvm::zip_equal (
2067+ dsp.getAllSymbolsToPrivatize (), privateClauseOps.privateVars )) {
2068+ auto arg = info.doLoop .getRegion ().begin ()->addArgument (
2069+ privateVar.getType (), info.doLoop .getLoc ());
2070+ bindSymbol (*sym, hlfir::translateToExtendedValue (
2071+ privateVar.getLoc (), *builder, hlfir::Entity{arg},
2072+ /* contiguousHint=*/ true )
2073+ .first );
2074+ }
2075+
20412076 // Note that allocatable, types with ultimate components, and type
20422077 // requiring finalization are forbidden in LOCAL/LOCAL_INIT (F2023 C1130),
20432078 // so no clean-up needs to be generated for these entities.
0 commit comments