@@ -236,28 +236,20 @@ class CIRTryOpFlattening : public mlir::OpRewritePattern<mlir::cir::TryOp> {
236
236
loc, mlir::cir::ExceptionInfoType::get (rewriter.getContext ()));
237
237
auto selector = rewriter.create <mlir::cir::EhSelectorOp>(loc, exception );
238
238
239
- // TODO: direct catch all needs no dispatch?
240
-
241
239
// Handle dispatch. In could in theory use a switch, but let's just
242
240
// mimic LLVM more closely since we have no specific thing to achieve
243
241
// doing that (might not play as well with existing optimizers either).
244
- auto *dispatchBlock =
242
+ auto *nextDispatcher =
245
243
rewriter.splitBlock (catchBegin, rewriter.getInsertionPoint ());
246
244
rewriter.setInsertionPointToEnd (catchBegin);
247
- rewriter.create <mlir::cir::BrOp>(loc, dispatchBlock );
245
+ rewriter.create <mlir::cir::BrOp>(loc, nextDispatcher );
248
246
249
247
// Fill in dispatcher.
250
- rewriter.setInsertionPointToEnd (dispatchBlock);
251
-
252
- // FIXME: we should have an extra block for the dispatcher, just in case
253
- // there isn't one later.
254
-
248
+ rewriter.setInsertionPointToEnd (nextDispatcher);
255
249
llvm::MutableArrayRef<mlir::Region> caseRegions = tryOp.getCatchRegions ();
256
250
mlir::ArrayAttr caseAttrList = tryOp.getCatchTypesAttr ();
257
251
unsigned caseCnt = 0 ;
258
252
259
- mlir::Block *nextDispatcher = rewriter.getInsertionBlock ();
260
-
261
253
for (mlir::Attribute caseAttr : caseAttrList) {
262
254
if (auto typeIdGlobal = dyn_cast<mlir::cir::GlobalViewAttr>(caseAttr)) {
263
255
auto typeId = rewriter.create <mlir::cir::EhTypeIdOp>(
@@ -275,7 +267,8 @@ class CIRTryOpFlattening : public mlir::OpRewritePattern<mlir::cir::TryOp> {
275
267
nextDispatcher);
276
268
rewriter.setInsertionPointToEnd (nextDispatcher);
277
269
} else if (auto catchAll = dyn_cast<mlir::cir::CatchAllAttr>(caseAttr)) {
278
- assert (nextDispatcher->empty () && " expect empty dispatcher" );
270
+ // In case the catch(...) is all we got, `nextDispatcher` shall be
271
+ // non-empty.
279
272
buildAllCase (rewriter, caseRegions[caseCnt], afterTry, nextDispatcher);
280
273
nextDispatcher = nullptr ; // No more business in try/catch
281
274
} else if (auto catchUnwind =
0 commit comments