[PATCH] D90839: [BranchProbabilityInfo] Introduce method copyEdgeProbabilities(). NFC
Yevgeny Rouban via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 5 23:53:21 PST 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG681d6c711f27: [BranchProbabilityInfo] Introduce method copyEdgeProbabilities(). NFC (authored by yrouban).
Changed prior to commit:
https://reviews.llvm.org/D90839?vs=303084&id=303344#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90839/new/
https://reviews.llvm.org/D90839
Files:
llvm/include/llvm/Analysis/BranchProbabilityInfo.h
llvm/lib/Analysis/BranchProbabilityInfo.cpp
Index: llvm/lib/Analysis/BranchProbabilityInfo.cpp
===================================================================
--- llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -1157,6 +1157,25 @@
assert(TotalNumerator >= BranchProbability::getDenominator() - Probs.size());
}
+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.find(std::make_pair(Src, 0)) == this->Probs.end())
+ 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");
+ }
+}
+
raw_ostream &
BranchProbabilityInfo::printEdgeProbability(raw_ostream &OS,
const BasicBlock *Src,
Index: llvm/include/llvm/Analysis/BranchProbabilityInfo.h
===================================================================
--- llvm/include/llvm/Analysis/BranchProbabilityInfo.h
+++ llvm/include/llvm/Analysis/BranchProbabilityInfo.h
@@ -131,6 +131,12 @@
void setEdgeProbability(const BasicBlock *Src,
const SmallVectorImpl<BranchProbability> &Probs);
+ /// Copy outgoing edge probabilities from \p Src to \p Dst.
+ ///
+ /// This allows to keep probabilities unset for the destination if they were
+ /// unset for source.
+ void copyEdgeProbabilities(BasicBlock *Src, BasicBlock *Dst);
+
static BranchProbability getBranchProbStackProtector(bool IsLikely) {
static const BranchProbability LikelyProb((1u << 20) - 1, 1u << 20);
return IsLikely ? LikelyProb : LikelyProb.getCompl();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90839.303344.patch
Type: text/x-patch
Size: 2236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201106/52d37f0a/attachment.bin>
More information about the llvm-commits
mailing list