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 (),
@@ -72,7 +73,10 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter,
72
73
fir::MutableBoxValue mutableBox{converted, /* lenParameters=*/ {},
73
74
/* mutableProperties=*/ {}};
74
75
Fortran::lower::genDeallocateIfAllocated (converter, mutableBox, loc);
75
- builder.create <mlir::omp::YieldOp>(loc);
76
+ if (isDoConcurrent)
77
+ builder.create <fir::YieldOp>(loc);
78
+ else
79
+ builder.create <mlir::omp::YieldOp>(loc);
76
80
return ;
77
81
}
78
82
}
@@ -100,7 +104,10 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter,
100
104
builder.create <fir::FreeMemOp>(loc, cast);
101
105
102
106
builder.setInsertionPointAfter (ifOp);
103
- builder.create <mlir::omp::YieldOp>(loc);
107
+ if (isDoConcurrent)
108
+ builder.create <fir::YieldOp>(loc);
109
+ else
110
+ builder.create <mlir::omp::YieldOp>(loc);
104
111
return ;
105
112
}
106
113
@@ -115,14 +122,18 @@ static void createCleanupRegion(Fortran::lower::AbstractConverter &converter,
115
122
addr = builder.createConvert (loc, heapTy, addr);
116
123
117
124
builder.create <fir::FreeMemOp>(loc, addr);
118
- builder.create <mlir::omp::YieldOp>(loc);
125
+ if (isDoConcurrent)
126
+ builder.create <fir::YieldOp>(loc);
127
+ else
128
+ builder.create <mlir::omp::YieldOp>(loc);
129
+
119
130
return ;
120
131
}
121
132
122
133
typeError ();
123
134
}
124
135
125
- fir::ShapeShiftOp Fortran::lower::omp:: getShapeShift (
136
+ fir::ShapeShiftOp Fortran::lower::getShapeShift (
126
137
fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box,
127
138
bool cannotHaveNonDefaultLowerBounds, bool useDefaultLowerBounds) {
128
139
fir::SequenceType sequenceType = mlir::cast<fir::SequenceType>(
@@ -262,7 +273,7 @@ static mlir::Value generateZeroShapeForRank(fir::FirOpBuilder &builder,
262
273
}
263
274
264
275
namespace {
265
- using namespace Fortran ::lower::omp ;
276
+ using namespace Fortran ::lower;
266
277
// / Class to store shared data so we don't have to maintain so many function
267
278
// / arguments
268
279
class PopulateInitAndCleanupRegionsHelper {
@@ -273,12 +284,13 @@ class PopulateInitAndCleanupRegionsHelper {
273
284
mlir::Value allocatedPrivVarArg, mlir::Value moldArg,
274
285
mlir::Block *initBlock, mlir::Region &cleanupRegion,
275
286
DeclOperationKind kind, const Fortran::semantics::Symbol *sym,
276
- bool cannotHaveLowerBounds)
287
+ bool cannotHaveLowerBounds, bool isDoConcurrent )
277
288
: converter{converter}, builder{converter.getFirOpBuilder ()}, loc{loc},
278
289
argType{argType}, scalarInitValue{scalarInitValue},
279
290
allocatedPrivVarArg{allocatedPrivVarArg}, moldArg{moldArg},
280
291
initBlock{initBlock}, cleanupRegion{cleanupRegion}, kind{kind},
281
- sym{sym}, cannotHaveNonDefaultLowerBounds{cannotHaveLowerBounds} {
292
+ sym{sym}, cannotHaveNonDefaultLowerBounds{cannotHaveLowerBounds},
293
+ isDoConcurrent{isDoConcurrent} {
282
294
valType = fir::unwrapRefType (argType);
283
295
}
284
296
@@ -324,8 +336,13 @@ class PopulateInitAndCleanupRegionsHelper {
324
336
// / lower bounds then we don't need to generate code to read them.
325
337
bool cannotHaveNonDefaultLowerBounds;
326
338
339
+ bool isDoConcurrent;
340
+
327
341
void createYield (mlir::Value ret) {
328
- builder.create <mlir::omp::YieldOp>(loc, ret);
342
+ if (isDoConcurrent)
343
+ builder.create <fir::YieldOp>(loc, ret);
344
+ else
345
+ builder.create <mlir::omp::YieldOp>(loc, ret);
329
346
}
330
347
331
348
void initTrivialType () {
@@ -429,11 +446,12 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedScalar(
429
446
/* slice=*/ mlir::Value{}, lenParams);
430
447
initializeIfDerivedTypeBox (
431
448
builder, loc, box, getLoadedMoldArg (), needsInitialization,
432
- /* isFirstPrivate=*/ kind == DeclOperationKind::FirstPrivate );
449
+ /* isFirstPrivate=*/ kind == DeclOperationKind::FirstPrivateOrLocalInit );
433
450
fir::StoreOp lastOp =
434
451
builder.create <fir::StoreOp>(loc, box, allocatedPrivVarArg);
435
452
436
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
453
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
454
+ isDoConcurrent);
437
455
438
456
if (ifUnallocated)
439
457
builder.setInsertionPointAfter (ifUnallocated);
@@ -470,13 +488,14 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray(
470
488
allocatedArray, shape);
471
489
initializeIfDerivedTypeBox (
472
490
builder, loc, firClass, source, needsInitialization,
473
- /* isFirstprivate=*/ kind == DeclOperationKind::FirstPrivate );
491
+ /* isFirstprivate=*/ kind == DeclOperationKind::FirstPrivateOrLocalInit );
474
492
builder.create <fir::StoreOp>(loc, firClass, allocatedPrivVarArg);
475
493
if (ifUnallocated)
476
494
builder.setInsertionPointAfter (ifUnallocated);
477
495
createYield (allocatedPrivVarArg);
478
496
mlir::OpBuilder::InsertionGuard guard (builder);
479
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
497
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
498
+ isDoConcurrent);
480
499
return ;
481
500
}
482
501
@@ -492,7 +511,8 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray(
492
511
" createTempFromMold decides this statically" );
493
512
if (cstNeedsDealloc.has_value () && *cstNeedsDealloc != false ) {
494
513
mlir::OpBuilder::InsertionGuard guard (builder);
495
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
514
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
515
+ isDoConcurrent);
496
516
} else {
497
517
assert (!isAllocatableOrPointer &&
498
518
" Pointer-like arrays must be heap allocated" );
@@ -520,7 +540,7 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxedArray(
520
540
521
541
initializeIfDerivedTypeBox (
522
542
builder, loc, box, getLoadedMoldArg (), needsInitialization,
523
- /* isFirstPrivate=*/ kind == DeclOperationKind::FirstPrivate );
543
+ /* isFirstPrivate=*/ kind == DeclOperationKind::FirstPrivateOrLocalInit );
524
544
525
545
builder.create <fir::StoreOp>(loc, box, allocatedPrivVarArg);
526
546
if (ifUnallocated)
@@ -548,7 +568,8 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupBoxchar(
548
568
loc, eleTy, /* name=*/ {}, /* shape=*/ {}, /* lenParams=*/ len);
549
569
mlir::Value boxChar = charExprHelper.createEmboxChar (privateAddr, len);
550
570
551
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
571
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
572
+ isDoConcurrent);
552
573
553
574
builder.setInsertionPointToEnd (initBlock);
554
575
createYield (boxChar);
@@ -563,10 +584,11 @@ void PopulateInitAndCleanupRegionsHelper::initAndCleanupUnboxedDerivedType(
563
584
mlir::Value moldBox = builder.create <fir::EmboxOp>(loc, boxedTy, moldArg);
564
585
initializeIfDerivedTypeBox (builder, loc, newBox, moldBox, needsInitialization,
565
586
/* isFirstPrivate=*/ kind ==
566
- DeclOperationKind::FirstPrivate );
587
+ DeclOperationKind::FirstPrivateOrLocalInit );
567
588
568
589
if (sym && hasFinalization (*sym))
569
- createCleanupRegion (converter, loc, argType, cleanupRegion, sym);
590
+ createCleanupRegion (converter, loc, argType, cleanupRegion, sym,
591
+ isDoConcurrent);
570
592
571
593
builder.setInsertionPointToEnd (initBlock);
572
594
createYield (allocatedPrivVarArg);
@@ -632,15 +654,17 @@ void PopulateInitAndCleanupRegionsHelper::populateByRefInitAndCleanupRegions() {
632
654
" creating reduction/privatization init region for unsupported type" );
633
655
}
634
656
635
- void Fortran::lower::omp:: populateByRefInitAndCleanupRegions (
657
+ void Fortran::lower::populateByRefInitAndCleanupRegions (
636
658
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
637
659
mlir::Type argType, mlir::Value scalarInitValue, mlir::Block *initBlock,
638
660
mlir::Value allocatedPrivVarArg, mlir::Value moldArg,
639
661
mlir::Region &cleanupRegion, DeclOperationKind kind,
640
- const Fortran::semantics::Symbol *sym, bool cannotHaveLowerBounds) {
662
+ const Fortran::semantics::Symbol *sym, bool cannotHaveLowerBounds,
663
+ bool isDoConcurrent) {
641
664
PopulateInitAndCleanupRegionsHelper helper (
642
665
converter, loc, argType, scalarInitValue, allocatedPrivVarArg, moldArg,
643
- initBlock, cleanupRegion, kind, sym, cannotHaveLowerBounds);
666
+ initBlock, cleanupRegion, kind, sym, cannotHaveLowerBounds,
667
+ isDoConcurrent);
644
668
helper.populateByRefInitAndCleanupRegions ();
645
669
646
670
// Often we load moldArg to check something (e.g. length parameters, shape)
0 commit comments