12
12
13
13
#include " flang/Lower/Bridge.h"
14
14
15
+ #include " OpenMP/DataSharingProcessor.h"
16
+ #include " OpenMP/Utils.h"
15
17
#include " flang/Lower/Allocatable.h"
16
18
#include " flang/Lower/CallInterface.h"
17
19
#include " flang/Lower/Coarray.h"
@@ -1136,6 +1138,14 @@ class FirConverter : public Fortran::lower::AbstractConverter {
1136
1138
return name;
1137
1139
}
1138
1140
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
+
1139
1149
private:
1140
1150
FirConverter () = delete ;
1141
1151
FirConverter (const FirConverter &) = delete ;
@@ -1210,14 +1220,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
1210
1220
return {};
1211
1221
}
1212
1222
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
-
1221
1223
// / Find the symbol in one level up of symbol map such as for host-association
1222
1224
// / in OpenMP code or return null.
1223
1225
Fortran::lower::SymbolBox
@@ -2017,12 +2019,29 @@ class FirConverter : public Fortran::lower::AbstractConverter {
2017
2019
2018
2020
// / Create DO CONCURRENT construct symbol bindings and generate LOCAL_INIT
2019
2021
// / assignments.
2020
- void handleLocalitySpecs (const IncrementLoopInfo &info) {
2022
+ void handleLocalitySpecs (IncrementLoopInfo &info) {
2021
2023
Fortran::semantics::SemanticsContext &semanticsContext =
2022
2024
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
+
2024
2036
createHostAssociateVarClone (*sym, /* skipDefaultInit=*/ false );
2037
+ }
2038
+
2025
2039
for (const Fortran::semantics::Symbol *sym : info.localInitSymList ) {
2040
+ if (enableDelayedPrivatizationStaging) {
2041
+ dsp.doPrivatize (sym, &privateClauseOps);
2042
+ continue ;
2043
+ }
2044
+
2026
2045
createHostAssociateVarClone (*sym, /* skipDefaultInit=*/ true );
2027
2046
const auto *hostDetails =
2028
2047
sym->detailsIf <Fortran::semantics::HostAssocDetails>();
@@ -2036,11 +2055,27 @@ class FirConverter : public Fortran::lower::AbstractConverter {
2036
2055
assign.u = Fortran::evaluate::Assignment::BoundsSpec{};
2037
2056
genAssignment (assign);
2038
2057
}
2058
+
2039
2059
for (const Fortran::semantics::Symbol *sym : info.sharedSymList ) {
2040
2060
const auto *hostDetails =
2041
2061
sym->detailsIf <Fortran::semantics::HostAssocDetails>();
2042
2062
copySymbolBinding (hostDetails->symbol (), *sym);
2043
2063
}
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
+
2044
2079
// Note that allocatable, types with ultimate components, and type
2045
2080
// requiring finalization are forbidden in LOCAL/LOCAL_INIT (F2023 C1130),
2046
2081
// so no clean-up needs to be generated for these entities.
0 commit comments