diff options
author | Bruno Ricci <riccibrun@gmail.com> | 2018-08-15 16:28:58 +0000 |
---|---|---|
committer | Bruno Ricci <riccibrun@gmail.com> | 2018-08-15 16:28:58 +0000 |
commit | 36208c914a98635319a7fd38a8666755622c36f9 (patch) | |
tree | cd21f6a2f866c5da6b7949a9ec951d47bf8c9672 | |
parent | 56915a64116b6e236c72b9338f784ac0cda3e2d3 (diff) |
[AST] Pack the unsigned of PackExpansionType into Type
The bit-fields of `Type` have enough space for
the `unsigned NumExpansions` of `PackExpansionType`
Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D50711
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339789 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Type.h | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 617ea772d0..9580f39a5e 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1624,6 +1624,25 @@ protected: unsigned NumArgs; }; + class PackExpansionTypeBitfields { + friend class PackExpansionType; + + unsigned : NumTypeBits; + + /// The number of expansions that this pack expansion will + /// generate when substituted (+1), which is expected to be able to + /// hold at least 1024 according to [implimits]. However, as this limit + /// is somewhat easy to hit with template metaprogramming we'd prefer to + /// keep it as large as possible. At the moment it has been left as a + /// non-bitfield since this type safely fits in 64 bits as an unsigned, so + /// there is no reason to introduce the performance impact of a bitfield. + /// + /// This field will only have a non-zero value when some of the parameter + /// packs that occur within the pattern have been substituted but others + /// have not. + unsigned NumExpansions; + }; + union { TypeBitfields TypeBits; ArrayTypeBitfields ArrayTypeBits; @@ -1636,6 +1655,7 @@ protected: TypeWithKeywordBitfields TypeWithKeywordBits; VectorTypeBitfields VectorTypeBits; TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits; + PackExpansionTypeBitfields PackExpansionTypeBits; static_assert(sizeof(TypeBitfields) <= 8, "TypeBitfields is larger than 8 bytes!"); @@ -1660,6 +1680,8 @@ protected: static_assert(sizeof(TemplateSpecializationTypeBitfields) <= 8, "TemplateSpecializationTypeBitfields is larger" " than 8 bytes!"); + static_assert(sizeof(PackExpansionTypeBitfields) <= 8, + "PackExpansionTypeBitfields is larger than 8 bytes"); }; private: @@ -5189,22 +5211,16 @@ class PackExpansionType : public Type, public llvm::FoldingSetNode { /// The pattern of the pack expansion. QualType Pattern; - /// The number of expansions that this pack expansion will - /// generate when substituted (+1), or indicates that - /// - /// This field will only have a non-zero value when some of the parameter - /// packs that occur within the pattern have been substituted but others have - /// not. - unsigned NumExpansions; - PackExpansionType(QualType Pattern, QualType Canon, Optional<unsigned> NumExpansions) : Type(PackExpansion, Canon, /*Dependent=*/Pattern->isDependentType(), /*InstantiationDependent=*/true, /*VariablyModified=*/Pattern->isVariablyModifiedType(), /*ContainsUnexpandedParameterPack=*/false), - Pattern(Pattern), - NumExpansions(NumExpansions ? *NumExpansions + 1 : 0) {} + Pattern(Pattern) { + PackExpansionTypeBits.NumExpansions = + NumExpansions ? *NumExpansions + 1 : 0; + } public: /// Retrieve the pattern of this pack expansion, which is the @@ -5215,9 +5231,8 @@ public: /// Retrieve the number of expansions that this pack expansion will /// generate, if known. Optional<unsigned> getNumExpansions() const { - if (NumExpansions) - return NumExpansions - 1; - + if (PackExpansionTypeBits.NumExpansions) + return PackExpansionTypeBits.NumExpansions - 1; return None; } |