[llvm] e4dd1d0 - Add assert to avoid unexpected situation

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 18 00:23:59 PDT 2023


Author: Wang, Xin10
Date: 2023-04-18T03:23:41-04:00
New Revision: e4dd1d033063c8a669c7e77d9d7f88c1d3058e88

URL: https://github.com/llvm/llvm-project/commit/e4dd1d033063c8a669c7e77d9d7f88c1d3058e88
DIFF: https://github.com/llvm/llvm-project/commit/e4dd1d033063c8a669c7e77d9d7f88c1d3058e88.diff

LOG: Add assert to avoid unexpected situation

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h b/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
index 2290d26c0827..6d58c7a14fb9 100644
--- a/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
@@ -66,6 +66,7 @@ class MachineBlockFrequencyInfo : public MachineFunctionPass {
   /// 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());
   }
 


        


More information about the llvm-commits mailing list