@@ -1667,15 +1667,17 @@ static void privatizeIv(Fortran::lower::AbstractConverter &converter,
1667
1667
ivPrivate.push_back (privateValue);
1668
1668
}
1669
1669
1670
- static mlir::acc::LoopOp
1671
- createLoopOp (Fortran::lower::AbstractConverter &converter,
1672
- mlir::Location currentLocation,
1673
- Fortran::semantics::SemanticsContext &semanticsContext,
1674
- Fortran::lower::StatementContext &stmtCtx,
1675
- const Fortran::parser::DoConstruct &outerDoConstruct,
1676
- Fortran::lower::pft::Evaluation &eval,
1677
- const Fortran::parser::AccClauseList &accClauseList,
1678
- bool needEarlyReturnHandling = false ) {
1670
+ static mlir::acc::LoopOp createLoopOp (
1671
+ Fortran::lower::AbstractConverter &converter,
1672
+ mlir::Location currentLocation,
1673
+ Fortran::semantics::SemanticsContext &semanticsContext,
1674
+ Fortran::lower::StatementContext &stmtCtx,
1675
+ const Fortran::parser::DoConstruct &outerDoConstruct,
1676
+ Fortran::lower::pft::Evaluation &eval,
1677
+ const Fortran::parser::AccClauseList &accClauseList,
1678
+ std::optional<mlir::acc::CombinedConstructsType> combinedConstructs =
1679
+ std::nullopt,
1680
+ bool needEarlyReturnHandling = false ) {
1679
1681
fir::FirOpBuilder &builder = converter.getFirOpBuilder ();
1680
1682
llvm::SmallVector<mlir::Value> tileOperands, privateOperands, ivPrivate,
1681
1683
reductionOperands, cacheOperands, vectorOperands, workerNumOperands,
@@ -2015,6 +2017,10 @@ createLoopOp(Fortran::lower::AbstractConverter &converter,
2015
2017
if (!collapseDeviceTypes.empty ())
2016
2018
loopOp.setCollapseDeviceTypeAttr (builder.getArrayAttr (collapseDeviceTypes));
2017
2019
2020
+ if (combinedConstructs)
2021
+ loopOp.setCombinedAttr (mlir::acc::CombinedConstructsTypeAttr::get (
2022
+ builder.getContext (), *combinedConstructs));
2023
+
2018
2024
return loopOp;
2019
2025
}
2020
2026
@@ -2060,7 +2066,7 @@ genACC(Fortran::lower::AbstractConverter &converter,
2060
2066
std::get<std::optional<Fortran::parser::DoConstruct>>(loopConstruct.t );
2061
2067
auto loopOp = createLoopOp (converter, currentLocation, semanticsContext,
2062
2068
stmtCtx, *outerDoConstruct, eval, accClauseList,
2063
- needEarlyExitHandling);
2069
+ /* combinedConstructs= */ {}, needEarlyExitHandling);
2064
2070
if (needEarlyExitHandling)
2065
2071
return loopOp.getResult (0 );
2066
2072
@@ -2092,14 +2098,14 @@ static void genDataOperandOperationsWithModifier(
2092
2098
}
2093
2099
2094
2100
template <typename Op>
2095
- static Op
2096
- createComputeOp ( Fortran::lower::AbstractConverter &converter,
2097
- mlir::Location currentLocation,
2098
- Fortran::lower::pft::Evaluation &eval ,
2099
- Fortran::semantics::SemanticsContext &semanticsContext ,
2100
- Fortran::lower::StatementContext &stmtCtx ,
2101
- const Fortran::parser::AccClauseList &accClauseList,
2102
- bool outerCombined = false ) {
2101
+ static Op createComputeOp (
2102
+ Fortran::lower::AbstractConverter &converter,
2103
+ mlir::Location currentLocation, Fortran::lower::pft::Evaluation &eval ,
2104
+ Fortran::semantics::SemanticsContext &semanticsContext ,
2105
+ Fortran::lower::StatementContext &stmtCtx ,
2106
+ const Fortran::parser::AccClauseList &accClauseList ,
2107
+ std::optional<mlir::acc::CombinedConstructsType> combinedConstructs =
2108
+ std::nullopt ) {
2103
2109
2104
2110
// Parallel operation operands
2105
2111
mlir::Value ifCond;
@@ -2292,7 +2298,7 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
2292
2298
} else if (const auto *privateClause =
2293
2299
std::get_if<Fortran::parser::AccClause::Private>(
2294
2300
&clause.u )) {
2295
- if (!outerCombined )
2301
+ if (!combinedConstructs )
2296
2302
genPrivatizations<mlir::acc::PrivateRecipeOp>(
2297
2303
privateClause->v , converter, semanticsContext, stmtCtx,
2298
2304
privateOperands, privatizations);
@@ -2310,7 +2316,7 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
2310
2316
// combined - delay it to the loop. However, a reduction clause on a
2311
2317
// combined construct implies a copy clause so issue an implicit copy
2312
2318
// instead.
2313
- if (!outerCombined ) {
2319
+ if (!combinedConstructs ) {
2314
2320
genReductions (reductionClause->v , converter, semanticsContext, stmtCtx,
2315
2321
reductionOperands, reductionRecipes);
2316
2322
} else {
@@ -2362,11 +2368,11 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
2362
2368
if constexpr (std::is_same_v<Op, mlir::acc::KernelsOp>)
2363
2369
computeOp = createRegionOp<Op, mlir::acc::TerminatorOp>(
2364
2370
builder, currentLocation, currentLocation, eval, operands,
2365
- operandSegments, outerCombined);
2371
+ operandSegments, /* outerCombined= */ combinedConstructs. has_value () );
2366
2372
else
2367
2373
computeOp = createRegionOp<Op, mlir::acc::YieldOp>(
2368
2374
builder, currentLocation, currentLocation, eval, operands,
2369
- operandSegments, outerCombined);
2375
+ operandSegments, /* outerCombined= */ combinedConstructs. has_value () );
2370
2376
2371
2377
if (addSelfAttr)
2372
2378
computeOp.setSelfAttrAttr (builder.getUnitAttr ());
@@ -2419,6 +2425,9 @@ createComputeOp(Fortran::lower::AbstractConverter &converter,
2419
2425
mlir::ArrayAttr::get (builder.getContext (), firstPrivatizations));
2420
2426
}
2421
2427
2428
+ if (combinedConstructs)
2429
+ computeOp.setCombinedAttr (builder.getUnitAttr ());
2430
+
2422
2431
auto insPt = builder.saveInsertionPoint ();
2423
2432
builder.setInsertionPointAfter (computeOp);
2424
2433
@@ -2734,21 +2743,24 @@ genACC(Fortran::lower::AbstractConverter &converter,
2734
2743
if (combinedDirective.v == llvm::acc::ACCD_kernels_loop) {
2735
2744
createComputeOp<mlir::acc::KernelsOp>(
2736
2745
converter, currentLocation, eval, semanticsContext, stmtCtx,
2737
- accClauseList, /* outerCombined= */ true );
2746
+ accClauseList, mlir::acc::CombinedConstructsType::KernelsLoop );
2738
2747
createLoopOp (converter, currentLocation, semanticsContext, stmtCtx,
2739
- *outerDoConstruct, eval, accClauseList);
2748
+ *outerDoConstruct, eval, accClauseList,
2749
+ mlir::acc::CombinedConstructsType::KernelsLoop);
2740
2750
} else if (combinedDirective.v == llvm::acc::ACCD_parallel_loop) {
2741
2751
createComputeOp<mlir::acc::ParallelOp>(
2742
2752
converter, currentLocation, eval, semanticsContext, stmtCtx,
2743
- accClauseList, /* outerCombined= */ true );
2753
+ accClauseList, mlir::acc::CombinedConstructsType::ParallelLoop );
2744
2754
createLoopOp (converter, currentLocation, semanticsContext, stmtCtx,
2745
- *outerDoConstruct, eval, accClauseList);
2755
+ *outerDoConstruct, eval, accClauseList,
2756
+ mlir::acc::CombinedConstructsType::ParallelLoop);
2746
2757
} else if (combinedDirective.v == llvm::acc::ACCD_serial_loop) {
2747
- createComputeOp<mlir::acc::SerialOp>(converter, currentLocation, eval,
2748
- semanticsContext, stmtCtx,
2749
- accClauseList, /* outerCombined= */ true );
2758
+ createComputeOp<mlir::acc::SerialOp>(
2759
+ converter, currentLocation, eval, semanticsContext, stmtCtx,
2760
+ accClauseList, mlir::acc::CombinedConstructsType::SerialLoop );
2750
2761
createLoopOp (converter, currentLocation, semanticsContext, stmtCtx,
2751
- *outerDoConstruct, eval, accClauseList);
2762
+ *outerDoConstruct, eval, accClauseList,
2763
+ mlir::acc::CombinedConstructsType::SerialLoop);
2752
2764
} else {
2753
2765
llvm::report_fatal_error (" Unknown combined construct encountered" );
2754
2766
}
0 commit comments