[PATCH] D87802: [MBFIWrapper] Add a new function getBlockProfileCount

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 15:58:44 PDT 2020


Carrot created this revision.
Carrot added reviewers: davidxl, xur.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Carrot requested review of this revision.

MBFIWrapper keeps track of block frequencies of newly created blocks and modified blocks, modified block frequencies should also impact block profile count. This class doesn't provide interface getBlockProfileCount, users can only use the underlying MBFI to query profile count, the underlying MBFI doesn't know the modifications made in MBFIWrapper, so it either provides stale profile count for modified block or simply crashes on new blocks.

So this patch add function getBlockProfileCount to class MBFIWrapper to handle new blocks or modified blocks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87802

Files:
  llvm/include/llvm/CodeGen/MBFIWrapper.h
  llvm/lib/CodeGen/MBFIWrapper.cpp
  llvm/lib/CodeGen/MachineBlockPlacement.cpp


Index: llvm/lib/CodeGen/MachineBlockPlacement.cpp
===================================================================
--- llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -418,7 +418,7 @@
   /// The return value is used to model tail duplication cost.
   BlockFrequency getBlockCountOrFrequency(const MachineBasicBlock *BB) {
     if (UseProfileCount) {
-      auto Count = MBFI->getMBFI().getBlockProfileCount(BB);
+      auto Count = MBFI->getBlockProfileCount(BB);
       if (Count)
         return *Count;
       else
Index: llvm/lib/CodeGen/MBFIWrapper.cpp
===================================================================
--- llvm/lib/CodeGen/MBFIWrapper.cpp
+++ llvm/lib/CodeGen/MBFIWrapper.cpp
@@ -30,6 +30,16 @@
   MergedBBFreq[MBB] = F;
 }
 
+Optional<uint64_t> MBFIWrapper::getBlockProfileCount(
+    const MachineBasicBlock *MBB) const {
+  auto I = MergedBBFreq.find(MBB);
+
+  if (I != MergedBBFreq.end())
+    return MBFI.getProfileCountFromFreq(I->second.getFrequency());
+
+  return MBFI.getBlockProfileCount(MBB);
+}
+
 raw_ostream & MBFIWrapper::printBlockFreq(raw_ostream &OS,
                                           const MachineBasicBlock *MBB) const {
   return MBFI.printBlockFreq(OS, getBlockFreq(MBB));
Index: llvm/include/llvm/CodeGen/MBFIWrapper.h
===================================================================
--- llvm/include/llvm/CodeGen/MBFIWrapper.h
+++ llvm/include/llvm/CodeGen/MBFIWrapper.h
@@ -28,6 +28,8 @@
 
   BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
   void setBlockFreq(const MachineBasicBlock *MBB, BlockFrequency F);
+  Optional<uint64_t> getBlockProfileCount(const MachineBasicBlock *MBB) const;
+
   raw_ostream &printBlockFreq(raw_ostream &OS,
                               const MachineBasicBlock *MBB) const;
   raw_ostream &printBlockFreq(raw_ostream &OS,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87802.292365.patch
Type: text/x-patch
Size: 1885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200916/3d661883/attachment.bin>


More information about the llvm-commits mailing list