[llvm] 8b6d1c0 - [ADT] Use alignas + sizeof for inline storage, NFC
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 19 22:25:10 PDT 2020
FWIW, I think there's some value in using a utility here - saves writing
the same type T twice, possibly having them get out of sync, Bit more
readable by using a named construct for what's being done, etc.
On Wed, Oct 14, 2020 at 4:16 PM Reid Kleckner via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
>
> Author: Reid Kleckner
> Date: 2020-10-14T16:16:02-07:00
> New Revision: 8b6d1c0467b2dfa14cb2d2dec7637bf95c78364b
>
> URL:
> https://github.com/llvm/llvm-project/commit/8b6d1c0467b2dfa14cb2d2dec7637bf95c78364b
> DIFF:
> https://github.com/llvm/llvm-project/commit/8b6d1c0467b2dfa14cb2d2dec7637bf95c78364b.diff
>
> LOG: [ADT] Use alignas + sizeof for inline storage, NFC
>
> AlignedCharArrayUnion is really only needed to handle the "union" case
> when we need memory of suitable size and alignment for multiple types.
> SmallVector only needs storage for one type, so use that directly.
>
> Added:
>
>
> Modified:
> clang/include/clang/AST/APValue.h
> llvm/include/llvm/ADT/SmallVector.h
> llvm/include/llvm/ADT/iterator_range.h
>
> Removed:
>
>
>
>
> ################################################################################
> diff --git a/clang/include/clang/AST/APValue.h
> b/clang/include/clang/AST/APValue.h
> index ac8ed0818af0..5eb1f68f7690 100644
> --- a/clang/include/clang/AST/APValue.h
> +++ b/clang/include/clang/AST/APValue.h
> @@ -17,9 +17,10 @@
> #include "llvm/ADT/APFixedPoint.h"
> #include "llvm/ADT/APFloat.h"
> #include "llvm/ADT/APSInt.h"
> +#include "llvm/ADT/FoldingSet.h"
> #include "llvm/ADT/PointerIntPair.h"
> #include "llvm/ADT/PointerUnion.h"
> -#include "llvm/ADT/FoldingSet.h"
> +#include "llvm/Support/AlignOf.h"
>
> namespace clang {
> class AddrLabelExpr;
>
> diff --git a/llvm/include/llvm/ADT/SmallVector.h
> b/llvm/include/llvm/ADT/SmallVector.h
> index c3c6a366dab2..dd5cd9531ded 100644
> --- a/llvm/include/llvm/ADT/SmallVector.h
> +++ b/llvm/include/llvm/ADT/SmallVector.h
> @@ -14,7 +14,6 @@
> #define LLVM_ADT_SMALLVECTOR_H
>
> #include "llvm/ADT/iterator_range.h"
> -#include "llvm/Support/AlignOf.h"
> #include "llvm/Support/Compiler.h"
> #include "llvm/Support/ErrorHandling.h"
> #include "llvm/Support/MathExtras.h"
> @@ -97,8 +96,9 @@ using SmallVectorSizeType =
>
> /// Figure out the offset of the first element.
> template <class T, typename = void> struct SmallVectorAlignmentAndSize {
> - AlignedCharArrayUnion<SmallVectorBase<SmallVectorSizeType<T>>> Base;
> - AlignedCharArrayUnion<T> FirstEl;
> + alignas(SmallVectorBase<SmallVectorSizeType<T>>) char Base[sizeof(
> + SmallVectorBase<SmallVectorSizeType<T>>)];
> + alignas(T) char FirstEl[sizeof(T)];
> };
>
> /// This is the part of SmallVectorTemplateBase which does not depend on
> whether
> @@ -870,13 +870,13 @@ SmallVectorImpl<T>
> &SmallVectorImpl<T>::operator=(SmallVectorImpl<T> &&RHS) {
> /// to avoid allocating unnecessary storage.
> template <typename T, unsigned N>
> struct SmallVectorStorage {
> - AlignedCharArrayUnion<T> InlineElts[N];
> + alignas(T) char InlineElts[N * sizeof(T)];
> };
>
> /// We need the storage to be properly aligned even for small-size of 0
> so that
> /// the pointer math in \a SmallVectorTemplateCommon::getFirstEl() is
> /// well-defined.
> -template <typename T> struct alignas(alignof(T)) SmallVectorStorage<T, 0>
> {};
> +template <typename T> struct alignas(T) SmallVectorStorage<T, 0> {};
>
> /// This is a 'vector' (really, a variable-sized array), optimized
> /// for the case when the array is small. It contains some number of
> elements
>
> diff --git a/llvm/include/llvm/ADT/iterator_range.h
> b/llvm/include/llvm/ADT/iterator_range.h
> index f038f6bf2128..a9b46a3aa45b 100644
> --- a/llvm/include/llvm/ADT/iterator_range.h
> +++ b/llvm/include/llvm/ADT/iterator_range.h
> @@ -18,7 +18,6 @@
> #ifndef LLVM_ADT_ITERATOR_RANGE_H
> #define LLVM_ADT_ITERATOR_RANGE_H
>
> -#include <iterator>
> #include <utility>
>
> namespace llvm {
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201019/c2af8d38/attachment.html>
More information about the llvm-commits
mailing list