[PATCH] D148606: Add assert to avoid unexpected situation

Wang, Xin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 23:23:25 PDT 2023


XinWang10 created this revision.
Herald added a project: All.
XinWang10 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In line 68, func getBlockFreqRelativeToEntryBlock assume getEntryFreq() is
non-zero, but the function could return 0, add assert to confirm it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148606

Files:
  llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h


Index: llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
+++ llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
@@ -66,6 +66,7 @@
   /// Compute the frequency of the block, relative to the entry block.
   /// This API assumes getEntryFreq() is non-zero.
   float getBlockFreqRelativeToEntryBlock(const MachineBasicBlock *MBB) const {
+    assert(getEntryFreq() != 0 && "getEntryFreq() should not return 0 here!");
     return getBlockFreq(MBB).getFrequency() * (1.0f / getEntryFreq());
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148606.514529.patch
Type: text/x-patch
Size: 626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230418/2f0e61e8/attachment.bin>


More information about the llvm-commits mailing list