diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-12-03 17:11:42 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-12-03 17:11:42 +0000 |
commit | 2357207a5753547740c70a12c3b37f71afa93f8a (patch) | |
tree | d446655bee3700372be6757d2d9d7e9af1efc38a /lib/AST/DeclBase.cpp | |
parent | 96bfa6249fe65eaaaba795845c0f92f94d2b8a0d (diff) |
Implement caching for the linkage and visibility calculations of
declarations.
The motivation for this patch is that linkage/visibility computations
are linear in the number of redeclarations of an entity, and we've run
into a case where a single translation unit has > 6500 redeclarations
of the same (unused!) external variable. Since each redeclaration
involves a linkage check, the resulting quadratic behavior makes Clang
slow to a crawl. With this change, a simple test with 512
redeclarations of a variable syntax-checks ~20x faster than
before.
That said, I hate this change, and will probably end up reverting it
in a few hours. Reasons to hate it:
- It makes NamedDecl larger, since we don't have enough free bits in
Decl to squeeze in the extra information about caching.
- There are way too many places where we need to invalidate this
cache, because the visibility of a declaration can change due to
redeclarations (!). Despite self-hosting and passing the testsuite,
I have no confidence that I've found all of places where this cache
needs to be invalidated.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120808 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r-- | lib/AST/DeclBase.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 843e907dea..3758ca1065 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -337,6 +337,38 @@ void Decl::dropAttrs() { getASTContext().eraseDeclAttrs(this); } +void Decl::addAttr(Attr *A) { + if (NamedDecl *ND = dyn_cast<NamedDecl>(this)) + if (VisibilityAttr *Visibility = dyn_cast<VisibilityAttr>(A)) { + bool ClearVisibility = true; + if (VarDecl *VD = dyn_cast<VarDecl>(this)) { + if (VD->getPreviousDeclaration()) { + VisibilityAttr *PrevVisibility + = VD->getPreviousDeclaration()->getAttr<VisibilityAttr>(); + if (PrevVisibility && + PrevVisibility->getVisibility() == Visibility->getVisibility()) + ClearVisibility = false; + } + } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(this)) { + if (FD->getPreviousDeclaration()) { + VisibilityAttr *PrevVisibility + = FD->getPreviousDeclaration()->getAttr<VisibilityAttr>(); + if (PrevVisibility && + PrevVisibility->getVisibility() == Visibility->getVisibility()) + ClearVisibility = false; + } + } + + if (ClearVisibility) + ND->ClearLinkageAndVisibilityCache(); + } + + if (hasAttrs()) + getAttrs().push_back(A); + else + setAttrs(AttrVec(1, A)); +} + const AttrVec &Decl::getAttrs() const { assert(HasAttrs && "No attrs to get!"); return getASTContext().getDeclAttrs(this); |