1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[BranchProbabilityInfo] Introduce method copyEdgeProbabilities(). NFC

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 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.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D90839
This commit is contained in:
Yevgeny Rouban 2020-11-06 14:46:34 +07:00
parent 3151371b49
commit 5ddd491d11
2 changed files with 25 additions and 0 deletions

View File

@ -131,6 +131,12 @@ public:
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();

View File

@ -1157,6 +1157,25 @@ void BranchProbabilityInfo::setEdgeProbability(
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,