[llvm] [BPI] Use BasicBlock::isEHPad() to check exception handling block. (PR #95771)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 18:14:33 PDT 2024


https://github.com/Enna1 updated https://github.com/llvm/llvm-project/pull/95771

>From 264c66412905b217a82d334f204898387b928eed Mon Sep 17 00:00:00 2001
From: "xumingjie.enna1" <xumingjie.enna1 at bytedance.com>
Date: Fri, 14 Jun 2024 10:18:29 +0800
Subject: [PATCH] [BPI] Use BasicBlock::isEHPad() to check exception handling
 block.

There is no need to iterate all predecessors of current block, check if
current block is the invoke unwind destination of any predcessor.
We can directly call `BasicBlock::isEHPad()` to check if current block
is a exception handling block.
---
 llvm/lib/Analysis/BranchProbabilityInfo.cpp | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 50dcd5f45233f..3e9c60918f3c0 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -787,12 +787,9 @@ BranchProbabilityInfo::getInitialEstimatedBlockWeight(const BasicBlock *BB) {
                ? static_cast<uint32_t>(BlockExecWeight::NORETURN)
                : static_cast<uint32_t>(BlockExecWeight::UNREACHABLE);
 
-  // Check if the block is 'unwind' handler of  some invoke instruction.
-  for (const auto *Pred : predecessors(BB))
-    if (Pred)
-      if (const auto *II = dyn_cast<InvokeInst>(Pred->getTerminator()))
-        if (II->getUnwindDest() == BB)
-          return static_cast<uint32_t>(BlockExecWeight::UNWIND);
+  // Check if the block is an exception handling block.
+  if (BB->isEHPad())
+    return static_cast<uint32_t>(BlockExecWeight::UNWIND);
 
   // Check if the block contains 'cold' call.
   for (const auto &I : *BB)



More information about the llvm-commits mailing list