[PATCH] D48518: ADT: Shrink SmallVector by 8B on 64-bit platforms

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 23 08:40:28 PDT 2018


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

Shrink `sizeof(SmallVector)` by 8B on 64-bit platforms by representing size and capacity directly as `unsigned` and calculating `end()` from `begin() + size()`.

This limits the maximum size/capacity of a vector to UINT32_MAX.

A few notes:

- I haven't profiled whether there is a compile-time hit, but I'm tempted to check the bots post-commit to check for regressions since this is no more branchy than before.  Happy to be proactive if others think it's warranted.

- I noticed that `SmallVectorImpl::resetToSmall`, used by `SmallVectorImpl::operator=(SmallVectorImpl &&)`, drops the small capacity to 0.  This is a little sad so I left behind a FIXME.

- I renamed the protected member function `setEnd()` to `setSize()`.  This is uncomfortably similar in name to the public `set_size()`.  Would `setRawSize()` be better?  Or should `set_size()` just be lifted up to `SmallVectorBase`, and I audit to be sure that the size is only set after the capacity is correct?


https://reviews.llvm.org/D48518

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48518.152593.patch
Type: text/x-patch
Size: 17193 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180623/0e92b44d/attachment.bin>


More information about the llvm-commits mailing list