[llvm-branch-commits] [llvm] [polly] [Support] Use block numbers for LoopInfo BBMap (PR #103400)

Nikita Popov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Mar 19 02:03:41 PDT 2026


================
@@ -756,14 +762,33 @@ void LoopInfoBase<BlockT, LoopT>::verify(
 
 // Verify that blocks are mapped to valid loops.
 #ifndef NDEBUG
-  for (auto &Entry : BBMap) {
-    const BlockT *BB = Entry.first;
-    LoopT *L = Entry.second;
-    assert(Loops.count(L) && "orphaned loop");
-    assert(L->contains(BB) && "orphaned block");
-    for (LoopT *ChildLoop : *L)
-      assert(!ChildLoop->contains(BB) &&
-             "BBMap should point to the innermost loop containing BB");
+  if constexpr (GraphHasNodeNumbers<const BlockT *>) {
+    for (auto It : enumerate(BBMap)) {
+      LoopT *L = It.value();
+      unsigned Number = It.index();
+      if (!L)
+        continue;
+      assert(Loops.count(L) && "orphaned loop");
+      // We have no way to map block numbers back to blocks, so find it.
+      auto BBIt = find_if(L->Blocks, [&Number](BlockT *BB) {
+        return GraphTraits<BlockT *>::getNumber(BB) == Number;
+      });
----------------
nikic wrote:

This makes the verification quadratic right?

Would it make sense to make the outer loop over blocks in the DT? (I guess we could also look up the block from the DT, which has a number -> block mapping, but exposing that is probably too hacky...)

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


More information about the llvm-branch-commits mailing list