[llvm] [ControlFlowHub] Add support for switch-based guards (PR #213549)
Robert Imschweiler via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 09:00:15 PDT 2026
================
@@ -25,11 +26,19 @@ class DomTreeUpdater;
/// Given a set of branch descriptors [BB, Succ0, Succ1], create a "hub" such
/// that the control flow from each BB to a successor is now split into two
-/// edges, one from BB to the hub and another from the hub to the successor. The
-/// hub consists of a series of guard blocks, one for each outgoing block. Each
-/// guard block conditionally branches to the corresponding outgoing block, or
-/// the next guard block in the chain. These guard blocks are returned in the
-/// argument vector.
+/// edges, one from BB to the hub and another from the hub to the successor.
+/// There are two ways to configure the hub: either as a branch sled or as a
+/// single switch.
+///
+/// For the branch sled case, the hub consists of a series of guard blocks, one
+/// for each outgoing block. Each guard block conditionally branches to the
+/// corresponding outgoing block, or the next guard block in the chain. These
+/// guard blocks are returned in the argument vector `GuardBlocks`.
+///
+/// In the case of a switch guard, the hub consists only of a single guard block
+/// containing a switch instruction that branches to all outgoing blocks (with
+/// an unreachable default destination). `GuardBlocks` will contain this single
+/// guard block.
----------------
ro-i wrote:
nit: due to your `if (SwitchGuards && Outgoing.size() > 2)` check, a single block in GuardBlocks doesn't necessarily mean that this block is a switch guard. It might be a branch sled that had been created due to `Outgoing.size()` being <= 2.
https://github.com/llvm/llvm-project/pull/213549
More information about the llvm-commits
mailing list