[PATCH] D63201: [ADT] Propagate the GT parameter of RPOT into po_iterator
Alain via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 12 07:06:47 PDT 2019
alain.carlucci created this revision.
alain.carlucci added reviewers: chandlerc, espindola.
Herald added subscribers: llvm-commits, kristina, dexonsmith.
Herald added a project: LLVM.
Today I tried to run the `ReversePostOrderIterator<T, Inverse<T>>` on a graph, expecting the traversal to be applied to the inverse of the graph, but that didn't happen.
The reason is: the second template parameter (GT) of ReversePostOrderTraversal is used only to pick the entryNode of the graph G, but not to traverse the graph.
Is this an expected behavior or a bug? I noticed this does not seem to be used anywhere in clang or llvm, but besides me other projects could rely on it in the future.
With this patch, using RPOT<T, Inverse<T>> correctly iterates in the reverse post-order on the inverse of the graph.
I tested it on my use-case and it works without breaking anything in llvm, even if there are no unit tests about the ReversePostOrderTraversal. If you think it might be useful, I can add some unit tests regarding this patch to the llvm test-suite.
Repository:
rL LLVM
https://reviews.llvm.org/D63201
Files:
llvm/include/llvm/ADT/PostOrderIterator.h
Index: llvm/include/llvm/ADT/PostOrderIterator.h
===================================================================
--- llvm/include/llvm/ADT/PostOrderIterator.h
+++ llvm/include/llvm/ADT/PostOrderIterator.h
@@ -177,10 +177,19 @@
// Provide global constructors that automatically figure out correct types...
//
-template <class T>
-po_iterator<T> po_begin(const T &G) { return po_iterator<T>::begin(G); }
-template <class T>
-po_iterator<T> po_end (const T &G) { return po_iterator<T>::end(G); }
+template <class T, class GT = GraphTraits<T>>
+po_iterator<T, SmallPtrSet<typename GraphTraits<T>::NodeRef, 8>, false, GT>
+po_begin(const T &G) {
+ return po_iterator<T, SmallPtrSet<typename GraphTraits<T>::NodeRef, 8>, false,
+ GT>::begin(G);
+}
+
+template <class T, class GT = GraphTraits<T>>
+po_iterator<T, SmallPtrSet<typename GraphTraits<T>::NodeRef, 8>, false, GT>
+po_end(const T &G) {
+ return po_iterator<T, SmallPtrSet<typename GraphTraits<T>::NodeRef, 8>, false,
+ GT>::end(G);
+}
template <class T> iterator_range<po_iterator<T>> post_order(const T &G) {
return make_range(po_begin(G), po_end(G));
@@ -290,7 +299,8 @@
std::vector<NodeRef> Blocks; // Block list in normal PO order
void Initialize(NodeRef BB) {
- std::copy(po_begin(BB), po_end(BB), std::back_inserter(Blocks));
+ std::copy(po_begin<GraphT, GT>(BB), po_end<GraphT, GT>(BB),
+ std::back_inserter(Blocks));
}
public:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63201.204276.patch
Type: text/x-patch
Size: 1479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190612/5bb7bcb9/attachment.bin>
More information about the llvm-commits
mailing list