[BranchProbabilityInfo] Remove block handles in eraseBlock()

BranchProbabilityInfo::eraseBlock() is a public method and
can be called without deleting the block itself.
This method is made remove the correspondent tracking handle
from BranchProbabilityInfo::Handles along with
the probabilities of the block. Handles.erase() call is moved
to eraseBlock().
In setEdgeProbability() we need to add the block handle only once.

Reviewed By: kazu

Differential Revision: https://reviews.llvm.org/D90838
This commit is contained in:
Yevgeny Rouban 2020-11-06 13:11:08 +07:00
parent 60e2c5b03b
commit e38c8e7590
2 changed files with 2 additions and 2 deletions

View File

@ -213,7 +213,6 @@ private:
void deleted() override {
assert(BPI != nullptr);
BPI->eraseBlock(cast<BasicBlock>(getValPtr()));
BPI->Handles.erase(*this);
}
public:

View File

@ -1138,10 +1138,10 @@ void BranchProbabilityInfo::setEdgeProbability(
if (Probs.size() == 0)
return; // Nothing to set.
Handles.insert(BasicBlockCallbackVH(Src, this));
uint64_t TotalNumerator = 0;
for (unsigned SuccIdx = 0; SuccIdx < Probs.size(); ++SuccIdx) {
this->Probs[std::make_pair(Src, SuccIdx)] = Probs[SuccIdx];
Handles.insert(BasicBlockCallbackVH(Src, this));
LLVM_DEBUG(dbgs() << "set edge " << Src->getName() << " -> " << SuccIdx
<< " successor probability to " << Probs[SuccIdx]
<< "\n");
@ -1177,6 +1177,7 @@ void BranchProbabilityInfo::eraseBlock(const BasicBlock *BB) {
// a pair (BB, N) if there is no data for (BB, N-1) because the data is always
// set for all successors from 0 to M at once by the method
// setEdgeProbability().
Handles.erase(BasicBlockCallbackVH(BB, this));
for (unsigned I = 0;; ++I) {
auto MapI = Probs.find(std::make_pair(BB, I));
if (MapI == Probs.end()) {