[PATCH] D104024: [llvm] remove Sequence::asSmallVector()

Arthur O'Dwyer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 10 08:27:32 PDT 2021


Quuxplusone accepted this revision.
Quuxplusone added inline comments.
This revision is now accepted and ready to land.


================
Comment at: mlir/lib/Conversion/PDLToPDLInterp/PDLToPDLInterp.cpp:385-386
     // Order the children such that the cases are in reverse numerical order.
-    SmallVector<unsigned> sortedChildren =
-        llvm::seq<unsigned>(0, switchNode->getChildren().size())
-            .asSmallVector();
+    SmallVector<unsigned> sortedChildren = llvm::to_vector<16>(
+        llvm::seq<unsigned>(0, switchNode->getChildren().size()));
     llvm::sort(sortedChildren, [&](unsigned lhs, unsigned rhs) {
----------------
The `<16>` here confuses me. I think `to_vector` should just figure out the appropriate small-buffer capacity, the same way `SmallVector` itself does. I think the way to do that would be to add this diff in SmallVector.h:
```
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -1249,6 +1249,13 @@ to_vector(R &&Range) {
   return {std::begin(Range), std::end(Range)};
 }
 
+template <typename R>
+SmallVector<typename std::remove_const<typename std::remove_reference<
+                decltype(*std::begin(std::declval<R &>()))>::type>::type>
+to_vector(R &&Range) {
+  return {std::begin(Range), std::end(Range)};
+}
+
 } // end namespace llvm
```
It would be reasonable, but not strictly necessary, to then audit the codebase for places where `llvm::to_vector<N>(r)` is called with a template argument, and update them to call just `llvm::to_vector(r)`. If you were to do that, presumably it'd be in a separate (and unfortunately massive) PR.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104024/new/

https://reviews.llvm.org/D104024



More information about the llvm-commits mailing list