[llvm] [WebAssembly] Replace Reachability with SCCs in Irreducible CFG Fixer (PR #179722)
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 14 06:35:13 PST 2026
================
@@ -120,65 +113,138 @@ class ReachabilityGraph {
assert(I != LoopEnterers.end());
return I->second;
}
+ unsigned getSCCId(MachineBasicBlock *MBB) const {
+ return SccId[getIndex(MBB)];
+ }
private:
MachineBasicBlock *Entry;
const BlockSet &Blocks;
+ DenseMap<MachineBasicBlock *, unsigned> BlockIndex;
BlockSet Loopers, LoopEntries;
DenseMap<MachineBasicBlock *, BlockSet> LoopEnterers;
bool inRegion(MachineBasicBlock *MBB) const { return Blocks.count(MBB); }
- // Maps a block to all the other blocks it can reach.
- DenseMap<MachineBasicBlock *, BlockSet> Reachable;
+ // Per-node adjacency in the region (excluding edges to Entry).
+ SmallVector<SmallVector<unsigned, 4>, 0> Succs;
+ SmallVector<bool, 0> SelfLoop;
+
+ // SCC = Strongly-connected component
+ // Map of an MBB's index (provided by `BlockIndex`) to it's assigned SCC
+ SmallVector<unsigned, 0> SccId;
+ // The number of elements in each SCC
+ SmallVector<unsigned, 0> SccSize;
+
+ unsigned getIndex(MachineBasicBlock *MBB) const {
+ auto It = BlockIndex.find(MBB);
+ assert(It != BlockIndex.end());
+ return It->second;
+ }
void calculate() {
- // Reachability computation work list. Contains pairs of recent additions
- // (A, B) where we just added a link A => B.
- using BlockPair = std::pair<MachineBasicBlock *, MachineBasicBlock *>;
- SmallVector<BlockPair, 4> WorkList;
+ auto NumBlocks = Blocks.size();
+ Succs.assign(NumBlocks, {});
+ SelfLoop.assign(NumBlocks, false);
+
+ unsigned MMBIdx = 0;
----------------
aheejin wrote:
Was this meant to be `MBBIdx`?
https://github.com/llvm/llvm-project/pull/179722
More information about the llvm-commits
mailing list