@@ -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+ void 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." );
@@ -500,7 +470,7 @@ mlir::Operation *CIRGenFunction::emitLandingPad(cir::TryOp tryOp) {
500470 switch (innermostEHScope.getKind ()) {
501471 case EHScope::Terminate:
502472 cgm.errorNYI (" emitLandingPad: terminate" );
503- return {} ;
473+ return ;
504474
505475 case EHScope::Catch:
506476 case EHScope::Cleanup:
@@ -523,17 +493,17 @@ mlir::Operation *CIRGenFunction::emitLandingPad(cir::TryOp tryOp) {
523493 switch (i->getKind ()) {
524494 case EHScope::Cleanup: {
525495 cgm.errorNYI (" emitLandingPad: Cleanup" );
526- return {} ;
496+ return ;
527497 }
528498
529499 case EHScope::Filter: {
530500 cgm.errorNYI (" emitLandingPad: Filter" );
531- return {} ;
501+ return ;
532502 }
533503
534504 case EHScope::Terminate: {
535505 cgm.errorNYI (" emitLandingPad: Terminate" );
536- return {} ;
506+ return ;
537507 }
538508
539509 case EHScope::Catch:
@@ -551,22 +521,22 @@ 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" );
558- return {} ;
528+ 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 {
568538 cgm.errorNYI (" emitLandingPad: non catch-all" );
569- return {} ;
539+ return ;
570540 }
571541
572542 // Add final array of clauses into TryOp.
@@ -576,23 +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);
582-
583- return tryOp;
551+ populateEHCatchRegions (ehStack.getInnermostEHScope (), tryOp);
584552}
585553
586554// Differently from LLVM traditional codegen, there are no dispatch blocks
587555// 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.
590- mlir::Block *
591- CIRGenFunction::getEHDispatchBlock (EHScopeStack::stable_iterator scope,
592- cir::TryOp tryOp) {
556+ // However.
557+ void CIRGenFunction::populateEHCatchRegions (EHScopeStack::stable_iterator scope,
558+ cir::TryOp tryOp) {
593559 if (EHPersonality::get (*this ).usesFuncletPads ()) {
594560 cgm.errorNYI (" getEHDispatchBlock: usesFuncletPads" );
595- return {} ;
561+ return ;
596562 }
597563
598564 // Otherwise, we should look at the actual scope.
@@ -606,7 +572,7 @@ CIRGenFunction::getEHDispatchBlock(EHScopeStack::stable_iterator scope,
606572 // - Update the map to enqueue new dispatchBlock to also get a cleanup. See
607573 // code at the end of the function.
608574 cgm.errorNYI (" getEHDispatchBlock: mayThrow & tryOp" );
609- return {} ;
575+ return ;
610576 }
611577
612578 if (!mayThrow) {
@@ -621,34 +587,33 @@ CIRGenFunction::getEHDispatchBlock(EHScopeStack::stable_iterator scope,
621587 break ;
622588 }
623589 cgm.errorNYI (" getEHDispatchBlock: mayThrow non-catch all" );
624- return {} ;
590+ return ;
625591 }
626592 case EHScope::Cleanup: {
627593 cgm.errorNYI (" getEHDispatchBlock: mayThrow & cleanup" );
628- return {} ;
594+ return ;
629595 }
630596 case EHScope::Filter: {
631597 cgm.errorNYI (" getEHDispatchBlock: mayThrow & Filter" );
632- return {} ;
598+ return ;
633599 }
634600 case EHScope::Terminate: {
635601 cgm.errorNYI (" getEHDispatchBlock: mayThrow & Terminate" );
636- return {} ;
602+ return ;
637603 }
638604 }
639605 }
640606
641607 if (originalBlock) {
642608 cgm.errorNYI (" getEHDispatchBlock: originalBlock" );
643- return {} ;
609+ return ;
644610 }
645611
646612 ehScope.setMayThrow (mayThrow);
647- return {};
648613}
649614
650- bool CIRGenFunction::isInvokeDest () {
651- if (!ehStack.requiresLandingPad ())
615+ bool CIRGenFunction::isCatchOrCleanupRequired () {
616+ if (!ehStack.requiresCatchOrCleanup ())
652617 return false ;
653618
654619 // If exceptions are disabled/ignored and SEH is not in use, then there is no
@@ -668,21 +633,17 @@ bool CIRGenFunction::isInvokeDest() {
668633 return true ;
669634}
670635
671- mlir::Operation * CIRGenFunction::getInvokeDestImpl (cir::TryOp tryOp) {
672- assert (ehStack.requiresLandingPad ());
636+ void CIRGenFunction::populateCatchHandlersIfRequired (cir::TryOp tryOp) {
637+ assert (ehStack.requiresCatchOrCleanup ());
673638 assert (!ehStack.empty ());
674639
675640 // TODO(cir): add personality function
676641
677642 // CIR does not cache landing pads.
678643 const EHPersonality &personality = EHPersonality::get (*this );
679-
680- mlir::Operation *lp = nullptr ;
681644 if (personality.usesFuncletPads ()) {
682645 cgm.errorNYI (" getInvokeDestImpl: usesFuncletPads" );
683646 } else {
684- lp = emitLandingPad (tryOp);
647+ populateCatchHandlers (tryOp);
685648 }
686-
687- return lp;
688649}
0 commit comments