@@ -214,24 +214,6 @@ static void threadPrivatizeVars(Fortran::lower::AbstractConverter &converter,
214214 firOpBuilder.restoreInsertionPoint (insPt);
215215}
216216
217- static mlir::Type getLoopVarType (Fortran::lower::AbstractConverter &converter,
218- std::size_t loopVarTypeSize) {
219- // OpenMP runtime requires 32-bit or 64-bit loop variables.
220- loopVarTypeSize = loopVarTypeSize * 8 ;
221- if (loopVarTypeSize < 32 ) {
222- loopVarTypeSize = 32 ;
223- } else if (loopVarTypeSize > 64 ) {
224- loopVarTypeSize = 64 ;
225- mlir::emitWarning (converter.getCurrentLocation (),
226- " OpenMP loop iteration variable cannot have more than 64 "
227- " bits size and will be narrowed into 64 bits." );
228- }
229- assert ((loopVarTypeSize == 32 || loopVarTypeSize == 64 ) &&
230- " OpenMP loop iteration variable size must be transformed into 32-bit "
231- " or 64-bit" );
232- return converter.getFirOpBuilder ().getIntegerType (loopVarTypeSize);
233- }
234-
235217static mlir::Operation *
236218createAndSetPrivatizedLoopVar (Fortran::lower::AbstractConverter &converter,
237219 mlir::Location loc, mlir::Value indexVal,
@@ -568,6 +550,7 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
568550 mlir::omp::ClauseProcBindKindAttr procBindKindAttr;
569551 llvm::SmallVector<mlir::Value> allocateOperands, allocatorOperands,
570552 reductionVars;
553+ llvm::SmallVector<mlir::Type> reductionTypes;
571554 llvm::SmallVector<mlir::Attribute> reductionDeclSymbols;
572555 llvm::SmallVector<const Fortran::semantics::Symbol *> reductionSymbols;
573556
@@ -578,13 +561,8 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
578561 cp.processDefault ();
579562 cp.processAllocate (allocatorOperands, allocateOperands);
580563 if (!outerCombined)
581- cp.processReduction (currentLocation, reductionVars, reductionDeclSymbols,
582- &reductionSymbols);
583-
584- llvm::SmallVector<mlir::Type> reductionTypes;
585- reductionTypes.reserve (reductionVars.size ());
586- llvm::transform (reductionVars, std::back_inserter (reductionTypes),
587- [](mlir::Value v) { return v.getType (); });
564+ cp.processReduction (currentLocation, reductionVars, reductionTypes,
565+ reductionDeclSymbols, &reductionSymbols);
588566
589567 auto reductionCallback = [&](mlir::Operation *op) {
590568 llvm::SmallVector<mlir::Location> locs (reductionVars.size (),
@@ -1468,25 +1446,6 @@ genOMP(Fortran::lower::AbstractConverter &converter,
14681446 standaloneConstruct.u );
14691447}
14701448
1471- static void convertLoopBounds (Fortran::lower::AbstractConverter &converter,
1472- mlir::Location loc,
1473- llvm::SmallVectorImpl<mlir::Value> &lowerBound,
1474- llvm::SmallVectorImpl<mlir::Value> &upperBound,
1475- llvm::SmallVectorImpl<mlir::Value> &step,
1476- std::size_t loopVarTypeSize) {
1477- fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
1478- // The types of lower bound, upper bound, and step are converted into the
1479- // type of the loop variable if necessary.
1480- mlir::Type loopVarType = getLoopVarType (converter, loopVarTypeSize);
1481- for (unsigned it = 0 ; it < (unsigned )lowerBound.size (); it++) {
1482- lowerBound[it] =
1483- firOpBuilder.createConvert (loc, loopVarType, lowerBound[it]);
1484- upperBound[it] =
1485- firOpBuilder.createConvert (loc, loopVarType, upperBound[it]);
1486- step[it] = firOpBuilder.createConvert (loc, loopVarType, step[it]);
1487- }
1488- }
1489-
14901449static llvm::SmallVector<const Fortran::semantics::Symbol *>
14911450genLoopVars (mlir::Operation *op, Fortran::lower::AbstractConverter &converter,
14921451 mlir::Location &loc,
@@ -1520,7 +1479,7 @@ genLoopAndReductionVars(
15201479 mlir::Location &loc,
15211480 llvm::ArrayRef<const Fortran::semantics::Symbol *> loopArgs,
15221481 llvm::ArrayRef<const Fortran::semantics::Symbol *> reductionArgs,
1523- llvm::SmallVectorImpl <mlir::Type> & reductionTypes) {
1482+ llvm::ArrayRef <mlir::Type> reductionTypes) {
15241483 fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
15251484
15261485 llvm::SmallVector<mlir::Type> blockArgTypes;
@@ -1582,16 +1541,15 @@ createSimdLoop(Fortran::lower::AbstractConverter &converter,
15821541 llvm::SmallVector<mlir::Value> lowerBound, upperBound, step, reductionVars;
15831542 llvm::SmallVector<mlir::Value> alignedVars, nontemporalVars;
15841543 llvm::SmallVector<const Fortran::semantics::Symbol *> iv;
1544+ llvm::SmallVector<mlir::Type> reductionTypes;
15851545 llvm::SmallVector<mlir::Attribute> reductionDeclSymbols;
15861546 mlir::omp::ClauseOrderKindAttr orderClauseOperand;
15871547 mlir::IntegerAttr simdlenClauseOperand, safelenClauseOperand;
1588- std::size_t loopVarTypeSize;
15891548
15901549 ClauseProcessor cp (converter, semaCtx, loopOpClauseList);
1591- cp.processCollapse (loc, eval, lowerBound, upperBound, step, iv,
1592- loopVarTypeSize);
1550+ cp.processCollapse (loc, eval, lowerBound, upperBound, step, iv);
15931551 cp.processScheduleChunk (stmtCtx, scheduleChunkClauseOperand);
1594- cp.processReduction (loc, reductionVars, reductionDeclSymbols);
1552+ cp.processReduction (loc, reductionVars, reductionTypes, reductionDeclSymbols);
15951553 cp.processIf (clause::If::DirectiveNameModifier::Simd, ifClauseOperand);
15961554 cp.processSimdlen (simdlenClauseOperand);
15971555 cp.processSafelen (safelenClauseOperand);
@@ -1601,9 +1559,6 @@ createSimdLoop(Fortran::lower::AbstractConverter &converter,
16011559 Fortran::parser::OmpClause::Nontemporal,
16021560 Fortran::parser::OmpClause::Order>(loc, ompDirective);
16031561
1604- convertLoopBounds (converter, loc, lowerBound, upperBound, step,
1605- loopVarTypeSize);
1606-
16071562 mlir::TypeRange resultType;
16081563 auto simdLoopOp = firOpBuilder.create <mlir::omp::SimdLoopOp>(
16091564 loc, resultType, lowerBound, upperBound, step, alignedVars,
@@ -1641,27 +1596,23 @@ static void createWsLoop(Fortran::lower::AbstractConverter &converter,
16411596 llvm::SmallVector<mlir::Value> lowerBound, upperBound, step, reductionVars;
16421597 llvm::SmallVector<mlir::Value> linearVars, linearStepVars;
16431598 llvm::SmallVector<const Fortran::semantics::Symbol *> iv;
1599+ llvm::SmallVector<mlir::Type> reductionTypes;
16441600 llvm::SmallVector<mlir::Attribute> reductionDeclSymbols;
16451601 llvm::SmallVector<const Fortran::semantics::Symbol *> reductionSymbols;
16461602 mlir::omp::ClauseOrderKindAttr orderClauseOperand;
16471603 mlir::omp::ClauseScheduleKindAttr scheduleValClauseOperand;
16481604 mlir::UnitAttr nowaitClauseOperand, byrefOperand, scheduleSimdClauseOperand;
16491605 mlir::IntegerAttr orderedClauseOperand;
16501606 mlir::omp::ScheduleModifierAttr scheduleModClauseOperand;
1651- std::size_t loopVarTypeSize;
16521607
16531608 ClauseProcessor cp (converter, semaCtx, beginClauseList);
1654- cp.processCollapse (loc, eval, lowerBound, upperBound, step, iv,
1655- loopVarTypeSize);
1609+ cp.processCollapse (loc, eval, lowerBound, upperBound, step, iv);
16561610 cp.processScheduleChunk (stmtCtx, scheduleChunkClauseOperand);
1657- cp.processReduction (loc, reductionVars, reductionDeclSymbols,
1611+ cp.processReduction (loc, reductionVars, reductionTypes, reductionDeclSymbols,
16581612 &reductionSymbols);
16591613 cp.processTODO <Fortran::parser::OmpClause::Linear,
16601614 Fortran::parser::OmpClause::Order>(loc, ompDirective);
16611615
1662- convertLoopBounds (converter, loc, lowerBound, upperBound, step,
1663- loopVarTypeSize);
1664-
16651616 if (ReductionProcessor::doReductionByRef (reductionVars))
16661617 byrefOperand = firOpBuilder.getUnitAttr ();
16671618
@@ -1702,11 +1653,6 @@ static void createWsLoop(Fortran::lower::AbstractConverter &converter,
17021653 auto *nestedEval = getCollapsedLoopEval (
17031654 eval, Fortran::lower::getCollapseValue (beginClauseList));
17041655
1705- llvm::SmallVector<mlir::Type> reductionTypes;
1706- reductionTypes.reserve (reductionVars.size ());
1707- llvm::transform (reductionVars, std::back_inserter (reductionTypes),
1708- [](mlir::Value v) { return v.getType (); });
1709-
17101656 auto ivCallback = [&](mlir::Operation *op) {
17111657 return genLoopAndReductionVars (op, converter, loc, iv, reductionSymbols,
17121658 reductionTypes);
0 commit comments