diff options
author | Easwaran Raman <eraman@google.com> | 2017-01-19 18:53:16 +0000 |
---|---|---|
committer | Easwaran Raman <eraman@google.com> | 2017-01-19 18:53:16 +0000 |
commit | 6c8f511f82805a2520175115d3648e7e1dbf0009 (patch) | |
tree | c30ea7c77b032ae6f11e850061b573481a46f693 /llvm/lib/Analysis/BlockFrequencyInfo.cpp | |
parent | 2ef8c4e708f189e5bc80af63e9ecb36fa68acff2 (diff) | |
download | bcm5719-llvm-6c8f511f82805a2520175115d3648e7e1dbf0009.tar.gz bcm5719-llvm-6c8f511f82805a2520175115d3648e7e1dbf0009.zip |
Add an interface to scale the frequencies of a set of blocks.
The scaling is done with reference to the the new frequency of a reference block.
Differential Revision: https://reviews.llvm.org/D28535
llvm-svn: 292507
Diffstat (limited to 'llvm/lib/Analysis/BlockFrequencyInfo.cpp')
-rw-r--r-- | llvm/lib/Analysis/BlockFrequencyInfo.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/BlockFrequencyInfo.cpp b/llvm/lib/Analysis/BlockFrequencyInfo.cpp index 9c1c9667a67..1c4e28f20ca 100644 --- a/llvm/lib/Analysis/BlockFrequencyInfo.cpp +++ b/llvm/lib/Analysis/BlockFrequencyInfo.cpp @@ -180,6 +180,28 @@ void BlockFrequencyInfo::setBlockFreq(const BasicBlock *BB, uint64_t Freq) { BFI->setBlockFreq(BB, Freq); } +void BlockFrequencyInfo::setBlockFreqAndScale( + const BasicBlock *ReferenceBB, uint64_t Freq, + SmallPtrSetImpl<BasicBlock *> &BlocksToScale) { + assert(BFI && "Expected analysis to be available"); + // Use 128 bits APInt to avoid overflow. + APInt NewFreq(128, Freq); + APInt OldFreq(128, BFI->getBlockFreq(ReferenceBB).getFrequency()); + APInt BBFreq(128, 0); + for (auto *BB : BlocksToScale) { + BBFreq = BFI->getBlockFreq(BB).getFrequency(); + // Multiply first by NewFreq and then divide by OldFreq + // to minimize loss of precision. + BBFreq *= NewFreq; + // udiv is an expensive operation in the general case. If this ends up being + // 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(ReferenceBB, Freq); +} + /// Pop up a ghostview window with the current block frequency propagation /// rendered using dot. void BlockFrequencyInfo::view() const { |