From ee40d1e8da38e37a25854868d007720454396648 Mon Sep 17 00:00:00 2001 From: Igor Laevsky Date: Fri, 15 Jul 2016 14:31:16 +0000 Subject: Re-submit r272891 "Prevent dangling pointer problems in BranchProbabilityInfo" Most possibly problem was caused by the same reason as PR28400. This change bypasses it by using CallbackVH instead of AssertingVH. Differential Revision: https://reviews.llvm.org/D20957 llvm-svn: 275563 --- llvm/lib/Analysis/BranchProbabilityInfo.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'llvm/lib/Analysis/BranchProbabilityInfo.cpp') diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp index 8c12a100428..d802552d4e2 100644 --- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp +++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp @@ -624,6 +624,7 @@ void BranchProbabilityInfo::setEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors, BranchProbability Prob) { Probs[std::make_pair(Src, IndexInSuccessors)] = Prob; + Handles.insert(BasicBlockCallbackVH(Src, this)); DEBUG(dbgs() << "set edge " << Src->getName() << " -> " << IndexInSuccessors << " successor probability to " << Prob << "\n"); } @@ -641,6 +642,14 @@ BranchProbabilityInfo::printEdgeProbability(raw_ostream &OS, return OS; } +void BranchProbabilityInfo::eraseBlock(const BasicBlock *BB) { + for (auto I = Probs.begin(), E = Probs.end(); I != E; ++I) { + auto Key = I->first; + if (Key.first == BB) + Probs.erase(Key); + } +} + void BranchProbabilityInfo::calculate(const Function &F, const LoopInfo &LI) { DEBUG(dbgs() << "---- Branch Probability Info : " << F.getName() << " ----\n\n"); -- cgit v1.2.3