Add assert to avoid unexpected situation
authorWang, Xin10 <xin10.wang@intel.com>
Tue, 18 Apr 2023 06:49:18 +0000 (02:49 -0400)
committerWang, Xin10 <xin10.wang@intel.com>
Tue, 18 Apr 2023 07:23:41 +0000 (03:23 -0400)
In line 68, func getBlockFreqRelativeToEntryBlock assume getEntryFreq() is
non-zero, but the function could return 0, add assert to confirm it.

Reviewed By: HaohaiWen

Differential Revision: https://reviews.llvm.org/D148606

llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h

index 2290d26..6d58c7a 100644 (file)
@@ -66,6 +66,7 @@ public:
   /// 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());
   }