[Mlir-commits] [clang] [llvm] [mlir] [ADT] Refactor post order traversal (PR #191047)

Nikita Popov llvmlistbot at llvm.org
Thu Apr 9 11:52:08 PDT 2026


================
@@ -186,49 +186,34 @@ class LoopBlocksRPO {
   LoopBlocksDFS::RPOIterator end() const { return DFS.endRPO(); }
 };
 
-/// Specialize po_iterator_storage to record postorder numbers.
-template<> class po_iterator_storage<LoopBlocksTraversal, true> {
-  LoopBlocksTraversal &LBT;
-public:
-  po_iterator_storage(LoopBlocksTraversal &lbs) : LBT(lbs) {}
-  // These functions are defined below.
-  bool insertEdge(std::optional<BasicBlock *> From, BasicBlock *To);
-  void finishPostorder(BasicBlock *BB);
-};
-
 /// Traverse the blocks in a loop using a depth-first search.
-class LoopBlocksTraversal {
-public:
-  /// Graph traversal iterator.
-  typedef po_iterator<BasicBlock*, LoopBlocksTraversal, true> POTIterator;
-
-private:
+class LoopBlocksTraversal
+    : public PostOrderTraversalBase<LoopBlocksTraversal,
+                                    GraphTraits<Function *>> {
   LoopBlocksDFS &DFS;
   const LoopInfo *LI;
 
 public:
-  LoopBlocksTraversal(LoopBlocksDFS &Storage, const LoopInfo *LInfo) :
-    DFS(Storage), LI(LInfo) {}
+  LoopBlocksTraversal(LoopBlocksDFS &Storage, const LoopInfo *LInfo)
+      : DFS(Storage), LI(LInfo) {}
 
   /// Postorder traversal over the graph. This only needs to be done once.
   /// po_iterator "automatically" calls back to visitPreorder and
----------------
nikic wrote:

Reference to visitPreorder outdated?

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


More information about the Mlir-commits mailing list