summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Ricci <riccibrun@gmail.com>2018-08-15 16:21:17 +0000
committerBruno Ricci <riccibrun@gmail.com>2018-08-15 16:21:17 +0000
commit43ccc1c63dcdd1814774de7b8e88ab3583dd420b (patch)
treeaa750a3a675b55a54e5b32d3caba8725fe36dfe2
parent82812fb986aa217a69f18390207a683049b7748a (diff)
downloadbcm5719-llvm-43ccc1c63dcdd1814774de7b8e88ab3583dd420b.tar.gz
bcm5719-llvm-43ccc1c63dcdd1814774de7b8e88ab3583dd420b.zip
[AST] Pack the bits of TemplateSpecializationType into Type
Type has enough space for two members of TemplateSpecializationType. Mechanical patch. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D50643 llvm-svn: 339787
-rw-r--r--clang/include/clang/AST/Type.h37
-rw-r--r--clang/lib/AST/Type.cpp8
2 files changed, 32 insertions, 13 deletions
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 93dafc47dd0..617ea772d00 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1606,6 +1606,24 @@ protected:
unsigned Keyword : 2;
};
+ class TemplateSpecializationTypeBitfields {
+ friend class TemplateSpecializationType;
+
+ unsigned : NumTypeBits;
+
+ /// Whether this template specialization type is a substituted type alias.
+ unsigned TypeAlias : 1;
+
+ /// The number of template arguments named in this class template
+ /// specialization, 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.
+ unsigned NumArgs;
+ };
+
union {
TypeBitfields TypeBits;
ArrayTypeBitfields ArrayTypeBits;
@@ -1617,6 +1635,7 @@ protected:
ReferenceTypeBitfields ReferenceTypeBits;
TypeWithKeywordBitfields TypeWithKeywordBits;
VectorTypeBitfields VectorTypeBits;
+ TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits;
static_assert(sizeof(TypeBitfields) <= 8,
"TypeBitfields is larger than 8 bytes!");
@@ -1638,6 +1657,9 @@ protected:
"TypeWithKeywordBitfields is larger than 8 bytes!");
static_assert(sizeof(VectorTypeBitfields) <= 8,
"VectorTypeBitfields is larger than 8 bytes!");
+ static_assert(sizeof(TemplateSpecializationTypeBitfields) <= 8,
+ "TemplateSpecializationTypeBitfields is larger"
+ " than 8 bytes!");
};
private:
@@ -4669,13 +4691,6 @@ class alignas(8) TemplateSpecializationType
/// replacement must, recursively, be one of these).
TemplateName Template;
- /// The number of template arguments named in this class template
- /// specialization.
- unsigned NumArgs : 31;
-
- /// Whether this template specialization type is a substituted type alias.
- unsigned TypeAlias : 1;
-
TemplateSpecializationType(TemplateName T,
ArrayRef<TemplateArgument> Args,
QualType Canon,
@@ -4710,7 +4725,7 @@ public:
/// typedef A<Ts...> type; // not a type alias
/// };
/// \endcode
- bool isTypeAlias() const { return TypeAlias; }
+ bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; }
/// Get the aliased type, if this is a specialization of a type alias
/// template.
@@ -4733,14 +4748,16 @@ public:
}
/// Retrieve the number of template arguments.
- unsigned getNumArgs() const { return NumArgs; }
+ unsigned getNumArgs() const {
+ return TemplateSpecializationTypeBits.NumArgs;
+ }
/// Retrieve a specific template argument as a type.
/// \pre \c isArgType(Arg)
const TemplateArgument &getArg(unsigned Idx) const; // in TemplateBase.h
ArrayRef<TemplateArgument> template_arguments() const {
- return {getArgs(), NumArgs};
+ return {getArgs(), getNumArgs()};
}
bool isSugared() const {
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 315844fa424..1dba3e3e4c7 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3335,8 +3335,10 @@ TemplateSpecializationType(TemplateName T,
Canon.isNull()? true : Canon->isDependentType(),
Canon.isNull()? true : Canon->isInstantiationDependentType(),
false,
- T.containsUnexpandedParameterPack()),
- Template(T), NumArgs(Args.size()), TypeAlias(!AliasedType.isNull()) {
+ T.containsUnexpandedParameterPack()), Template(T) {
+ TemplateSpecializationTypeBits.NumArgs = Args.size();
+ TemplateSpecializationTypeBits.TypeAlias = !AliasedType.isNull();
+
assert(!T.getAsDependentTemplateName() &&
"Use DependentTemplateSpecializationType for dependent template-name");
assert((T.getKind() == TemplateName::Template ||
@@ -3365,7 +3367,7 @@ TemplateSpecializationType(TemplateName T,
}
// Store the aliased type if this is a type alias template specialization.
- if (TypeAlias) {
+ if (isTypeAlias()) {
auto *Begin = reinterpret_cast<TemplateArgument *>(this + 1);
*reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType;
}
OpenPOWER on IntegriCloud