Revert "Revert "ADT: Fix reference invalidation in SmallVector...""
This reverts commit 33be50da, effectively reapplying: - 260a856c - 3043e5a5 - 49142991 ... with a fix to skip a call to `SmallVector::isReferenceToStorage()` when we know the parameter had been taken by value for small, POD-like `T`. See https://reviews.llvm.org/D93779 for the discussion on the revert. At a high-level, these commits fix reference invalidation in SmallVector's push_back, append, insert (one or N), and resize operations. For more details, please see the original commit messages. This commit fixes a bug that crept into `SmallVectorTemplateCommon::reserveForAndGetAddress()` during the review process after performance analysis was done. That function is now called `reserveForParamAndGetAddress()`, clarifying that it only works for parameter values. It uses that knowledge to bypass `SmallVector::isReferenceToStorage()` when `TakesParamByValue`. This is `constexpr` and avoids adding overhead for "small enough", trivially copyable `T`. Performance could potentially be tuned further by increasing the threshold for `TakesParamByValue`, which is currently defined as: ``` bool TakesParamByValue = sizeof(T) <= 2 * sizeof(void *); ``` in the POD-like version of SmallVectorTemplateBase (else, `false`). Differential Revision: https://reviews.llvm.org/D94800
Loading
Please sign in to comment