aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorNikolas Klauser <nikolasklauser@berlin.de>2024-04-14 12:08:30 +0200
committerGitHub <noreply@github.com>2024-04-14 12:08:30 +0200
commitc6f9c84e498ee05a812511ae969773ff166fd25e (patch)
tree6a6746cf76f8f2498dc7eee0519faceb5feff883 /clang/lib/AST/DeclBase.cpp
parent09327efdf0f02c4f865a4536db96cac539bb1c01 (diff)
downloadllvm-c6f9c84e498ee05a812511ae969773ff166fd25e.zip
llvm-c6f9c84e498ee05a812511ae969773ff166fd25e.tar.gz
llvm-c6f9c84e498ee05a812511ae969773ff166fd25e.tar.bz2
[Clang] Reduce the size of Decl and classes derived from it (#87361)
Class | Old size (in bytes) | New size (in bytes) ----------------------------------|---------------------|-------------------- Decl | 40 | 32 AccessSpecDecl | 40 | 40 BlockDecl | 128 | 120 CapturedDecl | 88 | 80 EmptyDecl | 40 | 32 ExportDecl | 80 | 72 ExternCContextDecl | 72 | 64 FileScopeAsmDecl | 56 | 48 FriendDecl | 64 | 56 FriendTemplateDecl | 64 | 64 ImplicitConceptSpecializationDecl | 40 | 40 ImportDecl | 56 | 48 LifetimeExtendedTemporaryDecl | 72 | 64 LinkageSpecDecl | 80 | 72 NamedDecl | 48 | 40 ObjCPropertyImplDecl | 96 | 88 PragmaCommentDecl | 40 | 40 PragmaDetectMismatchDecl | 48 | 40 RequiresExprBodyDecl | 72 | 64 StaticAssertDecl | 64 | 56 TopLevelStmtDecl | 88 | 80 TranslationUnitDecl | 104 | 96 BaseUsingDecl | 56 | 48 UsingDecl | 88 | 80 UsingEnumDecl | 72 | 64 HLSLBufferDecl | 96 | 88 LabelDecl | 80 | 72 NamespaceAliasDecl | 96 | 88 NamespaceDecl | 112 | 104 ObjCCompatibleAliasDecl | 56 | 48 ObjCContainerDecl | 88 | 80 ObjCMethodDecl | 136 | 128 ObjCPropertyDecl | 128 | 120 TemplateDecl | 64 | 56 BuiltinTemplateDecl | 72 | 64 TypeDecl | 64 | 56 UnresolvedUsingIfExistsDecl | 48 | 40 UsingDirectiveDecl | 88 | 80 UsingPackDecl | 64 | 56 UsingShadowDecl | 80 | 72 ValueDecl | 56 | 48 When parsing libc++'s `<string>` header the used memory is reduced from 42.8MB to 42.5MB.
Diffstat (limited to 'clang/lib/AST/DeclBase.cpp')
-rw-r--r--clang/lib/AST/DeclBase.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 66a727d..8c83c71 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -52,6 +52,8 @@
using namespace clang;
+static_assert(sizeof(Decl) <= 32, "Decl grew beyond 32 bytes!");
+
//===----------------------------------------------------------------------===//
// Statistics
//===----------------------------------------------------------------------===//
@@ -130,7 +132,7 @@ const char *Decl::getDeclKindName() const {
}
void Decl::setInvalidDecl(bool Invalid) {
- InvalidDecl = Invalid;
+ DeclCtxWithInvalidDeclAndHasAttrs.setInt(Invalid);
assert(!isa<TagDecl>(this) || !cast<TagDecl>(this)->isCompleteDefinition());
if (!Invalid) {
return;
@@ -334,7 +336,9 @@ void PrettyStackTraceDecl::print(raw_ostream &OS) const {
Decl::~Decl() = default;
void Decl::setDeclContext(DeclContext *DC) {
- DeclCtx = DC;
+ auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+ InnerPtr.setPointer(DC);
+ DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
}
void Decl::setLexicalDeclContext(DeclContext *DC) {
@@ -364,12 +368,16 @@ void Decl::setLexicalDeclContext(DeclContext *DC) {
void Decl::setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
ASTContext &Ctx) {
if (SemaDC == LexicalDC) {
- DeclCtx = SemaDC;
+ auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+ InnerPtr.setPointer(SemaDC);
+ DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
} else {
auto *MDC = new (Ctx) Decl::MultipleDC();
MDC->SemanticDC = SemaDC;
MDC->LexicalDC = LexicalDC;
- DeclCtx = MDC;
+ auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+ InnerPtr.setPointer(MDC);
+ DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
}
}
@@ -956,19 +964,24 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
}
void Decl::setAttrsImpl(const AttrVec &attrs, ASTContext &Ctx) {
- assert(!HasAttrs && "Decl already contains attrs.");
+ assert(!hasAttrs() && "Decl already contains attrs.");
AttrVec &AttrBlank = Ctx.getDeclAttrs(this);
assert(AttrBlank.empty() && "HasAttrs was wrong?");
AttrBlank = attrs;
- HasAttrs = true;
+ auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+ InnerPtr.setInt(true);
+ DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
}
void Decl::dropAttrs() {
- if (!HasAttrs) return;
+ if (!hasAttrs())
+ return;
- HasAttrs = false;
+ auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+ InnerPtr.setInt(false);
+ DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
getASTContext().eraseDeclAttrs(this);
}
@@ -996,7 +1009,7 @@ void Decl::addAttr(Attr *A) {
}
const AttrVec &Decl::getAttrs() const {
- assert(HasAttrs && "No attrs to get!");
+ assert(hasAttrs() && "No attrs to get!");
return getASTContext().getDeclAttrs(this);
}