@@ -355,33 +355,6 @@ void CIRGenFunction::enterCXXTryStmt(const CXXTryStmt &s, cir::TryOp tryOp,
355355 }
356356}
357357
358- // / Emit the structure of the dispatch block for the given catch scope.
359- // / It is an invariant that the dispatch block already exists.
360- static void emitCatchDispatchBlock (CIRGenFunction &cgf,
361- EHCatchScope &catchScope, cir::TryOp tryOp) {
362- if (EHPersonality::get (cgf).isWasmPersonality ()) {
363- cgf.cgm .errorNYI (" emitCatchDispatchBlock: WASM personality" );
364- return ;
365- }
366-
367- if (EHPersonality::get (cgf).usesFuncletPads ()) {
368- cgf.cgm .errorNYI (" emitCatchDispatchBlock: usesFuncletPads" );
369- return ;
370- }
371-
372- assert (catchScope.mayThrow () &&
373- " Expected catchScope that may throw exception" );
374-
375- // If there's only a single catch-all, getEHDispatchBlock returned
376- // that catch-all as the dispatch block.
377- if (catchScope.getNumHandlers () == 1 &&
378- catchScope.getHandler (0 ).isCatchAll ()) {
379- return ;
380- }
381-
382- cgf.cgm .errorNYI (" emitCatchDispatchBlock: non-catch all handler" );
383- }
384-
385358void CIRGenFunction::exitCXXTryStmt (const CXXTryStmt &s, bool isFnTryBlock) {
386359 unsigned numHandlers = s.getNumHandlers ();
387360 EHCatchScope &catchScope = cast<EHCatchScope>(*ehStack.begin ());
@@ -410,9 +383,6 @@ void CIRGenFunction::exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock) {
410383 return ;
411384 }
412385
413- // Emit the structure of the EH dispatch for this catch.
414- emitCatchDispatchBlock (*this , catchScope, tryOp);
415-
416386 // Copy the handler blocks off before we pop the EH stack. Emitting
417387 // the handlers might scribble on this memory.
418388 SmallVector<EHCatchScope::Handler, 8 > handlers (
@@ -490,8 +460,8 @@ void CIRGenFunction::exitCXXTryStmt(const CXXTryStmt &s, bool isFnTryBlock) {
490460 assert (!cir::MissingFeatures::incrementProfileCounter ());
491461}
492462
493- mlir::Operation *CIRGenFunction::emitLandingPad (cir::TryOp tryOp) {
494- assert (ehStack.requiresLandingPad ());
463+ mlir::Operation *CIRGenFunction::populateCatchHandlers (cir::TryOp tryOp) {
464+ assert (ehStack.requiresCatchOrCleanup ());
495465 assert (!cgm.getLangOpts ().IgnoreExceptions &&
496466 " LandingPad should not be emitted when -fignore-exceptions are in "
497467 " effect." );
@@ -551,17 +521,17 @@ mlir::Operation *CIRGenFunction::emitLandingPad(cir::TryOp tryOp) {
551521 if (handler.isCatchAll ()) {
552522 assert (!hasCatchAll);
553523 hasCatchAll = true ;
554- goto done ;
524+ break ;
555525 }
556526
557527 cgm.errorNYI (" emitLandingPad: non catch-all" );
558528 return {};
559529 }
560530
561- goto done;
531+ if (hasCatchAll)
532+ break ;
562533 }
563534
564- done:
565535 if (hasCatchAll) {
566536 handlerAttrs.push_back (cir::CatchAllAttr::get (&getMLIRContext ()));
567537 } else {
@@ -576,20 +546,19 @@ mlir::Operation *CIRGenFunction::emitLandingPad(cir::TryOp tryOp) {
576546
577547 // In traditional LLVM codegen. this tells the backend how to generate the
578548 // landing pad by generating a branch to the dispatch block. In CIR,
579- // getEHDispatchBlock is used to populate blocks for later filing during
549+ // this is used to populate blocks for later filing during
580550 // cleanup handling.
581- (void )getEHDispatchBlock (ehStack.getInnermostEHScope (), tryOp);
551+ (void )populateEHCatchRegions (ehStack.getInnermostEHScope (), tryOp);
582552
583553 return tryOp;
584554}
585555
586556// Differently from LLVM traditional codegen, there are no dispatch blocks
587557// to look at given cir.try_call does not jump to blocks like invoke does.
588- // However, we keep this around since other parts of CIRGen use
589- // getCachedEHDispatchBlock to infer state.
558+ // However.
590559mlir::Block *
591- CIRGenFunction::getEHDispatchBlock (EHScopeStack::stable_iterator scope,
592- cir::TryOp tryOp) {
560+ CIRGenFunction::populateEHCatchRegions (EHScopeStack::stable_iterator scope,
561+ cir::TryOp tryOp) {
593562 if (EHPersonality::get (*this ).usesFuncletPads ()) {
594563 cgm.errorNYI (" getEHDispatchBlock: usesFuncletPads" );
595564 return {};
@@ -648,7 +617,7 @@ CIRGenFunction::getEHDispatchBlock(EHScopeStack::stable_iterator scope,
648617}
649618
650619bool CIRGenFunction::isInvokeDest () {
651- if (!ehStack.requiresLandingPad ())
620+ if (!ehStack.requiresCatchOrCleanup ())
652621 return false ;
653622
654623 // If exceptions are disabled/ignored and SEH is not in use, then there is no
@@ -669,7 +638,7 @@ bool CIRGenFunction::isInvokeDest() {
669638}
670639
671640mlir::Operation *CIRGenFunction::getInvokeDestImpl (cir::TryOp tryOp) {
672- assert (ehStack.requiresLandingPad ());
641+ assert (ehStack.requiresCatchOrCleanup ());
673642 assert (!ehStack.empty ());
674643
675644 // TODO(cir): add personality function
@@ -681,7 +650,7 @@ mlir::Operation *CIRGenFunction::getInvokeDestImpl(cir::TryOp tryOp) {
681650 if (personality.usesFuncletPads ()) {
682651 cgm.errorNYI (" getInvokeDestImpl: usesFuncletPads" );
683652 } else {
684- lp = emitLandingPad (tryOp);
653+ lp = populateCatchHandlers (tryOp);
685654 }
686655
687656 return lp;
0 commit comments