Changeset View
Changeset View
Standalone View
Standalone View
flang/lib/Lower/OpenMP.cpp
Show First 20 Lines • Show All 698 Lines • ▼ Show 20 Lines | static void genOMP(Fortran::lower::AbstractConverter &converter, | ||||
Fortran::lower::pft::Evaluation &eval, | Fortran::lower::pft::Evaluation &eval, | ||||
const Fortran::parser::OpenMPLoopConstruct &loopConstruct) { | const Fortran::parser::OpenMPLoopConstruct &loopConstruct) { | ||||
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); | fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); | ||||
mlir::Location currentLocation = converter.getCurrentLocation(); | mlir::Location currentLocation = converter.getCurrentLocation(); | ||||
llvm::SmallVector<mlir::Value> lowerBound, upperBound, step, linearVars, | llvm::SmallVector<mlir::Value> lowerBound, upperBound, step, linearVars, | ||||
linearStepVars, reductionVars; | linearStepVars, reductionVars; | ||||
mlir::Value scheduleChunkClauseOperand; | mlir::Value scheduleChunkClauseOperand; | ||||
mlir::Attribute scheduleClauseOperand, collapseClauseOperand, | mlir::Attribute scheduleClauseOperand, noWaitClauseOperand, | ||||
noWaitClauseOperand, orderedClauseOperand, orderClauseOperand; | orderedClauseOperand, orderClauseOperand; | ||||
const auto &loopOpClauseList = std::get<Fortran::parser::OmpClauseList>( | const auto &loopOpClauseList = std::get<Fortran::parser::OmpClauseList>( | ||||
std::get<Fortran::parser::OmpBeginLoopDirective>(loopConstruct.t).t); | std::get<Fortran::parser::OmpBeginLoopDirective>(loopConstruct.t).t); | ||||
const auto ompDirective = | const auto ompDirective = | ||||
std::get<Fortran::parser::OmpLoopDirective>( | std::get<Fortran::parser::OmpLoopDirective>( | ||||
std::get<Fortran::parser::OmpBeginLoopDirective>(loopConstruct.t).t) | std::get<Fortran::parser::OmpBeginLoopDirective>(loopConstruct.t).t) | ||||
.v; | .v; | ||||
if (llvm::omp::OMPD_parallel_do == ompDirective) { | if (llvm::omp::OMPD_parallel_do == ompDirective) { | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | static void genOMP(Fortran::lower::AbstractConverter &converter, | ||||
// 1. linear | // 1. linear | ||||
// 2. order | // 2. order | ||||
auto wsLoopOp = firOpBuilder.create<mlir::omp::WsLoopOp>( | auto wsLoopOp = firOpBuilder.create<mlir::omp::WsLoopOp>( | ||||
currentLocation, lowerBound, upperBound, step, linearVars, linearStepVars, | currentLocation, lowerBound, upperBound, step, linearVars, linearStepVars, | ||||
reductionVars, /*reductions=*/nullptr, | reductionVars, /*reductions=*/nullptr, | ||||
scheduleClauseOperand.dyn_cast_or_null<omp::ClauseScheduleKindAttr>(), | scheduleClauseOperand.dyn_cast_or_null<omp::ClauseScheduleKindAttr>(), | ||||
scheduleChunkClauseOperand, /*schedule_modifiers=*/nullptr, | scheduleChunkClauseOperand, /*schedule_modifiers=*/nullptr, | ||||
/*simd_modifier=*/nullptr, | /*simd_modifier=*/nullptr, | ||||
collapseClauseOperand.dyn_cast_or_null<IntegerAttr>(), | |||||
noWaitClauseOperand.dyn_cast_or_null<UnitAttr>(), | noWaitClauseOperand.dyn_cast_or_null<UnitAttr>(), | ||||
orderedClauseOperand.dyn_cast_or_null<IntegerAttr>(), | orderedClauseOperand.dyn_cast_or_null<IntegerAttr>(), | ||||
orderClauseOperand.dyn_cast_or_null<omp::ClauseOrderKindAttr>(), | orderClauseOperand.dyn_cast_or_null<omp::ClauseOrderKindAttr>(), | ||||
/*inclusive=*/firOpBuilder.getUnitAttr()); | /*inclusive=*/firOpBuilder.getUnitAttr()); | ||||
// Handle attribute based clauses. | // Handle attribute based clauses. | ||||
for (const Fortran::parser::OmpClause &clause : loopOpClauseList.v) { | for (const Fortran::parser::OmpClause &clause : loopOpClauseList.v) { | ||||
if (const auto &orderedClause = | if (const auto &orderedClause = | ||||
std::get_if<Fortran::parser::OmpClause::Ordered>(&clause.u)) { | std::get_if<Fortran::parser::OmpClause::Ordered>(&clause.u)) { | ||||
if (orderedClause->v.has_value()) { | if (orderedClause->v.has_value()) { | ||||
const auto *expr = Fortran::semantics::GetExpr(orderedClause->v); | const auto *expr = Fortran::semantics::GetExpr(orderedClause->v); | ||||
const std::optional<std::int64_t> orderedClauseValue = | const std::optional<std::int64_t> orderedClauseValue = | ||||
Fortran::evaluate::ToInt64(*expr); | Fortran::evaluate::ToInt64(*expr); | ||||
wsLoopOp.ordered_valAttr( | wsLoopOp.ordered_valAttr( | ||||
firOpBuilder.getI64IntegerAttr(*orderedClauseValue)); | firOpBuilder.getI64IntegerAttr(*orderedClauseValue)); | ||||
} else { | } else { | ||||
wsLoopOp.ordered_valAttr(firOpBuilder.getI64IntegerAttr(0)); | wsLoopOp.ordered_valAttr(firOpBuilder.getI64IntegerAttr(0)); | ||||
} | } | ||||
} else if (const auto &collapseClause = | |||||
std::get_if<Fortran::parser::OmpClause::Collapse>( | |||||
&clause.u)) { | |||||
const auto *expr = Fortran::semantics::GetExpr(collapseClause->v); | |||||
const std::optional<std::int64_t> collapseValue = | |||||
Fortran::evaluate::ToInt64(*expr); | |||||
wsLoopOp.collapse_valAttr(firOpBuilder.getI64IntegerAttr(*collapseValue)); | |||||
} else if (const auto &scheduleClause = | } else if (const auto &scheduleClause = | ||||
std::get_if<Fortran::parser::OmpClause::Schedule>( | std::get_if<Fortran::parser::OmpClause::Schedule>( | ||||
&clause.u)) { | &clause.u)) { | ||||
mlir::MLIRContext *context = firOpBuilder.getContext(); | mlir::MLIRContext *context = firOpBuilder.getContext(); | ||||
const auto &scheduleType = scheduleClause->v; | const auto &scheduleType = scheduleClause->v; | ||||
const auto &scheduleKind = | const auto &scheduleKind = | ||||
std::get<Fortran::parser::OmpScheduleClause::ScheduleType>( | std::get<Fortran::parser::OmpScheduleClause::ScheduleType>( | ||||
scheduleType.t); | scheduleType.t); | ||||
▲ Show 20 Lines • Show All 403 Lines • Show Last 20 Lines |