@@ -110,6 +110,32 @@ static void gatherFuncAndVarSyms(
110
110
}
111
111
}
112
112
113
+ static Fortran::lower::pft::Evaluation *
114
+ getEvalPastCollapse (Fortran::lower::pft::Evaluation &eval, int collapseValue) {
115
+ if (collapseValue == 0 )
116
+ return &eval;
117
+
118
+ Fortran::lower::pft::Evaluation *curEval = &eval.getFirstNestedEvaluation ();
119
+ for (int i = 1 ; i < collapseValue; i++) {
120
+ // The nested evaluations should be DoConstructs (i.e. they should form
121
+ // a loop nest). Each DoConstruct is a tuple <NonLabelDoStmt, Block,
122
+ // EndDoStmt>.
123
+ assert (curEval->isA <Fortran::parser::DoConstruct>());
124
+ curEval = &*std::next (curEval->getNestedEvaluations ().begin ());
125
+ }
126
+ return curEval;
127
+ }
128
+
129
+ static void genNestedEvaluations (Fortran::lower::AbstractConverter &converter,
130
+ Fortran::lower::pft::Evaluation &eval,
131
+ int collapseValue = 0 ) {
132
+ Fortran::lower::pft::Evaluation *curEval =
133
+ getEvalPastCollapse (eval, collapseValue);
134
+
135
+ for (Fortran::lower::pft::Evaluation &e : curEval->getNestedEvaluations ())
136
+ converter.genEval (e);
137
+ }
138
+
113
139
// ===----------------------------------------------------------------------===//
114
140
// DataSharingProcessor
115
141
// ===----------------------------------------------------------------------===//
@@ -2944,7 +2970,7 @@ genOmpFlush(Fortran::lower::AbstractConverter &converter,
2944
2970
2945
2971
static void
2946
2972
genOMP (Fortran::lower::AbstractConverter &converter,
2947
- Fortran::lower::pft::Evaluation &eval,
2973
+ Fortran::lower::SymMap &symTable, Fortran::lower:: pft::Evaluation &eval,
2948
2974
Fortran::semantics::SemanticsContext &semanticsContext,
2949
2975
const Fortran::parser::OpenMPStandaloneConstruct &standaloneConstruct) {
2950
2976
std::visit (
@@ -3025,6 +3051,9 @@ createSimdLoop(Fortran::lower::AbstractConverter &converter,
3025
3051
createBodyOfOp<mlir::omp::SimdLoopOp>(simdLoopOp, converter, loc, eval,
3026
3052
&loopOpClauseList, iv,
3027
3053
/* outer=*/ false , &dsp);
3054
+
3055
+ genNestedEvaluations (converter, eval,
3056
+ Fortran::lower::getCollapseValue (loopOpClauseList));
3028
3057
}
3029
3058
3030
3059
static void createWsLoop (Fortran::lower::AbstractConverter &converter,
@@ -3106,9 +3135,13 @@ static void createWsLoop(Fortran::lower::AbstractConverter &converter,
3106
3135
createBodyOfOp<mlir::omp::WsLoopOp>(wsLoopOp, converter, loc, eval,
3107
3136
&beginClauseList, iv,
3108
3137
/* outer=*/ false , &dsp);
3138
+
3139
+ genNestedEvaluations (converter, eval,
3140
+ Fortran::lower::getCollapseValue (beginClauseList));
3109
3141
}
3110
3142
3111
3143
static void genOMP (Fortran::lower::AbstractConverter &converter,
3144
+ Fortran::lower::SymMap &symTable,
3112
3145
Fortran::lower::pft::Evaluation &eval,
3113
3146
Fortran::semantics::SemanticsContext &semanticsContext,
3114
3147
const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
@@ -3178,11 +3211,12 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
3178
3211
createWsLoop (converter, eval, ompDirective, loopOpClauseList, endClauseList,
3179
3212
currentLocation);
3180
3213
}
3214
+ genOpenMPReduction (converter, loopOpClauseList);
3181
3215
}
3182
3216
3183
3217
static void
3184
3218
genOMP (Fortran::lower::AbstractConverter &converter,
3185
- Fortran::lower::pft::Evaluation &eval,
3219
+ Fortran::lower::SymMap &symTable, Fortran::lower:: pft::Evaluation &eval,
3186
3220
Fortran::semantics::SemanticsContext &semanticsContext,
3187
3221
const Fortran::parser::OpenMPBlockConstruct &blockConstruct) {
3188
3222
const auto &beginBlockDirective =
@@ -3297,11 +3331,14 @@ genOMP(Fortran::lower::AbstractConverter &converter,
3297
3331
break ;
3298
3332
}
3299
3333
}
3334
+
3335
+ genNestedEvaluations (converter, eval);
3336
+ genOpenMPReduction (converter, beginClauseList);
3300
3337
}
3301
3338
3302
3339
static void
3303
3340
genOMP (Fortran::lower::AbstractConverter &converter,
3304
- Fortran::lower::pft::Evaluation &eval,
3341
+ Fortran::lower::SymMap &symTable, Fortran::lower:: pft::Evaluation &eval,
3305
3342
const Fortran::parser::OpenMPCriticalConstruct &criticalConstruct) {
3306
3343
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
3307
3344
mlir::Location currentLocation = converter.getCurrentLocation ();
@@ -3335,11 +3372,12 @@ genOMP(Fortran::lower::AbstractConverter &converter,
3335
3372
}();
3336
3373
createBodyOfOp<mlir::omp::CriticalOp>(criticalOp, converter, currentLocation,
3337
3374
eval);
3375
+ genNestedEvaluations (converter, eval);
3338
3376
}
3339
3377
3340
3378
static void
3341
3379
genOMP (Fortran::lower::AbstractConverter &converter,
3342
- Fortran::lower::pft::Evaluation &eval,
3380
+ Fortran::lower::SymMap &symTable, Fortran::lower:: pft::Evaluation &eval,
3343
3381
const Fortran::parser::OpenMPSectionConstruct §ionConstruct) {
3344
3382
mlir::Location currentLocation = converter.getCurrentLocation ();
3345
3383
const Fortran::parser::OpenMPConstruct *parentOmpConstruct =
@@ -3358,14 +3396,17 @@ genOMP(Fortran::lower::AbstractConverter &converter,
3358
3396
.t );
3359
3397
// Currently only private/firstprivate clause is handled, and
3360
3398
// all privatization is done within `omp.section` operations.
3399
+ symTable.pushScope ();
3361
3400
genOpWithBody<mlir::omp::SectionOp>(converter, eval, currentLocation,
3362
3401
/* outerCombined=*/ false ,
3363
3402
§ionsClauseList);
3403
+ genNestedEvaluations (converter, eval);
3404
+ symTable.popScope ();
3364
3405
}
3365
3406
3366
3407
static void
3367
3408
genOMP (Fortran::lower::AbstractConverter &converter,
3368
- Fortran::lower::pft::Evaluation &eval,
3409
+ Fortran::lower::SymMap &symTable, Fortran::lower:: pft::Evaluation &eval,
3369
3410
const Fortran::parser::OpenMPSectionsConstruct §ionsConstruct) {
3370
3411
mlir::Location currentLocation = converter.getCurrentLocation ();
3371
3412
llvm::SmallVector<mlir::Value> allocateOperands, allocatorOperands;
@@ -3405,11 +3446,13 @@ genOMP(Fortran::lower::AbstractConverter &converter,
3405
3446
/* reduction_vars=*/ mlir::ValueRange (),
3406
3447
/* reductions=*/ nullptr , allocateOperands,
3407
3448
allocatorOperands, nowaitClauseOperand);
3449
+
3450
+ genNestedEvaluations (converter, eval);
3408
3451
}
3409
3452
3410
3453
static void
3411
3454
genOMP (Fortran::lower::AbstractConverter &converter,
3412
- Fortran::lower::pft::Evaluation &eval,
3455
+ Fortran::lower::SymMap &symTable, Fortran::lower:: pft::Evaluation &eval,
3413
3456
const Fortran::parser::OpenMPAtomicConstruct &atomicConstruct) {
3414
3457
std::visit (
3415
3458
Fortran::common::visitors{
@@ -3503,24 +3546,26 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
3503
3546
}
3504
3547
3505
3548
static void genOMP (Fortran::lower::AbstractConverter &converter,
3549
+ Fortran::lower::SymMap &symTable,
3506
3550
Fortran::semantics::SemanticsContext &semanticsContext,
3507
3551
Fortran::lower::pft::Evaluation &eval,
3508
3552
const Fortran::parser::OpenMPConstruct &ompConstruct) {
3509
3553
std::visit (
3510
3554
Fortran::common::visitors{
3511
3555
[&](const Fortran::parser::OpenMPStandaloneConstruct
3512
3556
&standaloneConstruct) {
3513
- genOMP (converter, eval, semanticsContext, standaloneConstruct);
3557
+ genOMP (converter, symTable, eval, semanticsContext,
3558
+ standaloneConstruct);
3514
3559
},
3515
3560
[&](const Fortran::parser::OpenMPSectionsConstruct
3516
3561
§ionsConstruct) {
3517
- genOMP (converter, eval, sectionsConstruct);
3562
+ genOMP (converter, symTable, eval, sectionsConstruct);
3518
3563
},
3519
3564
[&](const Fortran::parser::OpenMPSectionConstruct §ionConstruct) {
3520
- genOMP (converter, eval, sectionConstruct);
3565
+ genOMP (converter, symTable, eval, sectionConstruct);
3521
3566
},
3522
3567
[&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) {
3523
- genOMP (converter, eval, semanticsContext, loopConstruct);
3568
+ genOMP (converter, symTable, eval, semanticsContext, loopConstruct);
3524
3569
},
3525
3570
[&](const Fortran::parser::OpenMPDeclarativeAllocate
3526
3571
&execAllocConstruct) {
@@ -3535,14 +3580,14 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
3535
3580
TODO (converter.getCurrentLocation (), " OpenMPAllocatorsConstruct" );
3536
3581
},
3537
3582
[&](const Fortran::parser::OpenMPBlockConstruct &blockConstruct) {
3538
- genOMP (converter, eval, semanticsContext, blockConstruct);
3583
+ genOMP (converter, symTable, eval, semanticsContext, blockConstruct);
3539
3584
},
3540
3585
[&](const Fortran::parser::OpenMPAtomicConstruct &atomicConstruct) {
3541
- genOMP (converter, eval, atomicConstruct);
3586
+ genOMP (converter, symTable, eval, atomicConstruct);
3542
3587
},
3543
3588
[&](const Fortran::parser::OpenMPCriticalConstruct
3544
3589
&criticalConstruct) {
3545
- genOMP (converter, eval, criticalConstruct);
3590
+ genOMP (converter, symTable, eval, criticalConstruct);
3546
3591
},
3547
3592
},
3548
3593
ompConstruct.u );
@@ -3606,47 +3651,8 @@ void Fortran::lower::genOpenMPConstruct(
3606
3651
Fortran::semantics::SemanticsContext &semanticsContext,
3607
3652
Fortran::lower::pft::Evaluation &eval,
3608
3653
const Fortran::parser::OpenMPConstruct &omp) {
3609
-
3610
3654
symTable.pushScope ();
3611
- genOMP (converter, semanticsContext, eval, omp);
3612
-
3613
- const Fortran::parser::OpenMPLoopConstruct *ompLoop =
3614
- std::get_if<Fortran::parser::OpenMPLoopConstruct>(&omp.u );
3615
- const Fortran::parser::OpenMPBlockConstruct *ompBlock =
3616
- std::get_if<Fortran::parser::OpenMPBlockConstruct>(&omp.u );
3617
-
3618
- // If loop is part of an OpenMP Construct then the OpenMP dialect
3619
- // workshare loop operation has already been created. Only the
3620
- // body needs to be created here and the do_loop can be skipped.
3621
- // Skip the number of collapsed loops, which is 1 when there is a
3622
- // no collapse requested.
3623
-
3624
- Fortran::lower::pft::Evaluation *curEval = &eval;
3625
- const Fortran::parser::OmpClauseList *loopOpClauseList = nullptr ;
3626
- if (ompLoop) {
3627
- loopOpClauseList = &std::get<Fortran::parser::OmpClauseList>(
3628
- std::get<Fortran::parser::OmpBeginLoopDirective>(ompLoop->t ).t );
3629
- int64_t collapseValue = Fortran::lower::getCollapseValue (*loopOpClauseList);
3630
-
3631
- curEval = &curEval->getFirstNestedEvaluation ();
3632
- for (int64_t i = 1 ; i < collapseValue; i++) {
3633
- curEval = &*std::next (curEval->getNestedEvaluations ().begin ());
3634
- }
3635
- }
3636
-
3637
- for (Fortran::lower::pft::Evaluation &e : curEval->getNestedEvaluations ())
3638
- converter.genEval (e);
3639
-
3640
- if (ompLoop) {
3641
- genOpenMPReduction (converter, *loopOpClauseList);
3642
- } else if (ompBlock) {
3643
- const auto &blockStart =
3644
- std::get<Fortran::parser::OmpBeginBlockDirective>(ompBlock->t );
3645
- const auto &blockClauses =
3646
- std::get<Fortran::parser::OmpClauseList>(blockStart.t );
3647
- genOpenMPReduction (converter, blockClauses);
3648
- }
3649
-
3655
+ genOMP (converter, symTable, semanticsContext, eval, omp);
3650
3656
symTable.popScope ();
3651
3657
}
3652
3658
@@ -3655,8 +3661,7 @@ void Fortran::lower::genOpenMPDeclarativeConstruct(
3655
3661
Fortran::lower::pft::Evaluation &eval,
3656
3662
const Fortran::parser::OpenMPDeclarativeConstruct &omp) {
3657
3663
genOMP (converter, eval, omp);
3658
- for (Fortran::lower::pft::Evaluation &e : eval.getNestedEvaluations ())
3659
- converter.genEval (e);
3664
+ genNestedEvaluations (converter, eval);
3660
3665
}
3661
3666
3662
3667
void Fortran::lower::genOpenMPSymbolProperties (
0 commit comments