[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:28:34 PDT 2024
https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/86815
>From 43a81cbf959fc47ffbabb1741d16a790fc4694aa Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Wed, 27 Mar 2024 11:21:18 -0400
Subject: [PATCH] [clang] Compute Switch Capacity based on number of
branch-afters and fixups
---
clang/lib/CodeGen/CGCleanup.cpp | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index f87caf050eeaa7..762dddb5e0f910 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -904,17 +904,22 @@ 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);
More information about the cfe-commits
mailing list