Skip to content

Commit 1c55dcb

Browse files
committed
[NFCI][SimplifyCFG] Don't pay for a Small{Map,Set}Vector when plain SmallSet will suffice
This *only* changes the cases where we *really* don't care about the iteration order of the underlying contained, namely when we will use the values from it to form DTU updates.
1 parent 93a636d commit 1c55dcb

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
228228
// These dominator edges will be redirected from Pred.
229229
std::vector<DominatorTree::UpdateType> Updates;
230230
if (DTU) {
231-
SmallSetVector<BasicBlock *, 2> UniqueSuccessors(succ_begin(BB),
232-
succ_end(BB));
231+
SmallPtrSet<BasicBlock *, 2> UniqueSuccessors(succ_begin(BB), succ_end(BB));
233232
Updates.reserve(1 + (2 * UniqueSuccessors.size()));
234233
// Add insert edges first. Experimentally, for the particular case of two
235234
// blocks that can be merged, with a single successor and single predecessor
@@ -569,8 +568,8 @@ static BasicBlock *SplitBlockImpl(BasicBlock *Old, Instruction *SplitPt,
569568
if (DTU) {
570569
SmallVector<DominatorTree::UpdateType, 8> Updates;
571570
// Old dominates New. New node dominates all other nodes dominated by Old.
572-
SmallSetVector<BasicBlock *, 8> UniqueSuccessorsOfOld(succ_begin(New),
573-
succ_end(New));
571+
SmallPtrSet<BasicBlock *, 8> UniqueSuccessorsOfOld(succ_begin(New),
572+
succ_end(New));
574573
Updates.push_back({DominatorTree::Insert, Old, New});
575574
Updates.reserve(Updates.size() + 2 * UniqueSuccessorsOfOld.size());
576575
for (BasicBlock *UniqueSuccessorOfOld : UniqueSuccessorsOfOld) {
@@ -635,8 +634,8 @@ BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, Instruction *SplitPt,
635634
SmallVector<DominatorTree::UpdateType, 8> DTUpdates;
636635
// New dominates Old. The predecessor nodes of the Old node dominate
637636
// New node.
638-
SmallSetVector<BasicBlock *, 8> UniquePredecessorsOfOld(pred_begin(New),
639-
pred_end(New));
637+
SmallPtrSet<BasicBlock *, 8> UniquePredecessorsOfOld(pred_begin(New),
638+
pred_end(New));
640639
DTUpdates.push_back({DominatorTree::Insert, New, Old});
641640
DTUpdates.reserve(DTUpdates.size() + 2 * UniquePredecessorsOfOld.size());
642641
for (BasicBlock *UniquePredecessorOfOld : UniquePredecessorsOfOld) {
@@ -675,7 +674,7 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB,
675674
} else {
676675
// Split block expects NewBB to have a non-empty set of predecessors.
677676
SmallVector<DominatorTree::UpdateType, 8> Updates;
678-
SmallSetVector<BasicBlock *, 8> UniquePreds(Preds.begin(), Preds.end());
677+
SmallPtrSet<BasicBlock *, 8> UniquePreds(Preds.begin(), Preds.end());
679678
Updates.push_back({DominatorTree::Insert, NewBB, OldBB});
680679
Updates.reserve(Updates.size() + 2 * UniquePreds.size());
681680
for (auto *UniquePred : UniquePreds) {
@@ -1141,8 +1140,8 @@ SplitBlockAndInsertIfThenImpl(Value *Cond, Instruction *SplitBefore,
11411140
BasicBlock *Head = SplitBefore->getParent();
11421141
BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator());
11431142
if (DTU) {
1144-
SmallSetVector<BasicBlock *, 8> UniqueSuccessorsOfHead(succ_begin(Tail),
1145-
succ_end(Tail));
1143+
SmallPtrSet<BasicBlock *, 8> UniqueSuccessorsOfHead(succ_begin(Tail),
1144+
succ_end(Tail));
11461145
Updates.push_back({DominatorTree::Insert, Head, Tail});
11471146
Updates.reserve(Updates.size() + 2 * UniqueSuccessorsOfHead.size());
11481147
for (BasicBlock *UniqueSuccessorOfHead : UniqueSuccessorsOfHead) {

llvm/lib/Transforms/Utils/Local.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
258258
Builder.CreateBr(TheOnlyDest);
259259
BasicBlock *BB = SI->getParent();
260260

261-
SmallSetVector<BasicBlock *, 8> RemovedSuccessors;
261+
SmallSet<BasicBlock *, 8> RemovedSuccessors;
262262

263263
// Remove entries from PHI nodes which we no longer branch to...
264264
BasicBlock *SuccToKeep = TheOnlyDest;
@@ -330,7 +330,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
330330
if (auto *BA =
331331
dyn_cast<BlockAddress>(IBI->getAddress()->stripPointerCasts())) {
332332
BasicBlock *TheOnlyDest = BA->getBasicBlock();
333-
SmallSetVector<BasicBlock *, 8> RemovedSuccessors;
333+
SmallSet<BasicBlock *, 8> RemovedSuccessors;
334334

335335
// Insert the new branch.
336336
Builder.CreateBr(TheOnlyDest);
@@ -2132,7 +2132,7 @@ unsigned llvm::changeToUnreachable(Instruction *I, bool UseLLVMTrap,
21322132
if (MSSAU)
21332133
MSSAU->changeToUnreachable(I);
21342134

2135-
SmallSetVector<BasicBlock *, 8> UniqueSuccessors;
2135+
SmallSet<BasicBlock *, 8> UniqueSuccessors;
21362136

21372137
// Loop over all of the successors, removing BB's entry from any PHI
21382138
// nodes.
@@ -2393,7 +2393,7 @@ static bool markAliveBlocks(Function &F,
23932393
}
23942394
};
23952395

2396-
SmallMapVector<BasicBlock *, int, 8> NumPerSuccessorCases;
2396+
SmallDenseMap<BasicBlock *, int, 8> NumPerSuccessorCases;
23972397
// Set of unique CatchPads.
23982398
SmallDenseMap<CatchPadInst *, detail::DenseSetEmpty, 4,
23992399
CatchPadDenseMapInfo, detail::DenseSetPair<CatchPadInst *>>
@@ -2507,7 +2507,7 @@ bool llvm::removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU,
25072507
// their internal references. Update DTU if available.
25082508
std::vector<DominatorTree::UpdateType> Updates;
25092509
for (auto *BB : BlocksToRemove) {
2510-
SmallSetVector<BasicBlock *, 8> UniqueSuccessors;
2510+
SmallSet<BasicBlock *, 8> UniqueSuccessors;
25112511
for (BasicBlock *Successor : successors(BB)) {
25122512
// Only remove references to BB in reachable successors of BB.
25132513
if (Reachable.count(Successor))

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ bool SimplifyCFGOpt::SimplifyEqualityComparisonWithOnlyPredecessor(
910910
LLVM_DEBUG(dbgs() << "Threading pred instr: " << *Pred->getTerminator()
911911
<< "Through successor TI: " << *TI);
912912

913-
SmallMapVector<BasicBlock *, int, 8> NumPerSuccessorCases;
913+
SmallDenseMap<BasicBlock *, int, 8> NumPerSuccessorCases;
914914
for (SwitchInst::CaseIt i = SI->case_end(), e = SI->case_begin(); i != e;) {
915915
--i;
916916
auto *Successor = i->getCaseSuccessor();
@@ -961,7 +961,7 @@ bool SimplifyCFGOpt::SimplifyEqualityComparisonWithOnlyPredecessor(
961961
if (!TheRealDest)
962962
TheRealDest = ThisDef;
963963

964-
SmallSetVector<BasicBlock *, 2> RemovedSuccs;
964+
SmallPtrSet<BasicBlock *, 2> RemovedSuccs;
965965

966966
// Remove PHI node entries for dead edges.
967967
BasicBlock *CheckEdge = TheRealDest;
@@ -3793,7 +3793,7 @@ bool SimplifyCFGOpt::SimplifyTerminatorOnSelect(Instruction *OldTerm,
37933793
BasicBlock *KeepEdge1 = TrueBB;
37943794
BasicBlock *KeepEdge2 = TrueBB != FalseBB ? FalseBB : nullptr;
37953795

3796-
SmallSetVector<BasicBlock *, 2> RemovedSuccessors;
3796+
SmallPtrSet<BasicBlock *, 2> RemovedSuccessors;
37973797

37983798
// Then remove the rest.
37993799
for (BasicBlock *Succ : successors(OldTerm)) {
@@ -4913,7 +4913,7 @@ static bool eliminateDeadSwitchCases(SwitchInst *SI, DomTreeUpdater *DTU,
49134913

49144914
// Gather dead cases.
49154915
SmallVector<ConstantInt *, 8> DeadCases;
4916-
SmallMapVector<BasicBlock *, int, 8> NumPerSuccessorCases;
4916+
SmallDenseMap<BasicBlock *, int, 8> NumPerSuccessorCases;
49174917
for (auto &Case : SI->cases()) {
49184918
auto *Successor = Case.getCaseSuccessor();
49194919
if (DTU)
@@ -5999,7 +5999,7 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
59995999
}
60006000

60016001
// Remove the switch.
6002-
SmallSetVector<BasicBlock *, 8> RemovedSuccessors;
6002+
SmallPtrSet<BasicBlock *, 8> RemovedSuccessors;
60036003
for (unsigned i = 0, e = SI->getNumSuccessors(); i < e; ++i) {
60046004
BasicBlock *Succ = SI->getSuccessor(i);
60056005

@@ -6181,7 +6181,7 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) {
61816181

61826182
// Eliminate redundant destinations.
61836183
SmallPtrSet<Value *, 8> Succs;
6184-
SmallSetVector<BasicBlock *, 8> RemovedSuccs;
6184+
SmallPtrSet<BasicBlock *, 8> RemovedSuccs;
61856185
for (unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
61866186
BasicBlock *Dest = IBI->getDestination(i);
61876187
if (!Dest->hasAddressTaken() || !Succs.insert(Dest).second) {
@@ -6271,8 +6271,7 @@ static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
62716271

62726272
// We've found an identical block. Update our predecessors to take that
62736273
// path instead and make ourselves dead.
6274-
SmallPtrSet<BasicBlock *, 16> Preds;
6275-
Preds.insert(pred_begin(BB), pred_end(BB));
6274+
SmallPtrSet<BasicBlock *, 16> Preds(pred_begin(BB), pred_end(BB));
62766275
for (BasicBlock *Pred : Preds) {
62776276
InvokeInst *II = cast<InvokeInst>(Pred->getTerminator());
62786277
assert(II->getNormalDest() != BB && II->getUnwindDest() == BB &&
@@ -6293,8 +6292,7 @@ static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
62936292
Inst.eraseFromParent();
62946293
}
62956294

6296-
SmallPtrSet<BasicBlock *, 16> Succs;
6297-
Succs.insert(succ_begin(BB), succ_end(BB));
6295+
SmallPtrSet<BasicBlock *, 16> Succs(succ_begin(BB), succ_end(BB));
62986296
for (BasicBlock *Succ : Succs) {
62996297
Succ->removePredecessor(BB);
63006298
if (DTU)

0 commit comments

Comments
 (0)