summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ADT/PostOrderIterator.h27
1 files changed, 12 insertions, 15 deletions
diff --git a/llvm/include/llvm/ADT/PostOrderIterator.h b/llvm/include/llvm/ADT/PostOrderIterator.h
index abc510714f34..a80eed78c94d 100644
--- a/llvm/include/llvm/ADT/PostOrderIterator.h
+++ b/llvm/include/llvm/ADT/PostOrderIterator.h
@@ -106,14 +106,13 @@ private:
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 @@ private:
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 @@ private:
} // 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 @@ public:
}
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 @@ public:
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();