Skip to content

Commit 400c32c

Browse files
authored
[flang][OpenMP] Use llvm::enumerate in few places, NFC (#76095)
Use `llvm::enumerate` instead of iterating over a range and keeping a separate counter.
1 parent 1f3d70a commit 400c32c

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

flang/lib/Lower/OpenMP.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
3131
#include "mlir/Dialect/SCF/IR/SCF.h"
3232
#include "mlir/Transforms/RegionUtils.h"
33+
#include "llvm/ADT/STLExtras.h"
3334
#include "llvm/Frontend/OpenMP/OMPConstants.h"
3435
#include "llvm/Support/CommandLine.h"
3536

@@ -2122,14 +2123,13 @@ static void createBodyOfOp(
21222123
llvm::SmallVector<mlir::Type> tiv(args.size(), loopVarType);
21232124
llvm::SmallVector<mlir::Location> locs(args.size(), loc);
21242125
firOpBuilder.createBlock(&op.getRegion(), {}, tiv, locs);
2125-
int argIndex = 0;
21262126
// The argument is not currently in memory, so make a temporary for the
21272127
// argument, and store it there, then bind that location to the argument.
2128-
for (const Fortran::semantics::Symbol *arg : args) {
2128+
for (auto [argIndex, argSymbol] : llvm::enumerate(args)) {
21292129
mlir::Value indexVal =
21302130
fir::getBase(op.getRegion().front().getArgument(argIndex));
2131-
storeOp = createAndSetPrivatizedLoopVar(converter, loc, indexVal, arg);
2132-
argIndex++;
2131+
storeOp =
2132+
createAndSetPrivatizedLoopVar(converter, loc, indexVal, argSymbol);
21332133
}
21342134
} else {
21352135
firOpBuilder.createBlock(&op.getRegion());
@@ -2190,18 +2190,17 @@ static void genBodyOfTargetDataOp(
21902190

21912191
firOpBuilder.createBlock(&region, {}, useDeviceTypes, useDeviceLocs);
21922192

2193-
unsigned argIndex = 0;
2194-
for (const Fortran::semantics::Symbol *sym : useDeviceSymbols) {
2193+
for (auto [argIndex, argSymbol] : llvm::enumerate(useDeviceSymbols)) {
21952194
const mlir::BlockArgument &arg = region.front().getArgument(argIndex);
2196-
fir::ExtendedValue extVal = converter.getSymbolExtendedValue(*sym);
2195+
fir::ExtendedValue extVal = converter.getSymbolExtendedValue(*argSymbol);
21972196
if (auto refType = arg.getType().dyn_cast<fir::ReferenceType>()) {
21982197
if (fir::isa_builtin_cptr_type(refType.getElementType())) {
2199-
converter.bindSymbol(*sym, arg);
2198+
converter.bindSymbol(*argSymbol, arg);
22002199
} else {
22012200
extVal.match(
22022201
[&](const fir::MutableBoxValue &mbv) {
22032202
converter.bindSymbol(
2204-
*sym,
2203+
*argSymbol,
22052204
fir::MutableBoxValue(
22062205
arg, fir::factory::getNonDeferredLenParams(extVal), {}));
22072206
},
@@ -2214,7 +2213,6 @@ static void genBodyOfTargetDataOp(
22142213
TODO(converter.getCurrentLocation(),
22152214
"use_device clause operand unsupported type");
22162215
}
2217-
argIndex++;
22182216
}
22192217

22202218
// Insert dummy instruction to remember the insertion position. The
@@ -2470,8 +2468,6 @@ static void genBodyOfTargetOp(
24702468
auto *regionBlock =
24712469
firOpBuilder.createBlock(&region, {}, mapSymTypes, mapSymLocs);
24722470

2473-
unsigned argIndex = 0;
2474-
24752471
// Clones the `bounds` placing them inside the target region and returns them.
24762472
auto cloneBound = [&](mlir::Value bound) {
24772473
if (mlir::isMemoryEffectFree(bound.getDefiningOp())) {
@@ -2491,43 +2487,44 @@ static void genBodyOfTargetOp(
24912487
};
24922488

24932489
// Bind the symbols to their corresponding block arguments.
2494-
for (const Fortran::semantics::Symbol *sym : mapSymbols) {
2490+
for (auto [argIndex, argSymbol] : llvm::enumerate(mapSymbols)) {
24952491
const mlir::BlockArgument &arg = region.getArgument(argIndex);
2496-
fir::ExtendedValue extVal = converter.getSymbolExtendedValue(*sym);
2492+
fir::ExtendedValue extVal = converter.getSymbolExtendedValue(*argSymbol);
24972493
extVal.match(
24982494
[&](const fir::BoxValue &v) {
2499-
converter.bindSymbol(*sym,
2495+
converter.bindSymbol(*argSymbol,
25002496
fir::BoxValue(arg, cloneBounds(v.getLBounds()),
25012497
v.getExplicitParameters(),
25022498
v.getExplicitExtents()));
25032499
},
25042500
[&](const fir::MutableBoxValue &v) {
25052501
converter.bindSymbol(
2506-
*sym, fir::MutableBoxValue(arg, cloneBounds(v.getLBounds()),
2507-
v.getMutableProperties()));
2502+
*argSymbol, fir::MutableBoxValue(arg, cloneBounds(v.getLBounds()),
2503+
v.getMutableProperties()));
25082504
},
25092505
[&](const fir::ArrayBoxValue &v) {
25102506
converter.bindSymbol(
2511-
*sym, fir::ArrayBoxValue(arg, cloneBounds(v.getExtents()),
2512-
cloneBounds(v.getLBounds()),
2513-
v.getSourceBox()));
2507+
*argSymbol, fir::ArrayBoxValue(arg, cloneBounds(v.getExtents()),
2508+
cloneBounds(v.getLBounds()),
2509+
v.getSourceBox()));
25142510
},
25152511
[&](const fir::CharArrayBoxValue &v) {
25162512
converter.bindSymbol(
2517-
*sym, fir::CharArrayBoxValue(arg, cloneBound(v.getLen()),
2518-
cloneBounds(v.getExtents()),
2519-
cloneBounds(v.getLBounds())));
2513+
*argSymbol, fir::CharArrayBoxValue(arg, cloneBound(v.getLen()),
2514+
cloneBounds(v.getExtents()),
2515+
cloneBounds(v.getLBounds())));
25202516
},
25212517
[&](const fir::CharBoxValue &v) {
2522-
converter.bindSymbol(*sym,
2518+
converter.bindSymbol(*argSymbol,
25232519
fir::CharBoxValue(arg, cloneBound(v.getLen())));
25242520
},
2525-
[&](const fir::UnboxedValue &v) { converter.bindSymbol(*sym, arg); },
2521+
[&](const fir::UnboxedValue &v) {
2522+
converter.bindSymbol(*argSymbol, arg);
2523+
},
25262524
[&](const auto &) {
25272525
TODO(converter.getCurrentLocation(),
25282526
"target map clause operand unsupported type");
25292527
});
2530-
argIndex++;
25312528
}
25322529

25332530
// Check if cloning the bounds introduced any dependency on the outer region.

0 commit comments

Comments
 (0)