[PATCH] D74511: [BFI] Fix missed BFI updates in MachineSink.

Hiroshi Yamauchi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 15:27:13 PST 2020


yamauchi created this revision.
yamauchi added a reviewer: davidxl.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

This prevents BFI queries on new blocks (from
MachineSinking::GetAllSortedSuccessors) and fixes a bunch of assert failures
under -check-bfi-unknown-block-queries=true.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74511

Files:
  llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
  llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
  llvm/lib/CodeGen/MachineSink.cpp


Index: llvm/lib/CodeGen/MachineSink.cpp
===================================================================
--- llvm/lib/CodeGen/MachineSink.cpp
+++ llvm/lib/CodeGen/MachineSink.cpp
@@ -91,7 +91,7 @@
     MachineDominatorTree *DT;      // Machine dominator tree
     MachinePostDominatorTree *PDT; // Machine post dominator tree
     MachineLoopInfo *LI;
-    const MachineBlockFrequencyInfo *MBFI;
+    MachineBlockFrequencyInfo *MBFI;
     const MachineBranchProbabilityInfo *MBPI;
     AliasAnalysis *AA;
 
@@ -351,6 +351,11 @@
                           << printMBBReference(*Pair.first) << " -- "
                           << printMBBReference(*NewSucc) << " -- "
                           << printMBBReference(*Pair.second) << '\n');
+        if (MBFI) {
+          auto NewSuccFreq = MBFI->getBlockFreq(Pair.first) *
+                             MBPI->getEdgeProbability(Pair.first, NewSucc);
+          MBFI->setBlockFreq(NewSucc, NewSuccFreq.getFrequency());
+        }
         MadeChange = true;
         ++NumSplit;
       } else
Index: llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
===================================================================
--- llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
+++ llvm/lib/CodeGen/MachineBlockFrequencyInfo.cpp
@@ -247,6 +247,12 @@
   return MBFI->isIrrLoopHeader(MBB);
 }
 
+void MachineBlockFrequencyInfo::setBlockFreq(const MachineBasicBlock *MBB,
+                                             uint64_t Freq) {
+  assert(MBFI && "Expected analysis to be available");
+  MBFI->setBlockFreq(MBB, Freq);
+}
+
 const MachineFunction *MachineBlockFrequencyInfo::getFunction() const {
   return MBFI ? MBFI->getFunction() : nullptr;
 }
Index: llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
+++ llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
@@ -66,6 +66,8 @@
 
   bool isIrrLoopHeader(const MachineBasicBlock *MBB);
 
+  void setBlockFreq(const MachineBasicBlock *MBB, uint64_t Freq);
+
   const MachineFunction *getFunction() const;
   const MachineBranchProbabilityInfo *getMBPI() const;
   void view(const Twine &Name, bool isSimple = true) const;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74511.244287.patch
Type: text/x-patch
Size: 2246 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200212/79a193c2/attachment.bin>


More information about the llvm-commits mailing list