@@ -209,6 +209,7 @@ class BoxedProcedurePass
209
209
BoxprocTypeRewriter typeConverter (mlir::UnknownLoc::get (context));
210
210
mlir::Dialect *firDialect = context->getLoadedDialect (" fir" );
211
211
getModule ().walk ([&](mlir::Operation *op) {
212
+ bool opIsValid = true ;
212
213
typeConverter.setLocation (op->getLoc ());
213
214
if (auto addr = mlir::dyn_cast<BoxAddrOp>(op)) {
214
215
mlir::Type ty = addr.getVal ().getType ();
@@ -220,6 +221,7 @@ class BoxedProcedurePass
220
221
rewriter.setInsertionPoint (addr);
221
222
rewriter.replaceOpWithNewOp <ConvertOp>(
222
223
addr, typeConverter.convertType (addr.getType ()), addr.getVal ());
224
+ opIsValid = false ;
223
225
} else if (typeConverter.needsConversion (resTy)) {
224
226
rewriter.startOpModification (op);
225
227
op->getResult (0 ).setType (typeConverter.convertType (resTy));
@@ -271,10 +273,12 @@ class BoxedProcedurePass
271
273
llvm::ArrayRef<mlir::Value>{tramp});
272
274
rewriter.replaceOpWithNewOp <ConvertOp>(embox, toTy,
273
275
adjustCall.getResult (0 ));
276
+ opIsValid = false ;
274
277
} else {
275
278
// Just forward the function as a pointer.
276
279
rewriter.replaceOpWithNewOp <ConvertOp>(embox, toTy,
277
280
embox.getFunc ());
281
+ opIsValid = false ;
278
282
}
279
283
} else if (auto global = mlir::dyn_cast<GlobalOp>(op)) {
280
284
auto ty = global.getType ();
@@ -297,6 +301,7 @@ class BoxedProcedurePass
297
301
rewriter.replaceOpWithNewOp <AllocaOp>(
298
302
mem, toTy, uniqName, bindcName, isPinned, mem.getTypeparams (),
299
303
mem.getShape ());
304
+ opIsValid = false ;
300
305
}
301
306
} else if (auto mem = mlir::dyn_cast<AllocMemOp>(op)) {
302
307
auto ty = mem.getType ();
@@ -310,6 +315,7 @@ class BoxedProcedurePass
310
315
rewriter.replaceOpWithNewOp <AllocMemOp>(
311
316
mem, toTy, uniqName, bindcName, mem.getTypeparams (),
312
317
mem.getShape ());
318
+ opIsValid = false ;
313
319
}
314
320
} else if (auto coor = mlir::dyn_cast<CoordinateOp>(op)) {
315
321
auto ty = coor.getType ();
@@ -321,6 +327,7 @@ class BoxedProcedurePass
321
327
auto toBaseTy = typeConverter.convertType (baseTy);
322
328
rewriter.replaceOpWithNewOp <CoordinateOp>(coor, toTy, coor.getRef (),
323
329
coor.getCoor (), toBaseTy);
330
+ opIsValid = false ;
324
331
}
325
332
} else if (auto index = mlir::dyn_cast<FieldIndexOp>(op)) {
326
333
auto ty = index.getType ();
@@ -332,6 +339,7 @@ class BoxedProcedurePass
332
339
auto toOnTy = typeConverter.convertType (onTy);
333
340
rewriter.replaceOpWithNewOp <FieldIndexOp>(
334
341
index, toTy, index.getFieldId (), toOnTy, index.getTypeparams ());
342
+ opIsValid = false ;
335
343
}
336
344
} else if (auto index = mlir::dyn_cast<LenParamIndexOp>(op)) {
337
345
auto ty = index.getType ();
@@ -343,6 +351,7 @@ class BoxedProcedurePass
343
351
auto toOnTy = typeConverter.convertType (onTy);
344
352
rewriter.replaceOpWithNewOp <LenParamIndexOp>(
345
353
index, toTy, index.getFieldId (), toOnTy, index.getTypeparams ());
354
+ opIsValid = false ;
346
355
}
347
356
} else if (op->getDialect () == firDialect) {
348
357
rewriter.startOpModification (op);
@@ -354,7 +363,7 @@ class BoxedProcedurePass
354
363
rewriter.finalizeOpModification (op);
355
364
}
356
365
// Ensure block arguments are updated if needed.
357
- if (op->getNumRegions () != 0 ) {
366
+ if (opIsValid && op->getNumRegions () != 0 ) {
358
367
rewriter.startOpModification (op);
359
368
for (mlir::Region ®ion : op->getRegions ())
360
369
for (mlir::Block &block : region.getBlocks ())
0 commit comments