@@ -217,59 +217,36 @@ static void bindEntryBlockArgs(lower::AbstractConverter &converter,
217
217
assert (args.isValid () && " invalid args" );
218
218
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
219
219
220
- auto bindSingleMapLike = [&converter,
221
- &firOpBuilder](const semantics::Symbol &sym,
222
- const mlir::BlockArgument &arg) {
223
- // Clones the `bounds` placing them inside the entry block and returns
224
- // them.
225
- auto cloneBound = [&](mlir::Value bound) {
226
- if (mlir::isMemoryEffectFree (bound.getDefiningOp ())) {
227
- mlir::Operation *clonedOp = firOpBuilder.clone (*bound.getDefiningOp ());
228
- return clonedOp->getResult (0 );
229
- }
230
- TODO (converter.getCurrentLocation (),
231
- " target map-like clause operand unsupported bound type" );
232
- };
233
-
234
- auto cloneBounds = [cloneBound](llvm::ArrayRef<mlir::Value> bounds) {
235
- llvm::SmallVector<mlir::Value> clonedBounds;
236
- llvm::transform (bounds, std::back_inserter (clonedBounds),
237
- [&](mlir::Value bound) { return cloneBound (bound); });
238
- return clonedBounds;
239
- };
240
-
220
+ auto bindSingleMapLike = [&converter](const semantics::Symbol &sym,
221
+ const mlir::BlockArgument &arg) {
241
222
fir::ExtendedValue extVal = converter.getSymbolExtendedValue (sym);
242
223
auto refType = mlir::dyn_cast<fir::ReferenceType>(arg.getType ());
243
224
if (refType && fir::isa_builtin_cptr_type (refType.getElementType ())) {
244
225
converter.bindSymbol (sym, arg);
245
226
} else {
246
227
extVal.match (
247
228
[&](const fir::BoxValue &v) {
248
- converter.bindSymbol (sym,
249
- fir::BoxValue (arg, cloneBounds (v.getLBounds ()),
250
- v.getExplicitParameters (),
251
- v.getExplicitExtents ()));
229
+ converter.bindSymbol (sym, fir::BoxValue (arg, v.getLBounds (),
230
+ v.getExplicitParameters (),
231
+ v.getExplicitExtents ()));
252
232
},
253
233
[&](const fir::MutableBoxValue &v) {
254
234
converter.bindSymbol (
255
- sym, fir::MutableBoxValue (arg, cloneBounds ( v.getLBounds () ),
235
+ sym, fir::MutableBoxValue (arg, v.getLBounds (),
256
236
v.getMutableProperties ()));
257
237
},
258
238
[&](const fir::ArrayBoxValue &v) {
259
- converter.bindSymbol (
260
- sym, fir::ArrayBoxValue (arg, cloneBounds (v.getExtents ()),
261
- cloneBounds (v.getLBounds ()),
262
- v.getSourceBox ()));
239
+ converter.bindSymbol (sym, fir::ArrayBoxValue (arg, v.getExtents (),
240
+ v.getLBounds (),
241
+ v.getSourceBox ()));
263
242
},
264
243
[&](const fir::CharArrayBoxValue &v) {
265
- converter.bindSymbol (
266
- sym, fir::CharArrayBoxValue (arg, cloneBound (v.getLen ()),
267
- cloneBounds (v.getExtents ()),
268
- cloneBounds (v.getLBounds ())));
244
+ converter.bindSymbol (sym, fir::CharArrayBoxValue (arg, v.getLen (),
245
+ v.getExtents (),
246
+ v.getLBounds ()));
269
247
},
270
248
[&](const fir::CharBoxValue &v) {
271
- converter.bindSymbol (
272
- sym, fir::CharBoxValue (arg, cloneBound (v.getLen ())));
249
+ converter.bindSymbol (sym, fir::CharBoxValue (arg, v.getLen ()));
273
250
},
274
251
[&](const fir::UnboxedValue &v) { converter.bindSymbol (sym, arg); },
275
252
[&](const auto &) {
@@ -1487,14 +1464,13 @@ static void genBodyOfTargetOp(
1487
1464
while (!valuesDefinedAbove.empty ()) {
1488
1465
for (mlir::Value val : valuesDefinedAbove) {
1489
1466
mlir::Operation *valOp = val.getDefiningOp ();
1490
- assert (valOp != nullptr );
1491
1467
1492
1468
// NOTE: We skip BoxDimsOp's as the lesser of two evils is to map the
1493
1469
// indices separately, as the alternative is to eventually map the Box,
1494
1470
// which comes with a fairly large overhead comparatively. We could be
1495
1471
// more robust about this and check using a BackwardsSlice to see if we
1496
1472
// run the risk of mapping a box.
1497
- if (mlir::isMemoryEffectFree (valOp) &&
1473
+ if (valOp && mlir::isMemoryEffectFree (valOp) &&
1498
1474
!mlir::isa<fir::BoxDimsOp>(valOp)) {
1499
1475
mlir::Operation *clonedOp = valOp->clone ();
1500
1476
entryBlock->push_front (clonedOp);
@@ -1507,7 +1483,13 @@ static void genBodyOfTargetOp(
1507
1483
valOp->replaceUsesWithIf (clonedOp, replace);
1508
1484
} else {
1509
1485
auto savedIP = firOpBuilder.getInsertionPoint ();
1510
- firOpBuilder.setInsertionPointAfter (valOp);
1486
+
1487
+ if (valOp)
1488
+ firOpBuilder.setInsertionPointAfter (valOp);
1489
+ else
1490
+ // This means val is a block argument
1491
+ firOpBuilder.setInsertionPoint (targetOp);
1492
+
1511
1493
auto copyVal =
1512
1494
firOpBuilder.createTemporary (val.getLoc (), val.getType ());
1513
1495
firOpBuilder.createStoreWithConvert (copyVal.getLoc (), val, copyVal);
0 commit comments