[clang] [clang] Compute Switch Capacity based on number of branch-afters and fixups (PR #86815)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 27 08:22:34 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: AtariDreams (AtariDreams)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/86815.diff
1 Files Affected:
- (modified) clang/lib/CodeGen/CGCleanup.cpp (+13-8)
``````````diff
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index f87caf050eeaa7..c2120d1b844c6e 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -904,19 +904,24 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
(HasFixups && !HasEnclosingCleanups)) {
llvm::BasicBlock *Default =
- (BranchThroughDest ? BranchThroughDest : getUnreachableBlock());
-
- // TODO: base this on the number of branch-afters and fixups
- const unsigned SwitchCapacity = 10;
+ (BranchThroughDest ? BranchThroughDest : getUnreachableBlock());
// pass the abnormal exit flag to Fn (SEH cleanup)
cleanupFlags.setHasExitSwitch();
- llvm::LoadInst *Load =
- createLoadInstBefore(getNormalCleanupDestSlot(), "cleanup.dest",
- nullptr);
+ llvm::LoadInst *Load = createLoadInstBefore(getNormalCleanupDestSlot(),
+ "cleanup.dest", nullptr);
+
+ unsigned numBranchAfters = Scope.getNumBranchAfters();
+ unsigned numFixups = (HasFixups && !HasEnclosingCleanups)
+ ? EHStack.getNumBranchFixups() - FixupDepth
+ : 0;
+
+ // Compute Switch Capacity based on number of branch-afters and fixups.
+ const unsigned SwitchCapacity = numBranchAfters + numFixups;
+
llvm::SwitchInst *Switch =
- llvm::SwitchInst::Create(Load, Default, SwitchCapacity);
+ llvm::SwitchInst::Create(Load, Default, SwitchCapacity);
InstsToAppend.push_back(Load);
InstsToAppend.push_back(Switch);
``````````
</details>
https://github.com/llvm/llvm-project/pull/86815
More information about the cfe-commits
mailing list