Skip to content

Commit ca26665

Browse files
committed
Revert "[PostOrderIterator] Store end iterator (NFC)"
This reverts commit 50f0ee8. This breaks the bots. https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/lastFailedBuild/consoleFull#-1141050806a1ca8a51-895e-46c6-af87-ce24fa4cd561
1 parent 4907649 commit ca26665

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

llvm/include/llvm/ADT/PostOrderIterator.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,13 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
106106
using NodeRef = typename GT::NodeRef;
107107
using ChildItTy = typename GT::ChildIteratorType;
108108

109-
/// Used to maintain the ordering.
110-
/// First element is basic block pointer, second is iterator for the next
111-
/// child to visit, third is the end iterator.
112-
SmallVector<std::tuple<NodeRef, ChildItTy, ChildItTy>, 8> VisitStack;
109+
// VisitStack - Used to maintain the ordering. Top = current block
110+
// First element is basic block pointer, second is the 'next child' to visit
111+
SmallVector<std::pair<NodeRef, ChildItTy>, 8> VisitStack;
113112

114113
po_iterator(NodeRef BB) {
115114
this->insertEdge(std::optional<NodeRef>(), BB);
116-
VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
115+
VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
117116
traverseChild();
118117
}
119118

@@ -122,7 +121,7 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
122121
po_iterator(NodeRef BB, SetType &S)
123122
: po_iterator_storage<SetType, ExtStorage>(S) {
124123
if (this->insertEdge(std::optional<NodeRef>(), BB)) {
125-
VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
124+
VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
126125
traverseChild();
127126
}
128127
}
@@ -132,14 +131,12 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
132131
} // End is when stack is empty.
133132

134133
void traverseChild() {
135-
while (true) {
136-
auto &[ParentBB, It, End] = VisitStack.back();
137-
if (It == End)
138-
break;
139-
NodeRef BB = *It++;
140-
if (this->insertEdge(std::optional<NodeRef>(ParentBB), BB)) {
134+
while (VisitStack.back().second != GT::child_end(VisitStack.back().first)) {
135+
NodeRef BB = *VisitStack.back().second++;
136+
if (this->insertEdge(std::optional<NodeRef>(VisitStack.back().first),
137+
BB)) {
141138
// If the block is not visited...
142-
VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
139+
VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
143140
}
144141
}
145142
}
@@ -161,7 +158,7 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
161158
}
162159
bool operator!=(const po_iterator &x) const { return !(*this == x); }
163160

164-
const NodeRef &operator*() const { return std::get<0>(VisitStack.back()); }
161+
const NodeRef &operator*() const { return VisitStack.back().first; }
165162

166163
// This is a nonstandard operator-> that dereferences the pointer an extra
167164
// 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> {
170167
NodeRef operator->() const { return **this; }
171168

172169
po_iterator &operator++() { // Preincrement
173-
this->finishPostorder(std::get<0>(VisitStack.back()));
170+
this->finishPostorder(VisitStack.back().first);
174171
VisitStack.pop_back();
175172
if (!VisitStack.empty())
176173
traverseChild();

0 commit comments

Comments
 (0)