[PATCH] D49163: ADT: Shrink SmallVector size 0 to 16B on 64-bit platforms

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 10 17:14:43 PDT 2018


dexonsmith created this revision.
Herald added a subscriber: hiraditya.

`SmallVectorTemplateCommon` wants to know the address of the first element so it can detect whether it's in "small size" mode.

The old implementation split the small array, creating the storage for the first element in `SmallVectorTemplateCommon`, and pulling the rest into SmallVectorStorage where we know the size of the array.  This bloats `SmallVector` small-size 0 by the larger of `sizeof(void*)` and `sizeof(T)` unnecessarily.

The new implementation leaves the full small storage to `SmallVectorStorage`.  To calculate the offset of the first element in `SmallVectorTemplateCommon`, we just need to know how far to jump, which we can calculate out-of-band.  One subtlety is that we need `SmallVectorStorage` to be properly aligned even when the size is 0, to be sure that (for large alignments) we actually have the padding and it's well defined to do the pointer math.


https://reviews.llvm.org/D49163

Files:
  llvm/include/llvm/ADT/SmallVector.h
  llvm/lib/Support/SmallVector.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49163.154907.patch
Type: text/x-patch
Size: 4761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180711/f826ed7d/attachment.bin>


More information about the llvm-commits mailing list