|
18 | 18 | #include "flang/Lower/ConvertVariable.h"
|
19 | 19 | #include "flang/Lower/PFTBuilder.h"
|
20 | 20 | #include "flang/Lower/StatementContext.h"
|
| 21 | +#include "flang/Lower/SymbolMap.h" |
21 | 22 | #include "flang/Optimizer/Builder/BoxValue.h"
|
22 | 23 | #include "flang/Optimizer/Builder/FIRBuilder.h"
|
23 | 24 | #include "flang/Optimizer/Builder/Todo.h"
|
@@ -3384,27 +3385,12 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
|
3384 | 3385 | }
|
3385 | 3386 | }
|
3386 | 3387 |
|
3387 |
| -//===----------------------------------------------------------------------===// |
3388 |
| -// Public functions |
3389 |
| -//===----------------------------------------------------------------------===// |
3390 |
| - |
3391 |
| -void Fortran::lower::genOpenMPTerminator(fir::FirOpBuilder &builder, |
3392 |
| - mlir::Operation *op, |
3393 |
| - mlir::Location loc) { |
3394 |
| - if (mlir::isa<mlir::omp::WsLoopOp, mlir::omp::ReductionDeclareOp, |
3395 |
| - mlir::omp::AtomicUpdateOp, mlir::omp::SimdLoopOp>(op)) |
3396 |
| - builder.create<mlir::omp::YieldOp>(loc); |
3397 |
| - else |
3398 |
| - builder.create<mlir::omp::TerminatorOp>(loc); |
3399 |
| -} |
3400 |
| - |
3401 |
| -void Fortran::lower::genOpenMPConstruct( |
3402 |
| - Fortran::lower::AbstractConverter &converter, |
3403 |
| - Fortran::semantics::SemanticsContext &semanticsContext, |
3404 |
| - Fortran::lower::pft::Evaluation &eval, |
3405 |
| - const Fortran::parser::OpenMPConstruct &ompConstruct) { |
| 3388 | +static void genOMP(Fortran::lower::AbstractConverter &converter, |
| 3389 | + Fortran::semantics::SemanticsContext &semanticsContext, |
| 3390 | + Fortran::lower::pft::Evaluation &eval, |
| 3391 | + const Fortran::parser::OpenMPConstruct &ompConstruct) { |
3406 | 3392 | std::visit(
|
3407 |
| - common::visitors{ |
| 3393 | + Fortran::common::visitors{ |
3408 | 3394 | [&](const Fortran::parser::OpenMPStandaloneConstruct
|
3409 | 3395 | &standaloneConstruct) {
|
3410 | 3396 | genOMP(converter, eval, semanticsContext, standaloneConstruct);
|
@@ -3445,12 +3431,12 @@ void Fortran::lower::genOpenMPConstruct(
|
3445 | 3431 | ompConstruct.u);
|
3446 | 3432 | }
|
3447 | 3433 |
|
3448 |
| -void Fortran::lower::genOpenMPDeclarativeConstruct( |
3449 |
| - Fortran::lower::AbstractConverter &converter, |
3450 |
| - Fortran::lower::pft::Evaluation &eval, |
3451 |
| - const Fortran::parser::OpenMPDeclarativeConstruct &ompDeclConstruct) { |
| 3434 | +static void |
| 3435 | +genOMP(Fortran::lower::AbstractConverter &converter, |
| 3436 | + Fortran::lower::pft::Evaluation &eval, |
| 3437 | + const Fortran::parser::OpenMPDeclarativeConstruct &ompDeclConstruct) { |
3452 | 3438 | std::visit(
|
3453 |
| - common::visitors{ |
| 3439 | + Fortran::common::visitors{ |
3454 | 3440 | [&](const Fortran::parser::OpenMPDeclarativeAllocate
|
3455 | 3441 | &declarativeAllocate) {
|
3456 | 3442 | TODO(converter.getCurrentLocation(), "OpenMPDeclarativeAllocate");
|
@@ -3483,6 +3469,79 @@ void Fortran::lower::genOpenMPDeclarativeConstruct(
|
3483 | 3469 | ompDeclConstruct.u);
|
3484 | 3470 | }
|
3485 | 3471 |
|
| 3472 | +//===----------------------------------------------------------------------===// |
| 3473 | +// Public functions |
| 3474 | +//===----------------------------------------------------------------------===// |
| 3475 | + |
| 3476 | +void Fortran::lower::genOpenMPTerminator(fir::FirOpBuilder &builder, |
| 3477 | + mlir::Operation *op, |
| 3478 | + mlir::Location loc) { |
| 3479 | + if (mlir::isa<mlir::omp::WsLoopOp, mlir::omp::ReductionDeclareOp, |
| 3480 | + mlir::omp::AtomicUpdateOp, mlir::omp::SimdLoopOp>(op)) |
| 3481 | + builder.create<mlir::omp::YieldOp>(loc); |
| 3482 | + else |
| 3483 | + builder.create<mlir::omp::TerminatorOp>(loc); |
| 3484 | +} |
| 3485 | + |
| 3486 | +void Fortran::lower::genOpenMPConstruct( |
| 3487 | + Fortran::lower::AbstractConverter &converter, |
| 3488 | + Fortran::lower::SymMap &symTable, |
| 3489 | + Fortran::semantics::SemanticsContext &semanticsContext, |
| 3490 | + Fortran::lower::pft::Evaluation &eval, |
| 3491 | + const Fortran::parser::OpenMPConstruct &omp) { |
| 3492 | + |
| 3493 | + symTable.pushScope(); |
| 3494 | + genOMP(converter, semanticsContext, eval, omp); |
| 3495 | + |
| 3496 | + const Fortran::parser::OpenMPLoopConstruct *ompLoop = |
| 3497 | + std::get_if<Fortran::parser::OpenMPLoopConstruct>(&omp.u); |
| 3498 | + const Fortran::parser::OpenMPBlockConstruct *ompBlock = |
| 3499 | + std::get_if<Fortran::parser::OpenMPBlockConstruct>(&omp.u); |
| 3500 | + |
| 3501 | + // If loop is part of an OpenMP Construct then the OpenMP dialect |
| 3502 | + // workshare loop operation has already been created. Only the |
| 3503 | + // body needs to be created here and the do_loop can be skipped. |
| 3504 | + // Skip the number of collapsed loops, which is 1 when there is a |
| 3505 | + // no collapse requested. |
| 3506 | + |
| 3507 | + Fortran::lower::pft::Evaluation *curEval = &eval; |
| 3508 | + const Fortran::parser::OmpClauseList *loopOpClauseList = nullptr; |
| 3509 | + if (ompLoop) { |
| 3510 | + loopOpClauseList = &std::get<Fortran::parser::OmpClauseList>( |
| 3511 | + std::get<Fortran::parser::OmpBeginLoopDirective>(ompLoop->t).t); |
| 3512 | + int64_t collapseValue = Fortran::lower::getCollapseValue(*loopOpClauseList); |
| 3513 | + |
| 3514 | + curEval = &curEval->getFirstNestedEvaluation(); |
| 3515 | + for (int64_t i = 1; i < collapseValue; i++) { |
| 3516 | + curEval = &*std::next(curEval->getNestedEvaluations().begin()); |
| 3517 | + } |
| 3518 | + } |
| 3519 | + |
| 3520 | + for (Fortran::lower::pft::Evaluation &e : curEval->getNestedEvaluations()) |
| 3521 | + converter.genEval(e); |
| 3522 | + |
| 3523 | + if (ompLoop) { |
| 3524 | + genOpenMPReduction(converter, *loopOpClauseList); |
| 3525 | + } else if (ompBlock) { |
| 3526 | + const auto &blockStart = |
| 3527 | + std::get<Fortran::parser::OmpBeginBlockDirective>(ompBlock->t); |
| 3528 | + const auto &blockClauses = |
| 3529 | + std::get<Fortran::parser::OmpClauseList>(blockStart.t); |
| 3530 | + genOpenMPReduction(converter, blockClauses); |
| 3531 | + } |
| 3532 | + |
| 3533 | + symTable.popScope(); |
| 3534 | +} |
| 3535 | + |
| 3536 | +void Fortran::lower::genOpenMPDeclarativeConstruct( |
| 3537 | + Fortran::lower::AbstractConverter &converter, |
| 3538 | + Fortran::lower::pft::Evaluation &eval, |
| 3539 | + const Fortran::parser::OpenMPDeclarativeConstruct &omp) { |
| 3540 | + genOMP(converter, eval, omp); |
| 3541 | + for (Fortran::lower::pft::Evaluation &e : eval.getNestedEvaluations()) |
| 3542 | + converter.genEval(e); |
| 3543 | +} |
| 3544 | + |
3486 | 3545 | int64_t Fortran::lower::getCollapseValue(
|
3487 | 3546 | const Fortran::parser::OmpClauseList &clauseList) {
|
3488 | 3547 | for (const Fortran::parser::OmpClause &clause : clauseList.v) {
|
|
0 commit comments