@@ -414,6 +414,11 @@ VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
414
414
PrevBB->getParent (), CFG.ExitBB );
415
415
LLVM_DEBUG (dbgs () << " LV: created " << NewBB->getName () << ' \n ' );
416
416
417
+ return NewBB;
418
+ }
419
+
420
+ void VPBasicBlock::connectToPredecessors (VPTransformState::CFGState &CFG) {
421
+ BasicBlock *NewBB = CFG.VPBB2IRBB [this ];
417
422
// Hook up the new basic block to its predecessors.
418
423
for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors ()) {
419
424
VPBasicBlock *PredVPBB = PredVPBlock->getExitingBasicBlock ();
@@ -438,19 +443,22 @@ VPBasicBlock::createEmptyBasicBlock(VPTransformState::CFGState &CFG) {
438
443
// Set each forward successor here when it is created, excluding
439
444
// backedges. A backward successor is set when the branch is created.
440
445
unsigned idx = PredVPSuccessors.front () == this ? 0 : 1 ;
441
- assert (!TermBr->getSuccessor (idx) &&
442
- " Trying to reset an existing successor block." );
446
+ assert (
447
+ (!TermBr->getSuccessor (idx) ||
448
+ (isa<VPIRBasicBlock>(this ) && TermBr->getSuccessor (idx) == NewBB)) &&
449
+ " Trying to reset an existing successor block." );
443
450
TermBr->setSuccessor (idx, NewBB);
444
451
}
445
452
CFG.DTU .applyUpdates ({{DominatorTree::Insert, PredBB, NewBB}});
446
453
}
447
- return NewBB;
448
454
}
449
455
450
456
void VPIRBasicBlock::execute (VPTransformState *State) {
451
457
assert (getHierarchicalSuccessors ().size () <= 2 &&
452
458
" VPIRBasicBlock can have at most two successors at the moment!" );
453
459
State->Builder .SetInsertPoint (IRBB->getTerminator ());
460
+ State->CFG .PrevBB = IRBB;
461
+ State->CFG .VPBB2IRBB [this ] = IRBB;
454
462
executeRecipes (State, IRBB);
455
463
// Create a branch instruction to terminate IRBB if one was not created yet
456
464
// and is needed.
@@ -464,23 +472,7 @@ void VPIRBasicBlock::execute(VPTransformState *State) {
464
472
" other blocks must be terminated by a branch" );
465
473
}
466
474
467
- for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors ()) {
468
- VPBasicBlock *PredVPBB = PredVPBlock->getExitingBasicBlock ();
469
- BasicBlock *PredBB = State->CFG .VPBB2IRBB [PredVPBB];
470
- assert (PredBB && " Predecessor basic-block not found building successor." );
471
- LLVM_DEBUG (dbgs () << " LV: draw edge from" << PredBB->getName () << ' \n ' );
472
-
473
- auto *PredBBTerminator = PredBB->getTerminator ();
474
- auto *TermBr = cast<BranchInst>(PredBBTerminator);
475
- // Set each forward successor here when it is created, excluding
476
- // backedges. A backward successor is set when the branch is created.
477
- const auto &PredVPSuccessors = PredVPBB->getHierarchicalSuccessors ();
478
- unsigned idx = PredVPSuccessors.front () == this ? 0 : 1 ;
479
- assert ((!TermBr->getSuccessor (idx) || TermBr->getSuccessor (idx) == IRBB) &&
480
- " Trying to reset an existing successor block." );
481
- TermBr->setSuccessor (idx, IRBB);
482
- State->CFG .DTU .applyUpdates ({{DominatorTree::Insert, PredBB, IRBB}});
483
- }
475
+ connectToPredecessors (State->CFG );
484
476
}
485
477
486
478
void VPBasicBlock::execute (VPTransformState *State) {
@@ -512,6 +504,7 @@ void VPBasicBlock::execute(VPTransformState *State) {
512
504
// predecessor of this region.
513
505
514
506
NewBB = createEmptyBasicBlock (State->CFG );
507
+
515
508
State->Builder .SetInsertPoint (NewBB);
516
509
// Temporarily terminate with unreachable until CFG is rewired.
517
510
UnreachableInst *Terminator = State->Builder .CreateUnreachable ();
@@ -520,7 +513,12 @@ void VPBasicBlock::execute(VPTransformState *State) {
520
513
if (State->CurrentVectorLoop )
521
514
State->CurrentVectorLoop ->addBasicBlockToLoop (NewBB, *State->LI );
522
515
State->Builder .SetInsertPoint (Terminator);
516
+
523
517
State->CFG .PrevBB = NewBB;
518
+ State->CFG .VPBB2IRBB [this ] = NewBB;
519
+ connectToPredecessors (State->CFG );
520
+ } else {
521
+ State->CFG .VPBB2IRBB [this ] = NewBB;
524
522
}
525
523
526
524
// 2. Fill the IR basic block with IR instructions.
@@ -541,7 +539,6 @@ void VPBasicBlock::executeRecipes(VPTransformState *State, BasicBlock *BB) {
541
539
LLVM_DEBUG (dbgs () << " LV: vectorizing VPBB:" << getName ()
542
540
<< " in BB:" << BB->getName () << ' \n ' );
543
541
544
- State->CFG .VPBB2IRBB [this ] = BB;
545
542
State->CFG .PrevVPBB = this ;
546
543
547
544
for (VPRecipeBase &Recipe : Recipes)
0 commit comments