summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorEaswaran Raman <eraman@google.com>2016-03-23 18:18:26 +0000
committerEaswaran Raman <eraman@google.com>2016-03-23 18:18:26 +0000
commit12b79aa0f1b7aa6e792a0b65d219a969f4ea8f0b (patch)
tree8661b501acc2524157130488c0e91e2797d73f58 /llvm/lib/Analysis
parentd1728f0e5f5f4ab236febf2ae96949a974dca83a (diff)
downloadbcm5719-llvm-12b79aa0f1b7aa6e792a0b65d219a969f4ea8f0b.tar.gz
bcm5719-llvm-12b79aa0f1b7aa6e792a0b65d219a969f4ea8f0b.zip
Add getBlockProfileCount method to BlockFrequencyInfo
Differential Revision: http://reviews.llvm.org/D18233 llvm-svn: 264179
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/BlockFrequencyInfo.cpp14
1 files changed, 14 insertions, 0 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");
OpenPOWER on IntegriCloud