Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2024

Conversation

Enna1
Copy link
Contributor

@Enna1 Enna1 commented Jun 17, 2024

There is no need to iterate all predecessors of current block, check if current block is the invoke unwind destination of any predecessor. We can directly call BasicBlock::isEHPad() to check if current block is an 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.
@Enna1 Enna1 force-pushed the users/Enna1/BPI-use-isEHPad branch from 70de505 to 264c664 Compare June 17, 2024 13:18
@Enna1 Enna1 marked this pull request as ready for review June 17, 2024 15:22
@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2024

@llvm/pr-subscribers-llvm-analysis

Author: Enna1 (Enna1)

Changes

There is no need to iterate all predecessors of current block, check if current block is the invoke unwind destination of any predecessor. We can directly call BasicBlock::isEHPad() to check if current block is an exception handling block.


Full diff: https://github.com/llvm/llvm-project/pull/95771.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/BranchProbabilityInfo.cpp (+3-6)
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)

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Enna1 Enna1 merged commit 8f49dab into main Jun 24, 2024
7 checks passed
@Enna1 Enna1 deleted the users/Enna1/BPI-use-isEHPad branch June 24, 2024 01:45
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
…lvm#95771)

There is no need to iterate all predecessors of current block, check if
current block is the invoke unwind destination of any predecessor. We
can directly call `BasicBlock::isEHPad()` to check if current block is
an exception handling block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants