[PATCH] D11104: Add setBlockFreq interface to BlockFrequencyInfo, BlockFrequencyInfoImplBase, and BlockFrequencyInfoImpl.

Cong Hou congh at google.com
Fri Jul 10 11:26:26 PDT 2015


congh created this revision.
congh added reviewers: dexonsmith, davidxl.
congh added subscribers: llvm-commits, davidxl.

This patch make it possible to directly change the block frequency through BFI instead of updating block frequencies for the whole function (which is relatively expensive). This is useful when there are small local frequency changes and the up-to-date BFI is needed soon.

http://reviews.llvm.org/D11104

Files:
  include/llvm/Analysis/BlockFrequencyInfo.h
  include/llvm/Analysis/BlockFrequencyInfoImpl.h
  lib/Analysis/BlockFrequencyInfo.cpp
  lib/Analysis/BlockFrequencyInfoImpl.cpp

Index: lib/Analysis/BlockFrequencyInfoImpl.cpp
===================================================================
--- lib/Analysis/BlockFrequencyInfoImpl.cpp
+++ lib/Analysis/BlockFrequencyInfoImpl.cpp
@@ -527,6 +527,14 @@
   return Freqs[Node.Index].Scaled;
 }
 
+bool BlockFrequencyInfoImplBase::setBlockFreq(const BlockNode &Node,
+                                              uint64_t Freq) {
+  if (!Node.isValid())
+    return false;
+  Freqs[Node.Index].Integer = Freq;
+  return true;
+}
+
 std::string
 BlockFrequencyInfoImplBase::getBlockName(const BlockNode &Node) const {
   return std::string();
Index: lib/Analysis/BlockFrequencyInfo.cpp
===================================================================
--- lib/Analysis/BlockFrequencyInfo.cpp
+++ lib/Analysis/BlockFrequencyInfo.cpp
@@ -150,6 +150,11 @@
   return BFI ? BFI->getBlockFreq(BB) : 0;
 }
 
+bool BlockFrequencyInfo::setBlockFreq(const BasicBlock *BB,
+                                      uint64_t Freq) {
+  return BFI ? BFI->setBlockFreq(BB, Freq) : false;
+}
+
 /// Pop up a ghostview window with the current block frequency propagation
 /// rendered using dot.
 void BlockFrequencyInfo::view() const {
Index: include/llvm/Analysis/BlockFrequencyInfoImpl.h
===================================================================
--- include/llvm/Analysis/BlockFrequencyInfoImpl.h
+++ include/llvm/Analysis/BlockFrequencyInfoImpl.h
@@ -456,6 +456,8 @@
 
   BlockFrequency getBlockFreq(const BlockNode &Node) const;
 
+  bool setBlockFreq(const BlockNode &Node, uint64_t Freq);
+
   raw_ostream &printBlockFreq(raw_ostream &OS, const BlockNode &Node) const;
   raw_ostream &printBlockFreq(raw_ostream &OS,
                               const BlockFrequency &Freq) const;
@@ -886,6 +888,9 @@
   BlockFrequency getBlockFreq(const BlockT *BB) const {
     return BlockFrequencyInfoImplBase::getBlockFreq(getNode(BB));
   }
+  bool setBlockFreq(const BlockT *BB, uint64_t Freq) {
+    return BlockFrequencyInfoImplBase::setBlockFreq(getNode(BB), Freq);
+  }
   Scaled64 getFloatingBlockFreq(const BlockT *BB) const {
     return BlockFrequencyInfoImplBase::getFloatingBlockFreq(getNode(BB));
   }
Index: include/llvm/Analysis/BlockFrequencyInfo.h
===================================================================
--- include/llvm/Analysis/BlockFrequencyInfo.h
+++ include/llvm/Analysis/BlockFrequencyInfo.h
@@ -51,6 +51,10 @@
   /// floating points.
   BlockFrequency getBlockFreq(const BasicBlock *BB) const;
 
+  // Set the frequency of the given basic block. Return true if it succeeds and
+  // false otherwise.
+  bool setBlockFreq(const BasicBlock *BB, uint64_t Freq);
+
   // Print the block frequency Freq to OS using the current functions entry
   // frequency to convert freq into a relative decimal form.
   raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11104.29463.patch
Type: text/x-patch
Size: 2876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150710/6cb00442/attachment.bin>


More information about the llvm-commits mailing list