[PATCH] D148237: [BPI] Add method to swap outgoing edges probabilities
Aleksandr Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 13 08:18:54 PDT 2023
aleksandr.popov created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
aleksandr.popov requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The motivation is need to update branch probability info after
swapping successors of branch instruction
https://reviews.llvm.org/D148237
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
@@ -1175,6 +1175,14 @@
}
}
+void BranchProbabilityInfo::swapSuccEdgesProbabilities(const BasicBlock *Src) {
+ assert(Src->getTerminator()->getNumSuccessors() == 2);
+ if (!Probs.contains(std::make_pair(Src, 0)))
+ return; // No probability is set for edges from Src
+ assert(Probs.contains(std::make_pair(Src, 1)));
+ std::swap(Probs[std::make_pair(Src, 0)], Probs[std::make_pair(Src, 1)]);
+}
+
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
@@ -189,6 +189,9 @@
/// unset for source.
void copyEdgeProbabilities(BasicBlock *Src, BasicBlock *Dst);
+ /// Swap outgoing edges probabilities for \p Src with branch terminator
+ void swapSuccEdgesProbabilities(const BasicBlock *Src);
+
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: D148237.513243.patch
Type: text/x-patch
Size: 1459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230413/6662712d/attachment.bin>
More information about the llvm-commits
mailing list