Author: Nikolas Klauser
Date: 2024-04-14T12:23:21+02:00
New Revision: b243ca1d3616d1dd61b81e3a112707e27cd4c865
URL:
https://github.com/llvm/llvm-project/commit/b243ca1d3616d1dd61b81e3a112707e27cd4c865
DIFF:
https://github.com/llvm/llvm-project/commit/b243ca1d3616d1dd61b81e3a112707e27cd4c865.diff
LOG: Revert "[Clang] Reduce the size of Decl and classes derived from it
(#87361)"
This reverts commit c6f9c84e498ee05a812511ae969773ff166fd25e.
Added:
Modified:
clang/include/clang/AST/DeclBase.h
clang/lib/AST/DeclBase.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
Removed:
diff --git a/clang/include/clang/AST/DeclBase.h
b/clang/include/clang/AST/DeclBase.h
index 4bee18767dd11b..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,37 +268,17 @@ class alignas(8) Decl {
/// }
/// void A::f(); // SemanticDC == namespace 'A'
///// LexicalDC == global namespace
+ llvm::PointerUnion DeclCtx;
- // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
- // 32 bytes in size
- llvm::PointerIntPair<
- llvm::PointerIntPair, 1,
- bool>,
- 1, bool>
- DeclCtxWithInvalidDeclAndHasAttrs;
-
- bool isInSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
- }
-
- bool isOutOfSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
- }
+ bool isInSemaDC() const { return DeclCtx.is(); }
+ bool isOutOfSemaDC() const { return DeclCtx.is(); }
MultipleDC *getMultipleDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
}
DeclContext *getSemanticDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
}
/// Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
LLVM_PREFERRED_TYPE(Kind)
unsigned DeclKind : 7;
+ /// InvalidDecl - This indicates a semantic error occurred.
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned InvalidDecl : 1;
+
+ /// HasAttrs - This indicates whether the decl has attributes or not.
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned HasAttrs : 1;
+
/// Implicit - Whether this declaration was implicitly generated by
/// the implementation rather than explicitly written by the user.
LLVM_PREFERRED_TYPE(bool)
@@ -405,22 +393,21 @@ class alignas(8) Decl {
protected:
Decl(Kind DK, DeclContext *DC, SourceLocation L)
: NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
-DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
+Implicit(false), Used(false), Referenced(false),
TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
- add(DK);
+if (StatisticsEnabled) add(DK);
}
Decl(Kind DK, EmptyShell Empty)
- : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+ : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+Access(AS_none), FromASTFile(0),
IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
- add(DK);
+if (StatisticsEnabled) add(DK);
}
virtual ~Decl();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
return AccessSpecifier(Access);
}
- bool hasAttrs() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt();
- }
+ bool hasAttrs() const { return HasAttrs; }
void setAttrs(const AttrVec& Attrs) {
return setAttrsImpl(Attrs, getASTContext());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
}
template void dropAttrs() {
-if (!hasAttrs())
- return;
+if (!HasAttrs) return;
AttrVec &Vec = getAttrs();
llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
-if (Vec.empty()) {
- auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
- InnerPtr.setInt(false);
- DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
-}
+if (Vec.empty())
+ HasAttrs = false;
}
template void dropAttr() { dropAttrs(); }
@@ -609,10 +590,7 @@ class alignas(8) Decl {
/// setInvalidDecl - Indicates the Decl