[PATCH] D90839: [BranchProbabilityInfo] Introduce method copyEdgeProbabilities(). NFC
Yevgeny Rouban via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 5 04:49:04 PST 2020
yrouban created this revision.
yrouban added reviewers: kazu, efriedma, MaskRay, wmi, ebrevnov.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
yrouban requested review of this revision.
A new method is introduced to allow bulk copy of outgoing edge probabilities from one block to another. This can be useful when a block is a cloned from another one and we do not know if there are edge probabilities set for the original block or not. Copying outside of the BranchProbabilityInfo class makes the user unconditionally set the cloned block's edge probabilities even if they are unset for the original block.
This new method will be used in //JumpThreading//.
Repository:
rG LLVM Github Monorepo
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,24 @@
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.303084.patch
Type: text/x-patch
Size: 2185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201105/d0877773/attachment.bin>
More information about the llvm-commits
mailing list