[llvm] d69ada3 - [BranchProbabilityInfo] Make MaxSuccIdx[Src] efficient and add a comment about the subtle eraseBlock. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 27 16:29:30 PDT 2020
Author: Fangrui Song
Date: 2020-10-27T16:29:23-07:00
New Revision: d69ada30e23f1b226daeee3a9b13826e1e368ede
URL: https://github.com/llvm/llvm-project/commit/d69ada30e23f1b226daeee3a9b13826e1e368ede
DIFF: https://github.com/llvm/llvm-project/commit/d69ada30e23f1b226daeee3a9b13826e1e368ede.diff
LOG: [BranchProbabilityInfo] Make MaxSuccIdx[Src] efficient and add a comment about the subtle eraseBlock. NFC
Follow-up to D90272.
Added:
Modified:
llvm/lib/Analysis/BranchProbabilityInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 7d9760e3619c..267d415ff52b 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -1138,10 +1138,8 @@ void BranchProbabilityInfo::setEdgeProbability(const BasicBlock *Src,
<< IndexInSuccessors << " successor probability to " << Prob
<< "\n");
- if (MaxSuccIdx.find(Src) == MaxSuccIdx.end())
- MaxSuccIdx[Src] = IndexInSuccessors;
- else
- MaxSuccIdx[Src] = std::max(MaxSuccIdx[Src], IndexInSuccessors);
+ unsigned &SuccIdx = MaxSuccIdx[Src];
+ SuccIdx = std::max(SuccIdx, IndexInSuccessors);
}
/// Set the edge probability for all edges at once.
@@ -1179,6 +1177,8 @@ BranchProbabilityInfo::printEdgeProbability(raw_ostream &OS,
}
void BranchProbabilityInfo::eraseBlock(const BasicBlock *BB) {
+ // Note that we cannot use successors of BB because the terminator of BB may
+ // have changed when eraseBlock is called as a BasicBlockCallbackVH callback.
auto It = MaxSuccIdx.find(BB);
if (It == MaxSuccIdx.end())
return;
More information about the llvm-commits
mailing list