10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
- #include " PrivateReductionUtils.h"
13
+ #include " flang/Lower/Support/ PrivateReductionUtils.h"
14
14
15
15
#include " flang/Lower/AbstractConverter.h"
16
16
#include " flang/Lower/Allocatable.h"
@@ -42,7 +42,8 @@ static bool hasFinalization(const Fortran::semantics::Symbol &sym) {
42
42
static void createCleanupRegion (Fortran::lower::AbstractConverter &converter,
43
43
mlir::Location loc, mlir::Type argType,
44
44
mlir::Region &cleanupRegion,
45
- const Fortran::semantics::Symbol *sym) {
45
+ const Fortran::semantics::Symbol *sym,
46
+ bool isDoConcurrent) {
46
47
fir::FirOpBuilder &builder = converter.getFirOpBuilder ();
47
48
assert (cleanupRegion.empty ());
48
49
mlir::Block *block = builder.createBlock (&cleanupRegion, cleanupRegion.end (),
@@ -73,7 +74,10 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter,
73
74
fir::MutableBoxValue mutableBox{converted, /* lenParameters=*/ {},
74
75
/* mutableProperties=*/ {}};
75
76
Fortran::lower::genDeallocateIfAllocated (converter, mutableBox, loc);
76
- builder.create <mlir::omp::YieldOp>(loc);
77
+ if (isDoConcurrent)
78
+ builder.create <fir::YieldOp>(loc);
79
+ else
80
+ builder.create <mlir::omp::YieldOp>(loc);
77
81
return ;
78
82
}
79
83
}
@@ -101,7 +105,10 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter,
101
105
builder.create <fir::FreeMemOp>(loc, cast);
102
106
103
107
builder.setInsertionPointAfter (ifOp);
104
- builder.create <mlir::omp::YieldOp>(loc);
108
+ if (isDoConcurrent)
109
+ builder.create <fir::YieldOp>(loc);
110
+ else
111
+ builder.create <mlir::omp::YieldOp>(loc);
105
112
return ;
106
113
}
107
114
@@ -116,14 +123,18 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter,
116
123
addr = builder.createConvert (loc, heapTy, addr);
117
124
118
125
builder.create <fir::FreeMemOp>(loc, addr);
119
- builder.create <mlir::omp::YieldOp>(loc);
126
+ if (isDoConcurrent)
127
+ builder.create <fir::YieldOp>(loc);
128
+ else
129
+ builder.create <mlir::omp::YieldOp>(loc);
130
+
120
131
return ;
121
132
}
122
133
123
134
typeError ();
124
135
}
125
136
126
- fir::ShapeShiftOp Fortran::lower::omp:: getShapeShift (
137
+ fir::ShapeShiftOp Fortran::lower::getShapeShift (
127
138
fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box,
128
139
bool cannotHaveNonDefaultLowerBounds, bool useDefaultLowerBounds) {
129
140
fir::SequenceType sequenceType = mlir::cast<fir::SequenceType>(
@@ -263,7 +274,7 @@ static mlir::Value generateZeroShapeForRank(fir::FirOpBuilder &builder,
263
274
}
264
275
265
276
namespace {
266
- using namespace Fortran ::lower::omp ;
277
+ using namespace Fortran ::lower;
267
278
// / Class to store shared data so we don't have to maintain so many function
268
279
// / arguments
269
280
class PopulateInitAndCleanupRegionsHelper {
@@ -274,12 +285,13 @@ class PopulateInitAndCleanupRegionsHelper {
274
285
mlir::Value allocatedPrivVarArg, mlir::Value moldArg,
275
286
mlir::Block *initBlock, mlir::Region &cleanupRegion,
276
287
DeclOperationKind kind, const Fortran::semantics::Symbol *sym,
277
- bool cannotHaveLowerBounds)
288
+ bool cannotHaveLowerBounds, bool isDoConcurrent )
278
289
: converter{converter}, builder{converter.getFirOpBuilder ()}, loc{loc},
279
290
argType{argType}, scalarInitValue{scalarInitValue},
280
291
allocatedPrivVarArg{allocatedPrivVarArg}, moldArg{moldArg},
281
292
initBlock{initBlock}, cleanupRegion{cleanupRegion}, kind{kind},
282
- sym{sym}, cannotHaveNonDefaultLowerBounds{cannotHaveLowerBounds} {
293
+ sym{sym}, cannotHaveNonDefaultLowerBounds{cannotHaveLowerBounds},
294
+ isDoConcurrent{isDoConcurrent} {
283
295
valType = fir::unwrapRefType (argType);
284
296
}
285
297
@@ -325,8 +337,13 @@ class PopulateInitAndCleanupRegionsHelper {
325
337
// / lower bounds then we don't need to generate code to read them.
326
338
bool cannotHaveNonDefaultLowerBounds;
327
339
340
+ bool isDoConcurrent;
341
+
328
342
void createYield (mlir::Value ret) {
329
- builder.create <mlir::omp::YieldOp>(loc, ret);
343
+ if (isDoConcurrent)
344
+ builder.create <fir::YieldOp>(loc, ret);
345
+ else
346
+ builder.create <mlir::omp::YieldOp>(loc, ret);
330
347
}
331
348
332
349
void initTrivialType () {
@@ -430,11 +447,12 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedScalar(
430
447
/* slice=*/ mlir::Value{}, lenParams);
431
448
initializeIfDerivedTypeBox (
432
449
builder, loc, box, getLoadedMoldArg (), needsInitialization,
433
- /* isFirstPrivate=*/ kind == DeclOperationKind::FirstPrivate );
450
+ /* isFirstPrivate=*/ kind == DeclOperationKind::FirstPrivateOrLocalInit );
434
451
fir::StoreOp lastOp =
435
452
builder.create <fir::StoreOp>(loc, box, allocatedPrivVarArg);
436
453
437
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
454
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
455
+ isDoConcurrent);
438
456
439
457
if (ifUnallocated)
440
458
builder.setInsertionPointAfter (ifUnallocated);
@@ -471,13 +489,14 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray(
471
489
allocatedArray, shape);
472
490
initializeIfDerivedTypeBox (
473
491
builder, loc, firClass, source, needsInitialization,
474
- /* isFirstprivate=*/ kind == DeclOperationKind::FirstPrivate );
492
+ /* isFirstprivate=*/ kind == DeclOperationKind::FirstPrivateOrLocalInit );
475
493
builder.create <fir::StoreOp>(loc, firClass, allocatedPrivVarArg);
476
494
if (ifUnallocated)
477
495
builder.setInsertionPointAfter (ifUnallocated);
478
496
createYield (allocatedPrivVarArg);
479
497
mlir::OpBuilder::InsertionGuard guard (builder);
480
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
498
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
499
+ isDoConcurrent);
481
500
return ;
482
501
}
483
502
@@ -502,7 +521,8 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray(
502
521
" createTempFromMold decides this statically" );
503
522
if (cstNeedsDealloc.has_value () && *cstNeedsDealloc != false ) {
504
523
mlir::OpBuilder::InsertionGuard guard (builder);
505
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
524
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
525
+ isDoConcurrent);
506
526
} else {
507
527
assert (!isAllocatableOrPointer &&
508
528
" Pointer-like arrays must be heap allocated" );
@@ -530,7 +550,7 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray(
530
550
531
551
initializeIfDerivedTypeBox (
532
552
builder, loc, box, getLoadedMoldArg (), needsInitialization,
533
- /* isFirstPrivate=*/ kind == DeclOperationKind::FirstPrivate );
553
+ /* isFirstPrivate=*/ kind == DeclOperationKind::FirstPrivateOrLocalInit );
534
554
535
555
builder.create <fir::StoreOp>(loc, box, allocatedPrivVarArg);
536
556
if (ifUnallocated)
@@ -558,7 +578,8 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxchar(
558
578
loc, eleTy, /* name=*/ {}, /* shape=*/ {}, /* lenParams=*/ len);
559
579
mlir::Value boxChar = charExprHelper.createEmboxChar (privateAddr, len);
560
580
561
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
581
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
582
+ isDoConcurrent);
562
583
563
584
builder.setInsertionPointToEnd (initBlock);
564
585
createYield (boxChar);
@@ -573,10 +594,11 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupUnboxedDerivedType(
573
594
mlir::Value moldBox = builder.create <fir::EmboxOp>(loc, boxedTy, moldArg);
574
595
initializeIfDerivedTypeBox (builder, loc, newBox, moldBox, needsInitialization,
575
596
/* isFirstPrivate=*/ kind ==
576
- DeclOperationKind::FirstPrivate );
597
+ DeclOperationKind::FirstPrivateOrLocalInit );
577
598
578
599
if (sym && hasFinalization (*sym))
579
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
600
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
601
+ isDoConcurrent);
580
602
581
603
builder.setInsertionPointToEnd (initBlock);
582
604
createYield (allocatedPrivVarArg);
@@ -642,15 +664,17 @@ void PopulateInitAndCleanupRegionsHelper::populateByRefInitAndCleanupRegions() {
642
664
" creating reduction/privatization init region for unsupported type" );
643
665
}
644
666
645
- void Fortran::lower::omp:: populateByRefInitAndCleanupRegions (
667
+ void Fortran::lower::populateByRefInitAndCleanupRegions (
646
668
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
647
669
mlir::Type argType, mlir::Value scalarInitValue, mlir::Block *initBlock,
648
670
mlir::Value allocatedPrivVarArg, mlir::Value moldArg,
649
671
mlir::Region &cleanupRegion, DeclOperationKind kind,
650
- const Fortran::semantics::Symbol *sym, bool cannotHaveLowerBounds) {
672
+ const Fortran::semantics::Symbol *sym, bool cannotHaveLowerBounds,
673
+ bool isDoConcurrent) {
651
674
PopulateInitAndCleanupRegionsHelper helper (
652
675
converter, loc, argType, scalarInitValue, allocatedPrivVarArg, moldArg,
653
- initBlock, cleanupRegion, kind, sym, cannotHaveLowerBounds);
676
+ initBlock, cleanupRegion, kind, sym, cannotHaveLowerBounds,
677
+ isDoConcurrent);
654
678
helper.populateByRefInitAndCleanupRegions ();
655
679
656
680
// Often we load moldArg to check something (e.g. length parameters, shape)
0 commit comments