[llvm] 18a9209 - Reapply [PostOrderIterator] Store end iterator (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue May 23 05:16:41 PDT 2023
Author: Nikita Popov
Date: 2023-05-23T14:16:31+02:00
New Revision: 18a920978f9da47247b4cbd47615247a09cd0d48
URL: https://github.com/llvm/llvm-project/commit/18a920978f9da47247b4cbd47615247a09cd0d48
DIFF: https://github.com/llvm/llvm-project/commit/18a920978f9da47247b4cbd47615247a09cd0d48.diff
LOG: Reapply [PostOrderIterator] Store end iterator (NFC)
Replace structured bindings with std::get, as they apparently
break the modules build.
-----
Store the end iterator on the VisitStack, instead of recomputing
it every time, as doing so is not free.
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 a80eed78c94d1..73f6feaf1919c 100644
--- a/llvm/include/llvm/ADT/PostOrderIterator.h
+++ b/llvm/include/llvm/ADT/PostOrderIterator.h
@@ -106,13 +106,14 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
using NodeRef = typename GT::NodeRef;
using ChildItTy = typename GT::ChildIteratorType;
- // 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;
+ /// 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;
po_iterator(NodeRef BB) {
this->insertEdge(std::optional<NodeRef>(), BB);
- VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
+ VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
traverseChild();
}
@@ -121,7 +122,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.push_back(std::make_pair(BB, GT::child_begin(BB)));
+ VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
traverseChild();
}
}
@@ -131,12 +132,14 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
} // End is when stack is empty.
void traverseChild() {
- 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)) {
+ while (true) {
+ auto &Entry = VisitStack.back();
+ if (std::get<1>(Entry) == std::get<2>(Entry))
+ break;
+ NodeRef BB = *std::get<1>(Entry)++;
+ if (this->insertEdge(std::optional<NodeRef>(std::get<0>(Entry)), BB)) {
// If the block is not visited...
- VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
+ VisitStack.emplace_back(BB, GT::child_begin(BB), GT::child_end(BB));
}
}
}
@@ -158,7 +161,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 VisitStack.back().first; }
+ const NodeRef &operator*() const { return std::get<0>(VisitStack.back()); }
// This is a nonstandard operator-> that dereferences the pointer an extra
// time... so that you can actually call methods ON the BasicBlock, because
@@ -167,7 +170,7 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
NodeRef operator->() const { return **this; }
po_iterator &operator++() { // Preincrement
- this->finishPostorder(VisitStack.back().first);
+ this->finishPostorder(std::get<0>(VisitStack.back()));
VisitStack.pop_back();
if (!VisitStack.empty())
traverseChild();
More information about the llvm-commits
mailing list