uint32_t TrueWeight,
uint32_t FalseWeight) {
auto *BB = OldTerm->getParent();
-
// Remove any superfluous successor edges from the CFG.
// First, figure out which successors to preserve.
// If TrueBB and FalseBB are equal, only try to preserve one copy of that
BasicBlock *KeepEdge1 = TrueBB;
BasicBlock *KeepEdge2 = TrueBB != FalseBB ? FalseBB : nullptr;
- SmallVector<DominatorTree::UpdateType, 4> Updates;
+ SmallSetVector<BasicBlock *, 2> RemovedSuccessors;
// Then remove the rest.
for (BasicBlock *Succ : successors(OldTerm)) {
else {
Succ->removePredecessor(BB,
/*KeepOneInputPHIs=*/true);
- Updates.push_back({DominatorTree::Delete, BB, Succ});
+
+ if (Succ != TrueBB && Succ != FalseBB)
+ RemovedSuccessors.insert(Succ);
}
}
// We were only looking for one successor, and it was present.
// Create an unconditional branch to it.
Builder.CreateBr(TrueBB);
- Updates.push_back({DominatorTree::Insert, BB, TrueBB});
} else {
// We found both of the successors we were looking for.
// Create a conditional branch sharing the condition of the select.
BranchInst *NewBI = Builder.CreateCondBr(Cond, TrueBB, FalseBB);
- Updates.push_back({DominatorTree::Insert, BB, TrueBB});
- Updates.push_back({DominatorTree::Insert, BB, FalseBB});
if (TrueWeight != FalseWeight)
setBranchWeights(NewBI, TrueWeight, FalseWeight);
}
if (!KeepEdge1) {
// Only TrueBB was found.
Builder.CreateBr(TrueBB);
- Updates.push_back({DominatorTree::Insert, BB, TrueBB});
} else {
// Only FalseBB was found.
Builder.CreateBr(FalseBB);
- Updates.push_back({DominatorTree::Insert, BB, FalseBB});
}
}
EraseTerminatorAndDCECond(OldTerm);
- if (DTU)
- DTU->applyUpdatesPermissive(Updates);
+
+ if (DTU) {
+ SmallVector<DominatorTree::UpdateType, 2> Updates;
+ Updates.reserve(RemovedSuccessors.size());
+ for (auto *RemovedSuccessor : RemovedSuccessors)
+ Updates.push_back({DominatorTree::Delete, BB, RemovedSuccessor});
+ DTU->applyUpdates(Updates);
+ }
+
return true;
}