[llvm] [Analysis][NFC] Use block numbers for BranchProbabilityInfo (PR #186658)
Alexis Engelke via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 15 12:58:15 PDT 2026
================
@@ -1387,31 +1405,25 @@ void BranchProbabilityInfo::setEdgeProbability(
void BranchProbabilityInfo::copyEdgeProbabilities(BasicBlock *Src,
BasicBlock *Dst) {
- eraseBlock(Dst); // Erase stale data if any.
- unsigned NumSuccessors = Src->getTerminator()->getNumSuccessors();
- assert(NumSuccessors == Dst->getTerminator()->getNumSuccessors());
- if (NumSuccessors == 0)
- return; // Nothing to set.
- if (!this->Probs.contains(std::make_pair(Src, 0)))
- return; // No probability is set for edges from Src. Keep the same for Dst.
-
- Handles.insert(BasicBlockCallbackVH(Dst, this));
- for (unsigned SuccIdx = 0; SuccIdx < NumSuccessors; ++SuccIdx) {
- auto Prob = this->Probs[std::make_pair(Src, SuccIdx)];
- this->Probs[std::make_pair(Dst, SuccIdx)] = Prob;
- LLVM_DEBUG(dbgs() << "set edge " << Dst->getName() << " -> " << SuccIdx
- << " successor probability to " << Prob << "\n");
+ assert(succ_size(Src) == succ_size(Dst));
+ // allocEdges can reallocate and must be called first.
+ MutableArrayRef<BranchProbability> DstP = allocEdges(Dst);
+ const BranchProbability *SrcP = getEdges(Src);
+ if (!SrcP) {
+ eraseBlock(Dst);
+ return;
+ }
----------------
aengelke wrote:
Actually no: if !SrcP, it might also be the case that we don't have info for Src.
https://github.com/llvm/llvm-project/pull/186658
More information about the llvm-commits
mailing list