summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/BlockFrequencyInfo.cpp14
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp10
2 files changed, 17 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/BlockFrequencyInfo.cpp b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
index 90b7a339a0f..8b19b2e19c4 100644
--- a/llvm/lib/Analysis/BlockFrequencyInfo.cpp
+++ b/llvm/lib/Analysis/BlockFrequencyInfo.cpp
@@ -129,6 +129,20 @@ BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const {
return BFI ? BFI->getBlockFreq(BB) : 0;
}
+Optional<uint64_t>
+BlockFrequencyInfo::getBlockProfileCount(const BasicBlock *BB) const {
+ auto EntryCount = getFunction()->getEntryCount();
+ if (!EntryCount)
+ return None;
+ // Use 128 bit APInt to do the arithmetic to avoid overflow.
+ APInt BlockCount(128, EntryCount.getValue());
+ APInt BlockFreq(128, getBlockFreq(BB).getFrequency());
+ APInt EntryFreq(128, getEntryFreq());
+ BlockCount *= BlockFreq;
+ BlockCount = BlockCount.udiv(EntryFreq);
+ return BlockCount.getLimitedValue();
+}
+
void BlockFrequencyInfo::setBlockFreq(const BasicBlock *BB,
uint64_t Freq) {
assert(BFI && "Expected analysis to be available");
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 6510bce92b7..26cfe5943e1 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -34,7 +34,6 @@
#include "llvm/IR/Operator.h"
#include "llvm/IR/UseListOrder.h"
#include "llvm/IR/ValueSymbolTable.h"
-#include "llvm/ProfileData/ProfileCommon.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
@@ -2575,14 +2574,11 @@ static void WriteFunction(
auto *CalledFunction = CS.getCalledFunction();
if (CalledFunction && CalledFunction->hasName() &&
!CalledFunction->isIntrinsic()) {
- uint64_t ScaledCount = 0;
- if (HasProfileData)
- ScaledCount = getBlockProfileCount(
- BFI->getBlockFreq(&(*BB)).getFrequency(), BFI->getEntryFreq(),
- F.getEntryCount().getValue());
+ auto ScaledCount = BFI ? BFI->getBlockProfileCount(&*BB) : None;
unsigned CalleeId = VE.getValueID(
M->getValueSymbolTable().lookup(CalledFunction->getName()));
- CallGraphEdges[CalleeId] += ScaledCount;
+ CallGraphEdges[CalleeId] +=
+ (ScaledCount ? ScaledCount.getValue() : 0);
}
}
findRefEdges(&*I, VE, RefEdges, Visited);
OpenPOWER on IntegriCloud