[llvm] [ControlFlowHub] Add support for switch-based guards (PR #213549)

Robert Imschweiler via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 03:22:03 PDT 2026


================
@@ -279,17 +281,19 @@ static void reconnectPhis(BasicBlock *Out, BasicBlock *GuardBlock,
 
 std::pair<BasicBlock *, bool> ControlFlowHub::finalize(
     DomTreeUpdater *DTU, SmallVectorImpl<BasicBlock *> &GuardBlocks,
-    const StringRef Prefix, std::optional<unsigned> MaxControlFlowBooleans) {
+    const StringRef Prefix, std::optional<unsigned> MaxControlFlowBooleans,
+    bool SwitchGuards) {
 #ifndef NDEBUG
   SmallPtrSet<BasicBlock *, 8> Incoming;
 #endif
   SetVector<BasicBlock *> Outgoing;
 
   for (auto [BB, Succ0, Succ1] : Branches) {
 #ifndef NDEBUG
-    assert(
-        (Incoming.insert(BB).second || isa<CallBrInst>(BB->getTerminator())) &&
-        "Duplicate entry for incoming block.");
+    assert((Incoming.insert(BB).second ||
+            isa<CallBrInst>(BB->getTerminator()) ||
+            isa<SwitchInst>(BB->getTerminator())) &&
----------------
ro-i wrote:

the comment might be outdated. The issue is that you need to insert multiple edges coming from the same BB when you're dealing with multi-branches like callbr or switch.
(The comment should mention that callers need to handle those instructions using SplitMultiBrEdge)

https://github.com/llvm/llvm-project/pull/213549


More information about the llvm-commits mailing list