@@ -375,6 +375,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
375
375
// Mark live arguments in the regions of `regionBranchOp` in `liveArgs`.
376
376
auto markLiveArgs = [&](DenseMap<Region *, BitVector> &liveArgs) {
377
377
for (Region ®ion : regionBranchOp->getRegions ()) {
378
+ if (region.empty ())
379
+ continue ;
378
380
SmallVector<Value> arguments (region.front ().getArguments ());
379
381
BitVector regionLiveArgs = markLives (arguments, nonLiveSet, la);
380
382
liveArgs[®ion] = regionLiveArgs;
@@ -420,6 +422,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
420
422
auto markNonForwardedReturnValues =
421
423
[&](DenseMap<Operation *, BitVector> &nonForwardedRets) {
422
424
for (Region ®ion : regionBranchOp->getRegions ()) {
425
+ if (region.empty ())
426
+ continue ;
423
427
Operation *terminator = region.front ().getTerminator ();
424
428
nonForwardedRets[terminator] =
425
429
BitVector (terminator->getNumOperands (), true );
@@ -499,6 +503,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
499
503
// Recompute `resultsToKeep` and `argsToKeep` based on
500
504
// `terminatorOperandsToKeep`.
501
505
for (Region ®ion : regionBranchOp->getRegions ()) {
506
+ if (region.empty ())
507
+ continue ;
502
508
Operation *terminator = region.front ().getTerminator ();
503
509
for (const RegionSuccessor &successor : getSuccessors (®ion)) {
504
510
Region *successorRegion = successor.getSuccessor ();
@@ -547,6 +553,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
547
553
548
554
// Update the terminator operands that need to be kept.
549
555
for (Region ®ion : regionBranchOp->getRegions ()) {
556
+ if (region.empty ())
557
+ continue ;
550
558
updateOperandsOrTerminatorOperandsToKeep (
551
559
terminatorOperandsToKeep[region.back ().getTerminator ()],
552
560
resultsToKeep, argsToKeep, ®ion);
@@ -611,8 +619,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
611
619
612
620
// Do (2.a) and (2.b).
613
621
for (Region ®ion : regionBranchOp->getRegions ()) {
614
- assert (! region.empty () && " expected a non-empty region in an op "
615
- " implementing `RegionBranchOpInterface` " ) ;
622
+ if ( region.empty ())
623
+ continue ;
616
624
BitVector argsToRemove = argsToKeep[®ion].flip ();
617
625
cl.blocks .push_back ({®ion.front (), argsToRemove});
618
626
collectNonLiveValues (nonLiveSet, region.front ().getArguments (),
@@ -621,6 +629,8 @@ static void processRegionBranchOp(RegionBranchOpInterface regionBranchOp,
621
629
622
630
// Do (2.c).
623
631
for (Region ®ion : regionBranchOp->getRegions ()) {
632
+ if (region.empty ())
633
+ continue ;
624
634
Operation *terminator = region.front ().getTerminator ();
625
635
cl.operands .push_back (
626
636
{terminator, terminatorOperandsToKeep[terminator].flip ()});
0 commit comments