@@ -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 &) {
@@ -1338,14 +1315,13 @@ static void genBodyOfTargetOp(
1338
1315
while (!valuesDefinedAbove.empty ()) {
1339
1316
for (mlir::Value val : valuesDefinedAbove) {
1340
1317
mlir::Operation *valOp = val.getDefiningOp ();
1341
- assert (valOp != nullptr );
1342
1318
1343
1319
// NOTE: We skip BoxDimsOp's as the lesser of two evils is to map the
1344
1320
// indices separately, as the alternative is to eventually map the Box,
1345
1321
// which comes with a fairly large overhead comparatively. We could be
1346
1322
// more robust about this and check using a BackwardsSlice to see if we
1347
1323
// run the risk of mapping a box.
1348
- if (mlir::isMemoryEffectFree (valOp) &&
1324
+ if (valOp && mlir::isMemoryEffectFree (valOp) &&
1349
1325
!mlir::isa<fir::BoxDimsOp>(valOp)) {
1350
1326
mlir::Operation *clonedOp = valOp->clone ();
1351
1327
entryBlock->push_front (clonedOp);
@@ -1358,7 +1334,13 @@ static void genBodyOfTargetOp(
1358
1334
valOp->replaceUsesWithIf (clonedOp, replace);
1359
1335
} else {
1360
1336
auto savedIP = firOpBuilder.getInsertionPoint ();
1361
- firOpBuilder.setInsertionPointAfter (valOp);
1337
+
1338
+ if (valOp)
1339
+ firOpBuilder.setInsertionPointAfter (valOp);
1340
+ else
1341
+ // This means val is a block argument
1342
+ firOpBuilder.setInsertionPoint (targetOp);
1343
+
1362
1344
auto copyVal =
1363
1345
firOpBuilder.createTemporary (val.getLoc (), val.getType ());
1364
1346
firOpBuilder.createStoreWithConvert (copyVal.getLoc (), val, copyVal);
0 commit comments