aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Analysis/BlockFrequencyInfo.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-12-18 20:30:12 +0000
committerDimitry Andric <dim@FreeBSD.org>2024-04-19 21:12:03 +0000
commitc9157d925c489f07ba9c0b2ce47e5149b75969a5 (patch)
tree08bc4a3d9cad3f9ebffa558ddf140b9d9257b219 /contrib/llvm-project/llvm/lib/Analysis/BlockFrequencyInfo.cpp
parent2a66844f606a35d68ad8a8061f4bea204274b3bc (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/BlockFrequencyInfo.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Analysis/BlockFrequencyInfo.cpp60
1 files changed, 30 insertions, 30 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/BlockFrequencyInfo.cpp b/contrib/llvm-project/llvm/lib/Analysis/BlockFrequencyInfo.cpp
index b18d04cc73db..96c9bfa0e372 100644
--- a/contrib/llvm-project/llvm/lib/Analysis/BlockFrequencyInfo.cpp
+++ b/contrib/llvm-project/llvm/lib/Analysis/BlockFrequencyInfo.cpp
@@ -78,14 +78,13 @@ cl::opt<PGOViewCountsType> PGOViewCounts(
clEnumValN(PGOVCT_Graph, "graph", "show a graph."),
clEnumValN(PGOVCT_Text, "text", "show in text.")));
-static cl::opt<bool> PrintBlockFreq(
- "print-bfi", cl::init(false), cl::Hidden,
- cl::desc("Print the block frequency info."));
-
-cl::opt<std::string> PrintBlockFreqFuncName(
- "print-bfi-func-name", cl::Hidden,
- cl::desc("The option to specify the name of the function "
- "whose block frequency info is printed."));
+static cl::opt<bool> PrintBFI("print-bfi", cl::init(false), cl::Hidden,
+ cl::desc("Print the block frequency info."));
+
+cl::opt<std::string>
+ PrintBFIFuncName("print-bfi-func-name", cl::Hidden,
+ cl::desc("The option to specify the name of the function "
+ "whose block frequency info is printed."));
} // namespace llvm
namespace llvm {
@@ -193,15 +192,14 @@ void BlockFrequencyInfo::calculate(const Function &F,
F.getName().equals(ViewBlockFreqFuncName))) {
view();
}
- if (PrintBlockFreq &&
- (PrintBlockFreqFuncName.empty() ||
- F.getName().equals(PrintBlockFreqFuncName))) {
+ if (PrintBFI &&
+ (PrintBFIFuncName.empty() || F.getName().equals(PrintBFIFuncName))) {
print(dbgs());
}
}
BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const {
- return BFI ? BFI->getBlockFreq(BB) : 0;
+ return BFI ? BFI->getBlockFreq(BB) : BlockFrequency(0);
}
std::optional<uint64_t>
@@ -214,7 +212,7 @@ BlockFrequencyInfo::getBlockProfileCount(const BasicBlock *BB,
}
std::optional<uint64_t>
-BlockFrequencyInfo::getProfileCountFromFreq(uint64_t Freq) const {
+BlockFrequencyInfo::getProfileCountFromFreq(BlockFrequency Freq) const {
if (!BFI)
return std::nullopt;
return BFI->getProfileCountFromFreq(*getFunction(), Freq);
@@ -225,17 +223,18 @@ bool BlockFrequencyInfo::isIrrLoopHeader(const BasicBlock *BB) {
return BFI->isIrrLoopHeader(BB);
}
-void BlockFrequencyInfo::setBlockFreq(const BasicBlock *BB, uint64_t Freq) {
+void BlockFrequencyInfo::setBlockFreq(const BasicBlock *BB,
+ BlockFrequency Freq) {
assert(BFI && "Expected analysis to be available");
BFI->setBlockFreq(BB, Freq);
}
void BlockFrequencyInfo::setBlockFreqAndScale(
- const BasicBlock *ReferenceBB, uint64_t Freq,
+ const BasicBlock *ReferenceBB, BlockFrequency Freq,
SmallPtrSetImpl<BasicBlock *> &BlocksToScale) {
assert(BFI && "Expected analysis to be available");
// Use 128 bits APInt to avoid overflow.
- APInt NewFreq(128, Freq);
+ APInt NewFreq(128, Freq.getFrequency());
APInt OldFreq(128, BFI->getBlockFreq(ReferenceBB).getFrequency());
APInt BBFreq(128, 0);
for (auto *BB : BlocksToScale) {
@@ -247,7 +246,7 @@ void BlockFrequencyInfo::setBlockFreqAndScale(
// a hot spot, one of the options proposed in
// https://reviews.llvm.org/D28535#650071 could be used to avoid this.
BBFreq = BBFreq.udiv(OldFreq);
- BFI->setBlockFreq(BB, BBFreq.getLimitedValue());
+ BFI->setBlockFreq(BB, BlockFrequency(BBFreq.getLimitedValue()));
}
BFI->setBlockFreq(ReferenceBB, Freq);
}
@@ -266,19 +265,8 @@ const BranchProbabilityInfo *BlockFrequencyInfo::getBPI() const {
return BFI ? &BFI->getBPI() : nullptr;
}
-raw_ostream &BlockFrequencyInfo::
-printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const {
- return BFI ? BFI->printBlockFreq(OS, Freq) : OS;
-}
-
-raw_ostream &
-BlockFrequencyInfo::printBlockFreq(raw_ostream &OS,
- const BasicBlock *BB) const {
- return BFI ? BFI->printBlockFreq(OS, BB) : OS;
-}
-
-uint64_t BlockFrequencyInfo::getEntryFreq() const {
- return BFI ? BFI->getEntryFreq() : 0;
+BlockFrequency BlockFrequencyInfo::getEntryFreq() const {
+ return BFI ? BFI->getEntryFreq() : BlockFrequency(0);
}
void BlockFrequencyInfo::releaseMemory() { BFI.reset(); }
@@ -293,6 +281,18 @@ void BlockFrequencyInfo::verifyMatch(BlockFrequencyInfo &Other) const {
BFI->verifyMatch(*Other.BFI);
}
+Printable llvm::printBlockFreq(const BlockFrequencyInfo &BFI,
+ BlockFrequency Freq) {
+ return Printable([&BFI, Freq](raw_ostream &OS) {
+ printBlockFreqImpl(OS, BFI.getEntryFreq(), Freq);
+ });
+}
+
+Printable llvm::printBlockFreq(const BlockFrequencyInfo &BFI,
+ const BasicBlock &BB) {
+ return printBlockFreq(BFI, BFI.getBlockFreq(&BB));
+}
+
INITIALIZE_PASS_BEGIN(BlockFrequencyInfoWrapperPass, "block-freq",
"Block Frequency Analysis", true, true)
INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)