@@ -565,6 +565,9 @@ class ClauseProcessor {
565
565
bool processDevice (Fortran::lower::StatementContext &stmtCtx,
566
566
mlir::Value &result) const ;
567
567
bool processDeviceType (mlir::omp::DeclareTargetDeviceType &result) const ;
568
+ bool processDistSchedule (Fortran::lower::StatementContext &stmtCtx,
569
+ mlir::UnitAttr &scheduleStatic,
570
+ mlir::Value &chunkSize) const ;
568
571
bool processFinal (Fortran::lower::StatementContext &stmtCtx,
569
572
mlir::Value &result) const ;
570
573
bool processHint (mlir::IntegerAttr &result) const ;
@@ -1490,6 +1493,19 @@ bool ClauseProcessor::processDeviceType(
1490
1493
return false ;
1491
1494
}
1492
1495
1496
+ bool ClauseProcessor::processDistSchedule (
1497
+ Fortran::lower::StatementContext &stmtCtx, mlir::UnitAttr &scheduleStatic,
1498
+ mlir::Value &chunkSize) const {
1499
+ if (auto *distScheduleClause = findUniqueClause<ClauseTy::DistSchedule>()) {
1500
+ scheduleStatic = converter.getFirOpBuilder ().getUnitAttr ();
1501
+ if (const auto *expr = Fortran::semantics::GetExpr (distScheduleClause->v )) {
1502
+ chunkSize = fir::getBase (converter.genExprValue (*expr, stmtCtx));
1503
+ }
1504
+ return true ;
1505
+ }
1506
+ return false ;
1507
+ }
1508
+
1493
1509
bool ClauseProcessor::processFinal (Fortran::lower::StatementContext &stmtCtx,
1494
1510
mlir::Value &result) const {
1495
1511
const Fortran::parser::CharBlock *source = nullptr ;
@@ -2997,6 +3013,27 @@ genTeamsOp(Fortran::lower::AbstractConverter &converter,
2997
3013
reductionDeclSymbols));
2998
3014
}
2999
3015
3016
+ static mlir::omp::DistributeOp
3017
+ genDistributeOp (Fortran::lower::AbstractConverter &converter,
3018
+ Fortran::lower::pft::Evaluation &eval, bool genNested,
3019
+ mlir::Location currentLocation,
3020
+ const Fortran::parser::OmpClauseList &clauseList,
3021
+ bool outerCombined = false ) {
3022
+ Fortran::lower::StatementContext stmtCtx;
3023
+ mlir::UnitAttr scheduleStatic;
3024
+ mlir::Value chunkSize;
3025
+ llvm::SmallVector<mlir::Value> allocateOperands, allocatorOperands;
3026
+
3027
+ ClauseProcessor cp (converter, clauseList);
3028
+ cp.processDistSchedule (stmtCtx, scheduleStatic, chunkSize);
3029
+ cp.processAllocate (allocatorOperands, allocateOperands);
3030
+
3031
+ return genOpWithBody<mlir::omp::DistributeOp>(
3032
+ converter, eval, genNested, currentLocation, outerCombined, &clauseList,
3033
+ scheduleStatic, chunkSize, allocateOperands, allocatorOperands,
3034
+ /* order_val=*/ nullptr );
3035
+ }
3036
+
3000
3037
// / Extract the list of function and variable symbols affected by the given
3001
3038
// / 'declare target' directive and return the intended device type for them.
3002
3039
static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo (
@@ -3358,7 +3395,9 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
3358
3395
}
3359
3396
if (llvm::omp::allDistributeSet.test (ompDirective)) {
3360
3397
validDirective = true ;
3361
- TODO (currentLocation, " Distribute construct" );
3398
+ bool outerCombined = llvm::omp::topDistributeSet.test (ompDirective);
3399
+ genDistributeOp (converter, eval, /* genNested=*/ false , currentLocation,
3400
+ loopOpClauseList, outerCombined);
3362
3401
}
3363
3402
if ((llvm::omp::allParallelSet & llvm::omp::loopConstructSet)
3364
3403
.test (ompDirective)) {
0 commit comments