@@ -2250,6 +2250,17 @@ createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
2250
2250
return storeOp;
2251
2251
}
2252
2252
2253
+ struct CreateBodyOfOpInfo {
2254
+ Fortran::lower::AbstractConverter &converter;
2255
+ mlir::Location &loc;
2256
+ Fortran::lower::pft::Evaluation &eval;
2257
+ bool genNested = true ;
2258
+ const Fortran::parser::OmpClauseList *clauses = nullptr ;
2259
+ const llvm::SmallVector<const Fortran::semantics::Symbol *> &args = {};
2260
+ bool outerCombined = false ;
2261
+ DataSharingProcessor *dsp = nullptr ;
2262
+ };
2263
+
2253
2264
// / Create the body (block) for an OpenMP Operation.
2254
2265
// /
2255
2266
// / \param [in] op - the operation the body belongs to.
@@ -2263,13 +2274,8 @@ createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
2263
2274
// / \param [in] outerCombined - is this an outer operation - prevents
2264
2275
// / privatization.
2265
2276
template <typename Op>
2266
- static void createBodyOfOp (
2267
- Op &op, Fortran::lower::AbstractConverter &converter, mlir::Location &loc,
2268
- Fortran::lower::pft::Evaluation &eval, bool genNested,
2269
- const Fortran::parser::OmpClauseList *clauses = nullptr ,
2270
- const llvm::SmallVector<const Fortran::semantics::Symbol *> &args = {},
2271
- bool outerCombined = false , DataSharingProcessor *dsp = nullptr ) {
2272
- fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
2277
+ static void createBodyOfOp (Op &op, CreateBodyOfOpInfo info) {
2278
+ fir::FirOpBuilder &firOpBuilder = info.converter .getFirOpBuilder ();
2273
2279
2274
2280
auto insertMarker = [](fir::FirOpBuilder &builder) {
2275
2281
mlir::Value undef = builder.create <fir::UndefOp>(builder.getUnknownLoc (),
@@ -2281,22 +2287,22 @@ static void createBodyOfOp(
2281
2287
// argument. Also update the symbol's address with the mlir argument value.
2282
2288
// e.g. For loops the argument is the induction variable. And all further
2283
2289
// uses of the induction variable should use this mlir value.
2284
- if (args.size ()) {
2290
+ if (info. args .size ()) {
2285
2291
std::size_t loopVarTypeSize = 0 ;
2286
- for (const Fortran::semantics::Symbol *arg : args)
2292
+ for (const Fortran::semantics::Symbol *arg : info. args )
2287
2293
loopVarTypeSize = std::max (loopVarTypeSize, arg->GetUltimate ().size ());
2288
- mlir::Type loopVarType = getLoopVarType (converter, loopVarTypeSize);
2289
- llvm::SmallVector<mlir::Type> tiv (args.size (), loopVarType);
2290
- llvm::SmallVector<mlir::Location> locs (args.size (), loc);
2294
+ mlir::Type loopVarType = getLoopVarType (info. converter , loopVarTypeSize);
2295
+ llvm::SmallVector<mlir::Type> tiv (info. args .size (), loopVarType);
2296
+ llvm::SmallVector<mlir::Location> locs (info. args .size (), info. loc );
2291
2297
firOpBuilder.createBlock (&op.getRegion (), {}, tiv, locs);
2292
2298
// The argument is not currently in memory, so make a temporary for the
2293
2299
// argument, and store it there, then bind that location to the argument.
2294
2300
mlir::Operation *storeOp = nullptr ;
2295
- for (auto [argIndex, argSymbol] : llvm::enumerate (args)) {
2301
+ for (auto [argIndex, argSymbol] : llvm::enumerate (info. args )) {
2296
2302
mlir::Value indexVal =
2297
2303
fir::getBase (op.getRegion ().front ().getArgument (argIndex));
2298
- storeOp =
2299
- createAndSetPrivatizedLoopVar (converter, loc, indexVal, argSymbol);
2304
+ storeOp = createAndSetPrivatizedLoopVar (info. converter , info. loc ,
2305
+ indexVal, argSymbol);
2300
2306
}
2301
2307
firOpBuilder.setInsertionPointAfter (storeOp);
2302
2308
} else {
@@ -2308,44 +2314,44 @@ static void createBodyOfOp(
2308
2314
2309
2315
// If it is an unstructured region and is not the outer region of a combined
2310
2316
// construct, create empty blocks for all evaluations.
2311
- if (eval.lowerAsUnstructured () && !outerCombined)
2317
+ if (info. eval .lowerAsUnstructured () && !info. outerCombined )
2312
2318
Fortran::lower::createEmptyRegionBlocks<mlir::omp::TerminatorOp,
2313
2319
mlir::omp::YieldOp>(
2314
- firOpBuilder, eval.getNestedEvaluations ());
2320
+ firOpBuilder, info. eval .getNestedEvaluations ());
2315
2321
2316
2322
// Start with privatization, so that the lowering of the nested
2317
2323
// code will use the right symbols.
2318
2324
constexpr bool isLoop = std::is_same_v<Op, mlir::omp::WsLoopOp> ||
2319
2325
std::is_same_v<Op, mlir::omp::SimdLoopOp>;
2320
- bool privatize = clauses && !outerCombined;
2326
+ bool privatize = info. clauses && !info. outerCombined ;
2321
2327
2322
2328
firOpBuilder.setInsertionPoint (marker);
2323
2329
std::optional<DataSharingProcessor> tempDsp;
2324
2330
if (privatize) {
2325
- if (!dsp) {
2326
- tempDsp.emplace (converter, *clauses, eval);
2331
+ if (!info. dsp ) {
2332
+ tempDsp.emplace (info. converter , *info. clauses , info. eval );
2327
2333
tempDsp->processStep1 ();
2328
2334
}
2329
2335
}
2330
2336
2331
2337
if constexpr (std::is_same_v<Op, mlir::omp::ParallelOp>) {
2332
- threadPrivatizeVars (converter, eval);
2333
- if (clauses) {
2338
+ threadPrivatizeVars (info. converter , info. eval );
2339
+ if (info. clauses ) {
2334
2340
firOpBuilder.setInsertionPoint (marker);
2335
- ClauseProcessor (converter, *clauses).processCopyin ();
2341
+ ClauseProcessor (info. converter , *info. clauses ).processCopyin ();
2336
2342
}
2337
2343
}
2338
2344
2339
- if (genNested) {
2345
+ if (info. genNested ) {
2340
2346
// genFIR(Evaluation&) tries to patch up unterminated blocks, causing
2341
2347
// a lot of complications for our approach if the terminator generation
2342
2348
// is delayed past this point. Insert a temporary terminator here, then
2343
2349
// delete it.
2344
2350
firOpBuilder.setInsertionPointToEnd (&op.getRegion ().back ());
2345
- auto *temp = Fortran::lower::genOpenMPTerminator (firOpBuilder,
2346
- op.getOperation (), loc);
2351
+ auto *temp = Fortran::lower::genOpenMPTerminator (
2352
+ firOpBuilder, op.getOperation (), info. loc );
2347
2353
firOpBuilder.setInsertionPointAfter (marker);
2348
- genNestedEvaluations (converter, eval);
2354
+ genNestedEvaluations (info. converter , info. eval );
2349
2355
temp->erase ();
2350
2356
}
2351
2357
@@ -2380,28 +2386,28 @@ static void createBodyOfOp(
2380
2386
mlir::Block *exit = firOpBuilder.createBlock (®ion);
2381
2387
for (mlir::Block *b : exits) {
2382
2388
firOpBuilder.setInsertionPointToEnd (b);
2383
- firOpBuilder.create <mlir::cf::BranchOp>(loc, exit );
2389
+ firOpBuilder.create <mlir::cf::BranchOp>(info. loc , exit );
2384
2390
}
2385
2391
return exit ;
2386
2392
};
2387
2393
2388
2394
if (auto *exitBlock = getUniqueExit (op.getRegion ())) {
2389
2395
firOpBuilder.setInsertionPointToEnd (exitBlock);
2390
- auto *term = Fortran::lower::genOpenMPTerminator (firOpBuilder,
2391
- op.getOperation (), loc);
2396
+ auto *term = Fortran::lower::genOpenMPTerminator (
2397
+ firOpBuilder, op.getOperation (), info. loc );
2392
2398
// Only insert lastprivate code when there actually is an exit block.
2393
2399
// Such a block may not exist if the nested code produced an infinite
2394
2400
// loop (this may not make sense in production code, but a user could
2395
2401
// write that and we should handle it).
2396
2402
firOpBuilder.setInsertionPoint (term);
2397
2403
if (privatize) {
2398
- if (!dsp) {
2404
+ if (!info. dsp ) {
2399
2405
assert (tempDsp.has_value ());
2400
2406
tempDsp->processStep2 (op, isLoop);
2401
2407
} else {
2402
- if (isLoop && args.size () > 0 )
2403
- dsp->setLoopIV (converter.getSymbolAddress (*args[0 ]));
2404
- dsp->processStep2 (op, isLoop);
2408
+ if (isLoop && info. args .size () > 0 )
2409
+ info. dsp ->setLoopIV (info. converter .getSymbolAddress (*info. args [0 ]));
2410
+ info. dsp ->processStep2 (op, isLoop);
2405
2411
}
2406
2412
}
2407
2413
}
@@ -2475,39 +2481,43 @@ static void genBodyOfTargetDataOp(
2475
2481
genNestedEvaluations (converter, eval);
2476
2482
}
2477
2483
2484
+ struct GenOpWithBodyInfo {
2485
+ Fortran::lower::AbstractConverter &converter;
2486
+ Fortran::lower::pft::Evaluation &eval;
2487
+ bool genNested = false ;
2488
+ mlir::Location currentLocation;
2489
+ bool outerCombined = false ;
2490
+ const Fortran::parser::OmpClauseList *clauseList = nullptr ;
2491
+ };
2492
+
2478
2493
template <typename OpTy, typename ... Args>
2479
- static OpTy genOpWithBody (Fortran::lower::AbstractConverter &converter,
2480
- Fortran::lower::pft::Evaluation &eval, bool genNested,
2481
- mlir::Location currentLocation, bool outerCombined,
2482
- const Fortran::parser::OmpClauseList *clauseList,
2483
- Args &&...args) {
2484
- auto op = converter.getFirOpBuilder ().create <OpTy>(
2485
- currentLocation, std::forward<Args>(args)...);
2486
- createBodyOfOp<OpTy>(op, converter, currentLocation, eval, genNested,
2487
- clauseList,
2488
- /* args=*/ {}, outerCombined);
2494
+ static OpTy genOpWithBody (GenOpWithBodyInfo info, Args &&...args) {
2495
+ auto op = info.converter .getFirOpBuilder ().create <OpTy>(
2496
+ info.currentLocation , std::forward<Args>(args)...);
2497
+ createBodyOfOp<OpTy>(
2498
+ op, {info.converter , info.currentLocation , info.eval , info.genNested ,
2499
+ info.clauseList ,
2500
+ /* args*/ llvm::SmallVector<const Fortran::semantics::Symbol *>{},
2501
+ info.outerCombined });
2489
2502
return op;
2490
2503
}
2491
2504
2492
2505
static mlir::omp::MasterOp
2493
2506
genMasterOp (Fortran::lower::AbstractConverter &converter,
2494
2507
Fortran::lower::pft::Evaluation &eval, bool genNested,
2495
2508
mlir::Location currentLocation) {
2496
- return genOpWithBody<mlir::omp::MasterOp>(converter, eval, genNested,
2497
- currentLocation,
2498
- /* outerCombined=*/ false ,
2499
- /* clauseList=*/ nullptr ,
2500
- /* resultTypes=*/ mlir::TypeRange ());
2509
+ return genOpWithBody<mlir::omp::MasterOp>(
2510
+ {converter, eval, genNested, currentLocation},
2511
+ /* resultTypes=*/ mlir::TypeRange ());
2501
2512
}
2502
2513
2503
2514
static mlir::omp::OrderedRegionOp
2504
2515
genOrderedRegionOp (Fortran::lower::AbstractConverter &converter,
2505
2516
Fortran::lower::pft::Evaluation &eval, bool genNested,
2506
2517
mlir::Location currentLocation) {
2507
2518
return genOpWithBody<mlir::omp::OrderedRegionOp>(
2508
- converter, eval, genNested, currentLocation,
2509
- /* outerCombined=*/ false ,
2510
- /* clauseList=*/ nullptr , /* simd=*/ false );
2519
+ {converter, eval, genNested, currentLocation},
2520
+ /* simd=*/ false );
2511
2521
}
2512
2522
2513
2523
static mlir::omp::ParallelOp
@@ -2534,7 +2544,7 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
2534
2544
cp.processReduction (currentLocation, reductionVars, reductionDeclSymbols);
2535
2545
2536
2546
return genOpWithBody<mlir::omp::ParallelOp>(
2537
- converter, eval, genNested, currentLocation, outerCombined, &clauseList,
2547
+ { converter, eval, genNested, currentLocation, outerCombined, &clauseList} ,
2538
2548
/* resultTypes=*/ mlir::TypeRange (), ifClauseOperand,
2539
2549
numThreadsClauseOperand, allocateOperands, allocatorOperands,
2540
2550
reductionVars,
@@ -2553,8 +2563,8 @@ genSectionOp(Fortran::lower::AbstractConverter &converter,
2553
2563
// Currently only private/firstprivate clause is handled, and
2554
2564
// all privatization is done within `omp.section` operations.
2555
2565
return genOpWithBody<mlir::omp::SectionOp>(
2556
- converter, eval, genNested, currentLocation,
2557
- /* outerCombined=*/ false , §ionsClauseList);
2566
+ { converter, eval, genNested, currentLocation,
2567
+ /* outerCombined=*/ false , §ionsClauseList} );
2558
2568
}
2559
2569
2560
2570
static mlir::omp::SingleOp
@@ -2574,9 +2584,9 @@ genSingleOp(Fortran::lower::AbstractConverter &converter,
2574
2584
ClauseProcessor (converter, endClauseList).processNowait (nowaitAttr);
2575
2585
2576
2586
return genOpWithBody<mlir::omp::SingleOp>(
2577
- converter, eval, genNested, currentLocation,
2578
- /* outerCombined=*/ false , &beginClauseList, allocateOperands ,
2579
- allocatorOperands, nowaitAttr);
2587
+ { converter, eval, genNested, currentLocation,
2588
+ /* outerCombined=*/ false , &beginClauseList} ,
2589
+ allocateOperands, allocatorOperands, nowaitAttr);
2580
2590
}
2581
2591
2582
2592
static mlir::omp::TaskOp
@@ -2607,9 +2617,9 @@ genTaskOp(Fortran::lower::AbstractConverter &converter,
2607
2617
currentLocation, llvm::omp::Directive::OMPD_task);
2608
2618
2609
2619
return genOpWithBody<mlir::omp::TaskOp>(
2610
- converter, eval, genNested, currentLocation,
2611
- /* outerCombined=*/ false , &clauseList, ifClauseOperand, finalClauseOperand ,
2612
- untiedAttr, mergeableAttr,
2620
+ { converter, eval, genNested, currentLocation,
2621
+ /* outerCombined=*/ false , &clauseList} ,
2622
+ ifClauseOperand, finalClauseOperand, untiedAttr, mergeableAttr,
2613
2623
/* in_reduction_vars=*/ mlir::ValueRange (),
2614
2624
/* in_reductions=*/ nullptr , priorityClauseOperand,
2615
2625
dependTypeOperands.empty ()
@@ -2630,8 +2640,8 @@ genTaskGroupOp(Fortran::lower::AbstractConverter &converter,
2630
2640
cp.processTODO <Fortran::parser::OmpClause::TaskReduction>(
2631
2641
currentLocation, llvm::omp::Directive::OMPD_taskgroup);
2632
2642
return genOpWithBody<mlir::omp::TaskGroupOp>(
2633
- converter, eval, genNested, currentLocation,
2634
- /* outerCombined=*/ false , &clauseList,
2643
+ { converter, eval, genNested, currentLocation,
2644
+ /* outerCombined=*/ false , &clauseList} ,
2635
2645
/* task_reduction_vars=*/ mlir::ValueRange (),
2636
2646
/* task_reductions=*/ nullptr , allocateOperands, allocatorOperands);
2637
2647
}
@@ -3014,7 +3024,7 @@ genTeamsOp(Fortran::lower::AbstractConverter &converter,
3014
3024
currentLocation, llvm::omp::Directive::OMPD_teams);
3015
3025
3016
3026
return genOpWithBody<mlir::omp::TeamsOp>(
3017
- converter, eval, genNested, currentLocation, outerCombined, &clauseList,
3027
+ { converter, eval, genNested, currentLocation, outerCombined, &clauseList} ,
3018
3028
/* num_teams_lower=*/ nullptr , numTeamsClauseOperand, ifClauseOperand,
3019
3029
threadLimitClauseOperand, allocateOperands, allocatorOperands,
3020
3030
reductionVars,
@@ -3258,9 +3268,10 @@ createSimdLoop(Fortran::lower::AbstractConverter &converter,
3258
3268
3259
3269
auto *nestedEval = getCollapsedLoopEval (
3260
3270
eval, Fortran::lower::getCollapseValue (loopOpClauseList));
3261
- createBodyOfOp<mlir::omp::SimdLoopOp>(simdLoopOp, converter, loc, *nestedEval,
3262
- /* genNested=*/ true , &loopOpClauseList,
3263
- iv, /* outer=*/ false , &dsp);
3271
+ createBodyOfOp<mlir::omp::SimdLoopOp>(
3272
+ simdLoopOp, {converter, loc, *nestedEval,
3273
+ /* genNested=*/ true , &loopOpClauseList, iv,
3274
+ /* outerCombined=*/ false , &dsp});
3264
3275
}
3265
3276
3266
3277
static void createWsLoop (Fortran::lower::AbstractConverter &converter,
@@ -3333,9 +3344,10 @@ static void createWsLoop(Fortran::lower::AbstractConverter &converter,
3333
3344
3334
3345
auto *nestedEval = getCollapsedLoopEval (
3335
3346
eval, Fortran::lower::getCollapseValue (beginClauseList));
3336
- createBodyOfOp<mlir::omp::WsLoopOp>(wsLoopOp, converter, loc, *nestedEval,
3337
- /* genNested=*/ true , &beginClauseList, iv,
3338
- /* outer=*/ false , &dsp);
3347
+ createBodyOfOp<mlir::omp::WsLoopOp>(wsLoopOp,
3348
+ {converter, loc, *nestedEval,
3349
+ /* genNested=*/ true , &beginClauseList, iv,
3350
+ /* outerCombined=*/ false , &dsp});
3339
3351
}
3340
3352
3341
3353
static void createSimdWsLoop (
@@ -3616,8 +3628,8 @@ genOMP(Fortran::lower::AbstractConverter &converter,
3616
3628
currentLocation, mlir::FlatSymbolRefAttr::get (firOpBuilder.getContext (),
3617
3629
global.getSymName ()));
3618
3630
}();
3619
- createBodyOfOp<mlir::omp::CriticalOp>(criticalOp, converter, currentLocation,
3620
- eval, /* genNested= */ true );
3631
+ createBodyOfOp<mlir::omp::CriticalOp>(criticalOp,
3632
+ {converter, currentLocation, eval} );
3621
3633
}
3622
3634
3623
3635
static void
@@ -3659,10 +3671,8 @@ genOMP(Fortran::lower::AbstractConverter &converter,
3659
3671
}
3660
3672
3661
3673
// SECTIONS construct
3662
- genOpWithBody<mlir::omp::SectionsOp>(converter, eval,
3663
- /* genNested=*/ false , currentLocation,
3664
- /* outerCombined=*/ false ,
3665
- /* clauseList=*/ nullptr ,
3674
+ genOpWithBody<mlir::omp::SectionsOp>({converter, eval,
3675
+ /* genNested=*/ false , currentLocation},
3666
3676
/* reduction_vars=*/ mlir::ValueRange (),
3667
3677
/* reductions=*/ nullptr , allocateOperands,
3668
3678
allocatorOperands, nowaitClauseOperand);
0 commit comments