@@ -497,6 +497,9 @@ class ClauseProcessor {
497
497
bool processDevice (Fortran::lower::StatementContext &stmtCtx,
498
498
mlir::Value &result) const ;
499
499
bool processDeviceType (mlir::omp::DeclareTargetDeviceType &result) const ;
500
+ bool processDistSchedule (Fortran::lower::StatementContext &stmtCtx,
501
+ mlir::UnitAttr &scheduleStatic,
502
+ mlir::Value &chunkSize) const ;
500
503
bool processFinal (Fortran::lower::StatementContext &stmtCtx,
501
504
mlir::Value &result) const ;
502
505
bool processHint (mlir::IntegerAttr &result) const ;
@@ -1335,6 +1338,19 @@ bool ClauseProcessor::processDeviceType(
1335
1338
return false ;
1336
1339
}
1337
1340
1341
+ bool ClauseProcessor::processDistSchedule (
1342
+ Fortran::lower::StatementContext &stmtCtx, mlir::UnitAttr &scheduleStatic,
1343
+ mlir::Value &chunkSize) const {
1344
+ if (auto *distScheduleClause = findUniqueClause<ClauseTy::DistSchedule>()) {
1345
+ scheduleStatic = converter.getFirOpBuilder ().getUnitAttr ();
1346
+ if (const auto *expr = Fortran::semantics::GetExpr (distScheduleClause->v )) {
1347
+ chunkSize = fir::getBase (converter.genExprValue (*expr, stmtCtx));
1348
+ }
1349
+ return true ;
1350
+ }
1351
+ return false ;
1352
+ }
1353
+
1338
1354
bool ClauseProcessor::processFinal (Fortran::lower::StatementContext &stmtCtx,
1339
1355
mlir::Value &result) const {
1340
1356
const Fortran::parser::CharBlock *source = nullptr ;
@@ -2473,6 +2489,27 @@ genTeamsOp(Fortran::lower::AbstractConverter &converter,
2473
2489
reductionDeclSymbols));
2474
2490
}
2475
2491
2492
+ static mlir::omp::DistributeOp
2493
+ genDistributeOp (Fortran::lower::AbstractConverter &converter,
2494
+ Fortran::lower::pft::Evaluation &eval,
2495
+ mlir::Location currentLocation,
2496
+ const Fortran::parser::OmpClauseList &clauseList,
2497
+ bool outerCombined = false ) {
2498
+ Fortran::lower::StatementContext stmtCtx;
2499
+ mlir::UnitAttr scheduleStatic;
2500
+ mlir::Value chunkSize;
2501
+ llvm::SmallVector<mlir::Value> allocateOperands, allocatorOperands;
2502
+
2503
+ ClauseProcessor cp (converter, clauseList);
2504
+ cp.processDistSchedule (stmtCtx, scheduleStatic, chunkSize);
2505
+ cp.processAllocate (allocatorOperands, allocateOperands);
2506
+
2507
+ return genOpWithBody<mlir::omp::DistributeOp>(
2508
+ converter, eval, currentLocation, outerCombined, &clauseList,
2509
+ scheduleStatic, chunkSize, allocateOperands, allocatorOperands,
2510
+ /* order_val=*/ nullptr );
2511
+ }
2512
+
2476
2513
// / Extract the list of function and variable symbols affected by the given
2477
2514
// / 'declare target' directive and return the intended device type for them.
2478
2515
static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo (
@@ -2681,7 +2718,9 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
2681
2718
}
2682
2719
if (llvm::omp::allDistributeSet.test (ompDirective)) {
2683
2720
validDirective = true ;
2684
- TODO (currentLocation, " Distribute construct" );
2721
+ bool outerCombined = llvm::omp::topDistributeSet.test (ompDirective);
2722
+ genDistributeOp (converter, eval, currentLocation, loopOpClauseList,
2723
+ outerCombined);
2685
2724
}
2686
2725
if ((llvm::omp::allParallelSet & llvm::omp::loopConstructSet)
2687
2726
.test (ompDirective)) {
0 commit comments