Skip to content

Commit 9f80444

Browse files
committed
Revert "[Flang][OpenMP][Lower] NFC: Move clause processing helpers into the ClauseProcessor (#85258)"
Reverting due to failing gfortran test. This reverts commit 2f2f16f.
1 parent 4b10d1f commit 9f80444

File tree

5 files changed

+74
-66
lines changed

5 files changed

+74
-66
lines changed

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,25 +208,6 @@ addUseDeviceClause(Fortran::lower::AbstractConverter &converter,
208208
useDeviceSymbols.push_back(object.id());
209209
}
210210

211-
static void convertLoopBounds(Fortran::lower::AbstractConverter &converter,
212-
mlir::Location loc,
213-
llvm::SmallVectorImpl<mlir::Value> &lowerBound,
214-
llvm::SmallVectorImpl<mlir::Value> &upperBound,
215-
llvm::SmallVectorImpl<mlir::Value> &step,
216-
std::size_t loopVarTypeSize) {
217-
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
218-
// The types of lower bound, upper bound, and step are converted into the
219-
// type of the loop variable if necessary.
220-
mlir::Type loopVarType = getLoopVarType(converter, loopVarTypeSize);
221-
for (unsigned it = 0; it < (unsigned)lowerBound.size(); it++) {
222-
lowerBound[it] =
223-
firOpBuilder.createConvert(loc, loopVarType, lowerBound[it]);
224-
upperBound[it] =
225-
firOpBuilder.createConvert(loc, loopVarType, upperBound[it]);
226-
step[it] = firOpBuilder.createConvert(loc, loopVarType, step[it]);
227-
}
228-
}
229-
230211
//===----------------------------------------------------------------------===//
231212
// ClauseProcessor unique clauses
232213
//===----------------------------------------------------------------------===//
@@ -236,7 +217,8 @@ bool ClauseProcessor::processCollapse(
236217
llvm::SmallVectorImpl<mlir::Value> &lowerBound,
237218
llvm::SmallVectorImpl<mlir::Value> &upperBound,
238219
llvm::SmallVectorImpl<mlir::Value> &step,
239-
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *> &iv) const {
220+
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *> &iv,
221+
std::size_t &loopVarTypeSize) const {
240222
bool found = false;
241223
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
242224

@@ -254,7 +236,7 @@ bool ClauseProcessor::processCollapse(
254236
found = true;
255237
}
256238

257-
std::size_t loopVarTypeSize = 0;
239+
loopVarTypeSize = 0;
258240
do {
259241
Fortran::lower::pft::Evaluation *doLoop =
260242
&doConstructEval->getFirstNestedEvaluation();
@@ -285,9 +267,6 @@ bool ClauseProcessor::processCollapse(
285267
&*std::next(doConstructEval->getNestedEvaluations().begin());
286268
} while (collapseValue > 0);
287269

288-
convertLoopBounds(converter, currentLocation, lowerBound, upperBound, step,
289-
loopVarTypeSize);
290-
291270
return found;
292271
}
293272

@@ -928,7 +907,6 @@ bool ClauseProcessor::processMap(
928907
bool ClauseProcessor::processReduction(
929908
mlir::Location currentLocation,
930909
llvm::SmallVectorImpl<mlir::Value> &reductionVars,
931-
llvm::SmallVectorImpl<mlir::Type> &reductionTypes,
932910
llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
933911
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *> *reductionSymbols)
934912
const {
@@ -938,9 +916,6 @@ bool ClauseProcessor::processReduction(
938916
ReductionProcessor rp;
939917
rp.addReductionDecl(currentLocation, converter, clause, reductionVars,
940918
reductionDeclSymbols, reductionSymbols);
941-
reductionTypes.reserve(reductionVars.size());
942-
llvm::transform(reductionVars, std::back_inserter(reductionTypes),
943-
[](mlir::Value v) { return v.getType(); });
944919
});
945920
}
946921

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ class ClauseProcessor {
5656
clauses(makeList(clauses, semaCtx)) {}
5757

5858
// 'Unique' clauses: They can appear at most once in the clause list.
59-
bool processCollapse(
60-
mlir::Location currentLocation, Fortran::lower::pft::Evaluation &eval,
61-
llvm::SmallVectorImpl<mlir::Value> &lowerBound,
62-
llvm::SmallVectorImpl<mlir::Value> &upperBound,
63-
llvm::SmallVectorImpl<mlir::Value> &step,
64-
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *> &iv) const;
59+
bool
60+
processCollapse(mlir::Location currentLocation,
61+
Fortran::lower::pft::Evaluation &eval,
62+
llvm::SmallVectorImpl<mlir::Value> &lowerBound,
63+
llvm::SmallVectorImpl<mlir::Value> &upperBound,
64+
llvm::SmallVectorImpl<mlir::Value> &step,
65+
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *> &iv,
66+
std::size_t &loopVarTypeSize) const;
6567
bool processDefault() const;
6668
bool processDevice(Fortran::lower::StatementContext &stmtCtx,
6769
mlir::Value &result) const;
@@ -124,7 +126,6 @@ class ClauseProcessor {
124126
bool
125127
processReduction(mlir::Location currentLocation,
126128
llvm::SmallVectorImpl<mlir::Value> &reductionVars,
127-
llvm::SmallVectorImpl<mlir::Type> &reductionTypes,
128129
llvm::SmallVectorImpl<mlir::Attribute> &reductionDeclSymbols,
129130
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *>
130131
*reductionSymbols = nullptr) const;

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,24 @@ 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+
217235
static mlir::Operation *
218236
createAndSetPrivatizedLoopVar(Fortran::lower::AbstractConverter &converter,
219237
mlir::Location loc, mlir::Value indexVal,
@@ -550,7 +568,6 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
550568
mlir::omp::ClauseProcBindKindAttr procBindKindAttr;
551569
llvm::SmallVector<mlir::Value> allocateOperands, allocatorOperands,
552570
reductionVars;
553-
llvm::SmallVector<mlir::Type> reductionTypes;
554571
llvm::SmallVector<mlir::Attribute> reductionDeclSymbols;
555572
llvm::SmallVector<const Fortran::semantics::Symbol *> reductionSymbols;
556573

@@ -561,8 +578,13 @@ genParallelOp(Fortran::lower::AbstractConverter &converter,
561578
cp.processDefault();
562579
cp.processAllocate(allocatorOperands, allocateOperands);
563580
if (!outerCombined)
564-
cp.processReduction(currentLocation, reductionVars, reductionTypes,
565-
reductionDeclSymbols, &reductionSymbols);
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(); });
566588

567589
auto reductionCallback = [&](mlir::Operation *op) {
568590
llvm::SmallVector<mlir::Location> locs(reductionVars.size(),
@@ -1446,6 +1468,25 @@ genOMP(Fortran::lower::AbstractConverter &converter,
14461468
standaloneConstruct.u);
14471469
}
14481470

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+
14491490
static llvm::SmallVector<const Fortran::semantics::Symbol *>
14501491
genLoopVars(mlir::Operation *op, Fortran::lower::AbstractConverter &converter,
14511492
mlir::Location &loc,
@@ -1541,15 +1582,16 @@ createSimdLoop(Fortran::lower::AbstractConverter &converter,
15411582
llvm::SmallVector<mlir::Value> lowerBound, upperBound, step, reductionVars;
15421583
llvm::SmallVector<mlir::Value> alignedVars, nontemporalVars;
15431584
llvm::SmallVector<const Fortran::semantics::Symbol *> iv;
1544-
llvm::SmallVector<mlir::Type> reductionTypes;
15451585
llvm::SmallVector<mlir::Attribute> reductionDeclSymbols;
15461586
mlir::omp::ClauseOrderKindAttr orderClauseOperand;
15471587
mlir::IntegerAttr simdlenClauseOperand, safelenClauseOperand;
1588+
std::size_t loopVarTypeSize;
15481589

15491590
ClauseProcessor cp(converter, semaCtx, loopOpClauseList);
1550-
cp.processCollapse(loc, eval, lowerBound, upperBound, step, iv);
1591+
cp.processCollapse(loc, eval, lowerBound, upperBound, step, iv,
1592+
loopVarTypeSize);
15511593
cp.processScheduleChunk(stmtCtx, scheduleChunkClauseOperand);
1552-
cp.processReduction(loc, reductionVars, reductionTypes, reductionDeclSymbols);
1594+
cp.processReduction(loc, reductionVars, reductionDeclSymbols);
15531595
cp.processIf(clause::If::DirectiveNameModifier::Simd, ifClauseOperand);
15541596
cp.processSimdlen(simdlenClauseOperand);
15551597
cp.processSafelen(safelenClauseOperand);
@@ -1559,6 +1601,9 @@ createSimdLoop(Fortran::lower::AbstractConverter &converter,
15591601
Fortran::parser::OmpClause::Nontemporal,
15601602
Fortran::parser::OmpClause::Order>(loc, ompDirective);
15611603

1604+
convertLoopBounds(converter, loc, lowerBound, upperBound, step,
1605+
loopVarTypeSize);
1606+
15621607
mlir::TypeRange resultType;
15631608
auto simdLoopOp = firOpBuilder.create<mlir::omp::SimdLoopOp>(
15641609
loc, resultType, lowerBound, upperBound, step, alignedVars,
@@ -1596,23 +1641,27 @@ static void createWsLoop(Fortran::lower::AbstractConverter &converter,
15961641
llvm::SmallVector<mlir::Value> lowerBound, upperBound, step, reductionVars;
15971642
llvm::SmallVector<mlir::Value> linearVars, linearStepVars;
15981643
llvm::SmallVector<const Fortran::semantics::Symbol *> iv;
1599-
llvm::SmallVector<mlir::Type> reductionTypes;
16001644
llvm::SmallVector<mlir::Attribute> reductionDeclSymbols;
16011645
llvm::SmallVector<const Fortran::semantics::Symbol *> reductionSymbols;
16021646
mlir::omp::ClauseOrderKindAttr orderClauseOperand;
16031647
mlir::omp::ClauseScheduleKindAttr scheduleValClauseOperand;
16041648
mlir::UnitAttr nowaitClauseOperand, byrefOperand, scheduleSimdClauseOperand;
16051649
mlir::IntegerAttr orderedClauseOperand;
16061650
mlir::omp::ScheduleModifierAttr scheduleModClauseOperand;
1651+
std::size_t loopVarTypeSize;
16071652

16081653
ClauseProcessor cp(converter, semaCtx, beginClauseList);
1609-
cp.processCollapse(loc, eval, lowerBound, upperBound, step, iv);
1654+
cp.processCollapse(loc, eval, lowerBound, upperBound, step, iv,
1655+
loopVarTypeSize);
16101656
cp.processScheduleChunk(stmtCtx, scheduleChunkClauseOperand);
1611-
cp.processReduction(loc, reductionVars, reductionTypes, reductionDeclSymbols,
1657+
cp.processReduction(loc, reductionVars, reductionDeclSymbols,
16121658
&reductionSymbols);
16131659
cp.processTODO<Fortran::parser::OmpClause::Linear,
16141660
Fortran::parser::OmpClause::Order>(loc, ompDirective);
16151661

1662+
convertLoopBounds(converter, loc, lowerBound, upperBound, step,
1663+
loopVarTypeSize);
1664+
16161665
if (ReductionProcessor::doReductionByRef(reductionVars))
16171666
byrefOperand = firOpBuilder.getUnitAttr();
16181667

@@ -1653,6 +1702,11 @@ static void createWsLoop(Fortran::lower::AbstractConverter &converter,
16531702
auto *nestedEval = getCollapsedLoopEval(
16541703
eval, Fortran::lower::getCollapseValue(beginClauseList));
16551704

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+
16561710
auto ivCallback = [&](mlir::Operation *op) {
16571711
return genLoopAndReductionVars(op, converter, loc, iv, reductionSymbols,
16581712
reductionTypes);

flang/lib/Lower/OpenMP/Utils.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include <flang/Lower/AbstractConverter.h>
1717
#include <flang/Lower/ConvertType.h>
18-
#include <flang/Optimizer/Builder/FIRBuilder.h>
1918
#include <flang/Parser/parse-tree.h>
2019
#include <flang/Parser/tools.h>
2120
#include <flang/Semantics/tools.h>
@@ -71,24 +70,6 @@ void genObjectList2(const Fortran::parser::OmpObjectList &objectList,
7170
}
7271
}
7372

74-
mlir::Type getLoopVarType(Fortran::lower::AbstractConverter &converter,
75-
std::size_t loopVarTypeSize) {
76-
// OpenMP runtime requires 32-bit or 64-bit loop variables.
77-
loopVarTypeSize = loopVarTypeSize * 8;
78-
if (loopVarTypeSize < 32) {
79-
loopVarTypeSize = 32;
80-
} else if (loopVarTypeSize > 64) {
81-
loopVarTypeSize = 64;
82-
mlir::emitWarning(converter.getCurrentLocation(),
83-
"OpenMP loop iteration variable cannot have more than 64 "
84-
"bits size and will be narrowed into 64 bits.");
85-
}
86-
assert((loopVarTypeSize == 32 || loopVarTypeSize == 64) &&
87-
"OpenMP loop iteration variable size must be transformed into 32-bit "
88-
"or 64-bit");
89-
return converter.getFirOpBuilder().getIntegerType(loopVarTypeSize);
90-
}
91-
9273
void gatherFuncAndVarSyms(
9374
const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
9475
llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause) {

flang/lib/Lower/OpenMP/Utils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
5151
mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy,
5252
bool isVal = false);
5353

54-
mlir::Type getLoopVarType(Fortran::lower::AbstractConverter &converter,
55-
std::size_t loopVarTypeSize);
56-
5754
void gatherFuncAndVarSyms(
5855
const ObjectList &objects, mlir::omp::DeclareTargetCaptureClause clause,
5956
llvm::SmallVectorImpl<DeclareTargetCapturePair> &symbolAndClause);

0 commit comments

Comments
 (0)