@@ -520,6 +520,7 @@ static void createBodyOfOp(Op &op, OpWithBodyGenInfo &info) {
520
520
if (!info.dsp ) {
521
521
tempDsp.emplace (info.converter , *info.clauses , info.eval );
522
522
tempDsp->processStep1 ();
523
+ tempDsp->processStep2 ();
523
524
}
524
525
}
525
526
@@ -593,11 +594,11 @@ static void createBodyOfOp(Op &op, OpWithBodyGenInfo &info) {
593
594
if (privatize) {
594
595
if (!info.dsp ) {
595
596
assert (tempDsp.has_value ());
596
- tempDsp->processStep2 (op, isLoop);
597
+ tempDsp->processStep3 (op, isLoop);
597
598
} else {
598
599
if (isLoop && regionArgs.size () > 0 )
599
600
info.dsp ->setLoopIV (info.converter .getSymbolAddress (*regionArgs[0 ]));
600
- info.dsp ->processStep2 (op, isLoop);
601
+ info.dsp ->processStep3 (op, isLoop);
601
602
}
602
603
}
603
604
}
@@ -816,8 +817,11 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
816
817
DataSharingProcessor dsp (converter, clauseList, eval,
817
818
/* useDelayedPrivatization=*/ true , &symTable);
818
819
819
- if (privatize)
820
+ if (privatize) {
820
821
dsp.processStep1 ();
822
+ dsp.processStep2 ();
823
+ }
824
+
821
825
822
826
const auto &delayedPrivatizationInfo = dsp.getDelayedPrivatizationInfo ();
823
827
@@ -1093,7 +1097,9 @@ static void genBodyOfTargetOp(
1093
1097
const llvm::SmallVector<mlir::Type> &mapSymTypes,
1094
1098
const llvm::SmallVector<mlir::Location> &mapSymLocs,
1095
1099
const llvm::SmallVector<const Fortran::semantics::Symbol *> &mapSymbols,
1096
- const mlir::Location ¤tLocation) {
1100
+ const mlir::Location ¤tLocation,
1101
+ const Fortran::parser::OmpClauseList &clauseList,
1102
+ DataSharingProcessor &dsp) {
1097
1103
assert (mapSymTypes.size () == mapSymLocs.size ());
1098
1104
1099
1105
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
@@ -1102,6 +1108,8 @@ static void genBodyOfTargetOp(
1102
1108
auto *regionBlock =
1103
1109
firOpBuilder.createBlock (®ion, {}, mapSymTypes, mapSymLocs);
1104
1110
1111
+ dsp.processStep2 ();
1112
+
1105
1113
// Clones the `bounds` placing them inside the target region and returns them.
1106
1114
auto cloneBound = [&](mlir::Value bound) {
1107
1115
if (mlir::isMemoryEffectFree (bound.getDefiningOp ())) {
@@ -1243,7 +1251,8 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
1243
1251
Fortran::lower::pft::Evaluation &eval, bool genNested,
1244
1252
mlir::Location currentLocation,
1245
1253
const Fortran::parser::OmpClauseList &clauseList,
1246
- llvm::omp::Directive directive, bool outerCombined = false ) {
1254
+ llvm::omp::Directive directive, bool outerCombined = false ,
1255
+ DataSharingProcessor *dsp = nullptr ) {
1247
1256
Fortran::lower::StatementContext stmtCtx;
1248
1257
mlir::Value ifClauseOperand, deviceOperand, threadLimitOperand;
1249
1258
mlir::UnitAttr nowaitAttr;
@@ -1262,9 +1271,7 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
1262
1271
cp.processDepend (dependTypeOperands, dependOperands);
1263
1272
cp.processMap (currentLocation, directive, stmtCtx, mapOperands, &mapSymTypes,
1264
1273
&mapSymLocs, &mapSymbols);
1265
-
1266
- cp.processTODO <Fortran::parser::OmpClause::Private,
1267
- Fortran::parser::OmpClause::Firstprivate,
1274
+ cp.processTODO <Fortran::parser::OmpClause::Firstprivate,
1268
1275
Fortran::parser::OmpClause::IsDevicePtr,
1269
1276
Fortran::parser::OmpClause::HasDeviceAddr,
1270
1277
Fortran::parser::OmpClause::InReduction,
@@ -1273,6 +1280,10 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
1273
1280
Fortran::parser::OmpClause::Defaultmap>(
1274
1281
currentLocation, llvm::omp::Directive::OMPD_target);
1275
1282
1283
+ DataSharingProcessor localDSP (converter, clauseList, eval);
1284
+ DataSharingProcessor &actualDSP = dsp ? *dsp : localDSP;
1285
+ actualDSP.processStep1 ();
1286
+
1276
1287
// Process host-only clauses.
1277
1288
if (!llvm::cast<mlir::omp::OffloadModuleInterface>(*converter.getModuleOp ())
1278
1289
.getIsTargetDevice ())
@@ -1283,9 +1294,14 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
1283
1294
1284
1295
// 5.8.1 Implicit Data-Mapping Attribute Rules
1285
1296
// The following code follows the implicit data-mapping rules to map all the
1286
- // symbols used inside the region that have not been explicitly mapped using
1287
- // the map clause.
1297
+ // symbols used inside the region that do not have explicit data-environment
1298
+ // attribute clauses (neither data-sharing; e.g. `private`, nor `map`
1299
+ // clauses).
1288
1300
auto captureImplicitMap = [&](const Fortran::semantics::Symbol &sym) {
1301
+ if (actualDSP.getPrivatizedSymbols ().contains (&sym)) {
1302
+ return ;
1303
+ }
1304
+
1289
1305
if (llvm::find (mapSymbols, &sym) == mapSymbols.end ()) {
1290
1306
mlir::Value baseOp = converter.getSymbolAddress (sym);
1291
1307
if (!baseOp)
@@ -1383,7 +1399,8 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
1383
1399
/* teams_thread_limit=*/ nullptr , /* num_threads=*/ nullptr );
1384
1400
1385
1401
genBodyOfTargetOp (converter, semaCtx, eval, genNested, targetOp, mapSymTypes,
1386
- mapSymLocs, mapSymbols, currentLocation);
1402
+ mapSymLocs, mapSymbols, currentLocation, clauseList,
1403
+ actualDSP);
1387
1404
1388
1405
return targetOp;
1389
1406
}
@@ -1459,7 +1476,8 @@ genDistributeOp(Fortran::lower::AbstractConverter &converter,
1459
1476
Fortran::lower::pft::Evaluation &eval, bool genNested,
1460
1477
mlir::Location currentLocation,
1461
1478
const Fortran::parser::OmpClauseList &clauseList,
1462
- bool outerCombined = false ) {
1479
+ bool outerCombined = false ,
1480
+ DataSharingProcessor *dsp = nullptr ) {
1463
1481
// TODO Process clauses
1464
1482
// ClauseProcessor cp(converter, clauseList);
1465
1483
// cp.processAllocate(allocatorOperands, allocateOperands);
@@ -1469,7 +1487,8 @@ genDistributeOp(Fortran::lower::AbstractConverter &converter,
1469
1487
OpWithBodyGenInfo (converter, semaCtx, currentLocation, eval)
1470
1488
.setGenNested (genNested)
1471
1489
.setOuterCombined (outerCombined)
1472
- .setClauses (&clauseList),
1490
+ .setClauses (&clauseList)
1491
+ .setDataSharingProcessor (dsp),
1473
1492
/* dist_schedule_static=*/ nullptr ,
1474
1493
/* chunk_size=*/ nullptr ,
1475
1494
/* allocate_vars=*/ mlir::ValueRange (),
@@ -1780,6 +1799,7 @@ createSimdLoop(Fortran::lower::AbstractConverter &converter,
1780
1799
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
1781
1800
DataSharingProcessor dsp (converter, loopOpClauseList, eval);
1782
1801
dsp.processStep1 ();
1802
+ dsp.processStep2 ();
1783
1803
1784
1804
Fortran::lower::StatementContext stmtCtx;
1785
1805
mlir::Value scheduleChunkClauseOperand, ifClauseOperand;
@@ -1836,10 +1856,10 @@ static void createWsLoop(Fortran::lower::AbstractConverter &converter,
1836
1856
llvm::omp::Directive ompDirective,
1837
1857
const Fortran::parser::OmpClauseList &beginClauseList,
1838
1858
const Fortran::parser::OmpClauseList *endClauseList,
1839
- mlir::Location loc) {
1859
+ mlir::Location loc, DataSharingProcessor &dsp ) {
1840
1860
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
1841
- DataSharingProcessor dsp (converter, beginClauseList, eval);
1842
1861
dsp.processStep1 ();
1862
+ dsp.processStep2 ();
1843
1863
1844
1864
Fortran::lower::StatementContext stmtCtx;
1845
1865
mlir::Value scheduleChunkClauseOperand;
@@ -1962,8 +1982,9 @@ static void createSimdWsLoop(
1962
1982
// When support for vectorization is enabled, then we need to add handling of
1963
1983
// if clause. Currently if clause can be skipped because we always assume
1964
1984
// SIMD length = 1.
1985
+ DataSharingProcessor dsp (converter, beginClauseList, eval);
1965
1986
createWsLoop (converter, semaCtx, eval, ompDirective, beginClauseList,
1966
- endClauseList, loc);
1987
+ endClauseList, loc, dsp );
1967
1988
}
1968
1989
1969
1990
static void genOMP (Fortran::lower::AbstractConverter &converter,
@@ -1992,6 +2013,8 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
1992
2013
}();
1993
2014
1994
2015
bool validDirective = false ;
2016
+ DataSharingProcessor dsp (converter, loopOpClauseList, eval);
2017
+
1995
2018
if (llvm::omp::topTaskloopSet.test (ompDirective)) {
1996
2019
validDirective = true ;
1997
2020
TODO (currentLocation, " Taskloop construct" );
@@ -2002,7 +2025,7 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
2002
2025
validDirective = true ;
2003
2026
genTargetOp (converter, semaCtx, eval, /* genNested=*/ false ,
2004
2027
currentLocation, loopOpClauseList, ompDirective,
2005
- /* outerCombined=*/ true );
2028
+ /* outerCombined=*/ true , &dsp );
2006
2029
}
2007
2030
if ((llvm::omp::allTeamsSet & llvm::omp::loopConstructSet)
2008
2031
.test (ompDirective)) {
@@ -2014,7 +2037,7 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
2014
2037
validDirective = true ;
2015
2038
bool outerCombined = llvm::omp::topDistributeSet.test (ompDirective);
2016
2039
genDistributeOp (converter, semaCtx, eval, /* genNested=*/ false ,
2017
- currentLocation, loopOpClauseList, outerCombined);
2040
+ currentLocation, loopOpClauseList, outerCombined, &dsp );
2018
2041
}
2019
2042
if ((llvm::omp::allParallelSet & llvm::omp::loopConstructSet)
2020
2043
.test (ompDirective)) {
@@ -2045,7 +2068,7 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
2045
2068
genOpenMPReduction (converter, semaCtx, loopOpClauseList);
2046
2069
} else {
2047
2070
createWsLoop (converter, semaCtx, eval, ompDirective, loopOpClauseList,
2048
- endClauseList, currentLocation);
2071
+ endClauseList, currentLocation, dsp );
2049
2072
}
2050
2073
}
2051
2074
0 commit comments