[llvm] [ControlFlowHub] Add support for switch-based guards (PR #213549)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 03:52:54 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())) &&
----------------
hertelukas wrote:
Not sure if this is necessary - `isa<CallBrInst>` and `isa<SwitchInst>` should never evaluate to true:
```
/// Limitations:
/// -----------
/// 1. This assumes that all terminators in the CFG are direct branches (the
/// "br" instruction). The presence of any other control flow such as
/// indirectbr, switch or callbr will cause an assert.
```
And `FixIrreducible` and `UnifyLoopExits` adhere to that by running `SplitMultiBrEdge` first.
https://github.com/llvm/llvm-project/pull/213549
More information about the llvm-commits
mailing list