[PATCH] D112175: [NFC] Add llvm::StaticVector ADT

James Player via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 20 13:05:08 PDT 2021


jplayer-nv created this revision.
jplayer-nv added a project: LLVM.
Herald added subscribers: dexonsmith, mgorny.
jplayer-nv requested review of this revision.
Herald added a subscriber: llvm-commits.

I have implemented `llvm::StaticVector`, which is a fixed-capacity vector class.  Think `llvm::SmallVector` without the ability to grow beyond its inline storage capacity.  The `llvm::StaticVector` is lower overhead than an `llvm::SmallVector` with similar inline storage capacity:

Class storage savings:

1. There is no data pointer; only the inline storage.
2. The Size member can have its type scaled back depending on the stated capacity to save a few bytes. For example: `sizeof(StaticVector<char,200>) == 201` since a `uint8_t` is sufficient to track the max number of elements.

Host generated code size savings:

1. Heap buffer growth related code is not generated; thus eliminating control-flow + code size on common member functions.

If the user knows the required capacity at compile-time, then a `StaticVector` would be a more efficient choice than the jack-of-all-trades `SmallVector`.  Compared to a `std::array`, there are nice properties to exploit as well.  For example, not elements are constructed when an empty `StaticVector` object is instantiated (compared to a `std::array`, which constructs all its elements when instantiated).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112175

Files:
  llvm/include/llvm/ADT/STLExtras.h
  llvm/include/llvm/ADT/STLForwardCompat.h
  llvm/include/llvm/ADT/StaticVector.h
  llvm/unittests/ADT/CMakeLists.txt
  llvm/unittests/ADT/StaticVectorTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112175.381070.patch
Type: text/x-patch
Size: 102184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211020/f4b7adb1/attachment.bin>


More information about the llvm-commits mailing list