From: Xinliang David Li Date: Wed, 22 Jun 2016 17:12:12 +0000 (+0000) Subject: [BFI]: NFC refactoring X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f4f1f640d2b5abf8e8f1cade3d42d4f02b75b89;p=llvm [BFI]: NFC refactoring move getBlockProfileCount implementation to the base class so that MBFI can share too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273442 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/include/llvm/Analysis/BlockFrequencyInfoImpl.h index ea04049cd56..34739360a65 100644 --- a/include/llvm/Analysis/BlockFrequencyInfoImpl.h +++ b/include/llvm/Analysis/BlockFrequencyInfoImpl.h @@ -16,6 +16,7 @@ #define LLVM_ANALYSIS_BLOCKFREQUENCYINFOIMPL_H #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/iterator_range.h" #include "llvm/IR/BasicBlock.h" @@ -476,6 +477,8 @@ public: Scaled64 getFloatingBlockFreq(const BlockNode &Node) const; BlockFrequency getBlockFreq(const BlockNode &Node) const; + Optional getBlockProfileCount(const Function &F, + const BlockNode &Node) const; void setBlockFreq(const BlockNode &Node, uint64_t Freq); @@ -915,6 +918,10 @@ public: BlockFrequency getBlockFreq(const BlockT *BB) const { return BlockFrequencyInfoImplBase::getBlockFreq(getNode(BB)); } + Optional getBlockProfileCount(const Function &F, + const BlockT *BB) const { + return BlockFrequencyInfoImplBase::getBlockProfileCount(F, getNode(BB)); + } void setBlockFreq(const BlockT *BB, uint64_t Freq); Scaled64 getFloatingBlockFreq(const BlockT *BB) const { return BlockFrequencyInfoImplBase::getFloatingBlockFreq(getNode(BB)); diff --git a/lib/Analysis/BlockFrequencyInfo.cpp b/lib/Analysis/BlockFrequencyInfo.cpp index a0c472d7c72..ac7f6e28b3d 100644 --- a/lib/Analysis/BlockFrequencyInfo.cpp +++ b/lib/Analysis/BlockFrequencyInfo.cpp @@ -140,20 +140,13 @@ BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const { Optional BlockFrequencyInfo::getBlockProfileCount(const BasicBlock *BB) const { - auto EntryCount = getFunction()->getEntryCount(); - if (!EntryCount) + if (!BFI) 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(); + + return BFI->getBlockProfileCount(*getFunction(), BB); } -void BlockFrequencyInfo::setBlockFreq(const BasicBlock *BB, - uint64_t Freq) { +void BlockFrequencyInfo::setBlockFreq(const BasicBlock *BB, uint64_t Freq) { assert(BFI && "Expected analysis to be available"); BFI->setBlockFreq(BB, Freq); } diff --git a/lib/Analysis/BlockFrequencyInfoImpl.cpp b/lib/Analysis/BlockFrequencyInfoImpl.cpp index fba82076ac2..90bc249bcb3 100644 --- a/lib/Analysis/BlockFrequencyInfoImpl.cpp +++ b/lib/Analysis/BlockFrequencyInfoImpl.cpp @@ -13,6 +13,7 @@ #include "llvm/Analysis/BlockFrequencyInfoImpl.h" #include "llvm/ADT/SCCIterator.h" +#include "llvm/IR/Function.h" #include "llvm/Support/raw_ostream.h" #include @@ -529,6 +530,21 @@ BlockFrequencyInfoImplBase::getBlockFreq(const BlockNode &Node) const { return Freqs[Node.Index].Integer; } +Optional +BlockFrequencyInfoImplBase::getBlockProfileCount(const Function &F, + const BlockNode &Node) const { + auto EntryCount = F.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(Node).getFrequency()); + APInt EntryFreq(128, getEntryFreq()); + BlockCount *= BlockFreq; + BlockCount = BlockCount.udiv(EntryFreq); + return BlockCount.getLimitedValue(); +} + Scaled64 BlockFrequencyInfoImplBase::getFloatingBlockFreq(const BlockNode &Node) const { if (!Node.isValid())