[llvm] ca26665 - Revert "[PostOrderIterator] Store end iterator (NFC)"

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Mon May 22 13:01:37 PDT 2023


Author: Adrian Prantl
Date: 2023-05-22T13:01:23-07:00
New Revision: ca2666548085b3f4e61b1722272c4fa0eadd2d4e

URL: https://github.com/llvm/llvm-project/commit/ca2666548085b3f4e61b1722272c4fa0eadd2d4e
DIFF: https://github.com/llvm/llvm-project/commit/ca2666548085b3f4e61b1722272c4fa0eadd2d4e.diff

LOG: Revert "[PostOrderIterator] Store end iterator (NFC)"

This reverts commit 50f0ee8fbfc1f597ae7d2d49e0996c4338e5652f.

This breaks the bots.

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/lastFailedBuild/consoleFull#-1141050806a1ca8a51-895e-46c6-af87-ce24fa4cd561

Added: 
    

Modified: 
    llvm/include/llvm/ADT/PostOrderIterator.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/PostOrderIterator.h b/llvm/include/llvm/ADT/PostOrderIterator.h
index abc510714f345..a80eed78c94d1 100644
--- a/llvm/include/llvm/ADT/PostOrderIterator.h
+++ b/llvm/include/llvm/ADT/PostOrderIterator.h
@@ -106,14 +106,13 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
   using NodeRef = typename GT::NodeRef;
   using ChildItTy = typename GT::ChildIteratorType;
 
-  /// Used to maintain the ordering.
-  /// First element is basic block pointer, second is iterator for the next
-  /// child to visit, third is the end iterator.
-  SmallVector<std::tuple<NodeRef, ChildItTy, ChildItTy>, 8> VisitStack;
+  // VisitStack - Used to maintain the ordering.  Top = current block
+  // First element is basic block pointer, second is the 'next child' to visit
+  SmallVector<std::pair<NodeRef, ChildItTy>, 8> VisitStack;
 
   po_iterator(NodeRef BB) {
     this->insertEdge(std::optional<NodeRef>(), BB);
-    VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
+    VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
     traverseChild();
   }
 
@@ -122,7 +121,7 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
   po_iterator(NodeRef BB, SetType &S)
       : po_iterator_storage<SetType, ExtStorage>(S) {
     if (this->insertEdge(std::optional<NodeRef>(), BB)) {
-      VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
+      VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
       traverseChild();
     }
   }
@@ -132,14 +131,12 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
   } // End is when stack is empty.
 
   void traverseChild() {
-    while (true) {
-      auto &[ParentBB, It, End] = VisitStack.back();
-      if (It == End)
-        break;
-      NodeRef BB = *It++;
-      if (this->insertEdge(std::optional<NodeRef>(ParentBB), BB)) {
+    while (VisitStack.back().second != GT::child_end(VisitStack.back().first)) {
+      NodeRef BB = *VisitStack.back().second++;
+      if (this->insertEdge(std::optional<NodeRef>(VisitStack.back().first),
+                           BB)) {
         // If the block is not visited...
-        VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
+        VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
       }
     }
   }
@@ -161,7 +158,7 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
   }
   bool operator!=(const po_iterator &x) const { return !(*this == x); }
 
-  const NodeRef &operator*() const { return std::get<0>(VisitStack.back()); }
+  const NodeRef &operator*() const { return VisitStack.back().first; }
 
   // This is a nonstandard operator-> that dereferences the pointer an extra
   // time... so that you can actually call methods ON the BasicBlock, because
@@ -170,7 +167,7 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
   NodeRef operator->() const { return **this; }
 
   po_iterator &operator++() { // Preincrement
-    this->finishPostorder(std::get<0>(VisitStack.back()));
+    this->finishPostorder(VisitStack.back().first);
     VisitStack.pop_back();
     if (!VisitStack.empty())
       traverseChild();


        


More information about the llvm-commits mailing list