@@ -207,21 +207,6 @@ STATISTIC(NumInvokes,
207207STATISTIC (NumInvokesMerged, " Number of invokes that were merged together" );
208208STATISTIC (NumInvokeSetsFormed, " Number of invoke sets that were formed" );
209209
210- namespace llvm {
211-
212- void SimplifyCFGCostTracker::updateNumBonusInsts (BasicBlock *BB,
213- unsigned InstCount) {
214- auto Loc = NumBonusInsts.find (BB);
215- if (Loc == NumBonusInsts.end ())
216- Loc = NumBonusInsts.insert ({BB, 0 }).first ;
217- Loc->second = Loc->second + InstCount;
218- }
219- unsigned SimplifyCFGCostTracker::getNumBonusInsts (BasicBlock *BB) {
220- return NumBonusInsts.lookup (BB);
221- }
222-
223- } // namespace llvm
224-
225210namespace {
226211
227212// The first field contains the value that the switch produces when a certain
@@ -258,10 +243,6 @@ class SimplifyCFGOpt {
258243 ArrayRef<WeakVH> LoopHeaders;
259244 const SimplifyCFGOptions &Options;
260245 bool Resimplify;
261- // Accumulates number of bonus instructions due to merging basic blocks
262- // of common destination.
263- SimplifyCFGCostTracker *CostTracker;
264- std::unique_ptr<SimplifyCFGCostTracker> LocalCostTracker;
265246
266247 Value *isValueEqualityComparison (Instruction *TI);
267248 BasicBlock *GetValueEqualityComparisonCases (
@@ -305,15 +286,8 @@ class SimplifyCFGOpt {
305286public:
306287 SimplifyCFGOpt (const TargetTransformInfo &TTI, DomTreeUpdater *DTU,
307288 const DataLayout &DL, ArrayRef<WeakVH> LoopHeaders,
308- const SimplifyCFGOptions &Opts,
309- SimplifyCFGCostTracker *CostTracker_)
289+ const SimplifyCFGOptions &Opts)
310290 : TTI(TTI), DTU(DTU), DL(DL), LoopHeaders(LoopHeaders), Options(Opts) {
311- // Cannot do this with member initializer list since LocalCostTracker is not
312- // initialized there yet.
313- CostTracker = CostTracker_
314- ? CostTracker_
315- : (LocalCostTracker.reset (new SimplifyCFGCostTracker ()),
316- LocalCostTracker.get ());
317291 assert ((!DTU || !DTU->hasPostDomTree ()) &&
318292 " SimplifyCFG is not yet capable of maintaining validity of a "
319293 " PostDomTree, so don't ask for it." );
@@ -3650,9 +3624,8 @@ static bool isVectorOp(Instruction &I) {
36503624// / If this basic block is simple enough, and if a predecessor branches to us
36513625// / and one of our successors, fold the block into the predecessor and use
36523626// / logical operations to pick the right destination.
3653- bool llvm::FoldBranchToCommonDest (BranchInst *BI,
3654- SimplifyCFGCostTracker &CostTracker,
3655- DomTreeUpdater *DTU, MemorySSAUpdater *MSSAU,
3627+ bool llvm::FoldBranchToCommonDest (BranchInst *BI, DomTreeUpdater *DTU,
3628+ MemorySSAUpdater *MSSAU,
36563629 const TargetTransformInfo *TTI,
36573630 unsigned BonusInstThreshold) {
36583631 // If this block ends with an unconditional branch,
@@ -3724,6 +3697,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI,
37243697 // as "bonus instructions", and only allow this transformation when the
37253698 // number of the bonus instructions we'll need to create when cloning into
37263699 // each predecessor does not exceed a certain threshold.
3700+ unsigned NumBonusInsts = 0 ;
37273701 bool SawVectorOp = false ;
37283702 const unsigned PredCount = Preds.size ();
37293703 for (Instruction &I : *BB) {
@@ -3742,13 +3716,12 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI,
37423716 // predecessor. Ignore free instructions.
37433717 if (!TTI || TTI->getInstructionCost (&I, CostKind) !=
37443718 TargetTransformInfo::TCC_Free) {
3745- for (auto PredBB : Preds) {
3746- CostTracker.updateNumBonusInsts (PredBB, PredCount);
3747- // Early exits once we reach the limit.
3748- if (CostTracker.getNumBonusInsts (PredBB) >
3749- BonusInstThreshold * BranchFoldToCommonDestVectorMultiplier)
3750- return false ;
3751- }
3719+ NumBonusInsts += PredCount;
3720+
3721+ // Early exits once we reach the limit.
3722+ if (NumBonusInsts >
3723+ BonusInstThreshold * BranchFoldToCommonDestVectorMultiplier)
3724+ return false ;
37523725 }
37533726
37543727 auto IsBCSSAUse = [BB, &I](Use &U) {
@@ -3762,12 +3735,10 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI,
37623735 if (!all_of (I.uses (), IsBCSSAUse))
37633736 return false ;
37643737 }
3765- for (auto PredBB : Preds) {
3766- if (CostTracker.getNumBonusInsts (PredBB) >
3767- BonusInstThreshold *
3768- (SawVectorOp ? BranchFoldToCommonDestVectorMultiplier : 1 ))
3769- return false ;
3770- }
3738+ if (NumBonusInsts >
3739+ BonusInstThreshold *
3740+ (SawVectorOp ? BranchFoldToCommonDestVectorMultiplier : 1 ))
3741+ return false ;
37713742
37723743 // Ok, we have the budget. Perform the transformation.
37733744 for (BasicBlock *PredBlock : Preds) {
@@ -6918,7 +6889,7 @@ bool SimplifyCFGOpt::simplifyUncondBranch(BranchInst *BI,
69186889 // branches to us and our successor, fold the comparison into the
69196890 // predecessor and use logical operations to update the incoming value
69206891 // for PHI nodes in common successor.
6921- if (FoldBranchToCommonDest (BI, *CostTracker, DTU, /* MSSAU=*/ nullptr , &TTI,
6892+ if (FoldBranchToCommonDest (BI, DTU, /* MSSAU=*/ nullptr , &TTI,
69226893 Options.BonusInstThreshold ))
69236894 return requestResimplify ();
69246895 return false ;
@@ -6987,7 +6958,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
69876958 // If this basic block is ONLY a compare and a branch, and if a predecessor
69886959 // branches to us and one of our successors, fold the comparison into the
69896960 // predecessor and use logical operations to pick the right destination.
6990- if (FoldBranchToCommonDest (BI, *CostTracker, DTU, /* MSSAU=*/ nullptr , &TTI,
6961+ if (FoldBranchToCommonDest (BI, DTU, /* MSSAU=*/ nullptr , &TTI,
69916962 Options.BonusInstThreshold ))
69926963 return requestResimplify ();
69936964
@@ -7286,9 +7257,8 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
72867257
72877258bool llvm::simplifyCFG (BasicBlock *BB, const TargetTransformInfo &TTI,
72887259 DomTreeUpdater *DTU, const SimplifyCFGOptions &Options,
7289- ArrayRef<WeakVH> LoopHeaders,
7290- SimplifyCFGCostTracker *CostTracker) {
7260+ ArrayRef<WeakVH> LoopHeaders) {
72917261 return SimplifyCFGOpt (TTI, DTU, BB->getModule ()->getDataLayout (), LoopHeaders,
7292- Options, CostTracker )
7262+ Options)
72937263 .run (BB);
72947264}
0 commit comments