summaryrefslogtreecommitdiff
path: root/include/clang
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-07-12 23:43:21 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-07-12 23:43:21 +0000
commit5bdcb6dc1a8c1513384439c511fa9f4b4f5e3dfe (patch)
tree0ee39f94fae6fc27aa75b1ea9cb3322ee0909ece /include/clang
parent1c377036ee1772a07c7e5ae030e35ee499880245 (diff)
downloadclang-5bdcb6dc1a8c1513384439c511fa9f4b4f5e3dfe.tar.gz
[modules] Improve performance when there is a local declaration of an entity
before the first imported declaration. We don't need to track all formerly-canonical declarations of an entity; it's sufficient to track those ones for which no other formerly-canonical declaration was imported into the same module. We call those ones "key declarations", and use them as our starting points for collecting redeclarations and performing namespace lookups. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241999 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r--include/clang/Serialization/ASTReader.h54
-rw-r--r--include/clang/Serialization/ASTWriter.h2
2 files changed, 38 insertions, 18 deletions
diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h
index ef5b107a2f..6fa7ffa116 100644
--- a/include/clang/Serialization/ASTReader.h
+++ b/include/clang/Serialization/ASTReader.h
@@ -976,12 +976,14 @@ private:
MergedLookups;
typedef llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2> >
- MergedDeclsMap;
+ KeyDeclsMap;
- /// \brief A mapping from canonical declarations to the set of additional
- /// (global, previously-canonical) declaration IDs that have been merged with
- /// that canonical declaration.
- MergedDeclsMap MergedDecls;
+ /// \brief A mapping from canonical declarations to the set of global
+ /// declaration IDs for key declaration that have been merged with that
+ /// canonical declaration. A key declaration is a formerly-canonical
+ /// declaration whose module did not import any other key declaration for that
+ /// entity. These are the IDs that we use as keys when finding redecl chains.
+ KeyDeclsMap KeyDecls;
/// \brief A mapping from DeclContexts to the semantic DeclContext that we
/// are treating as the definition of the entity. This is used, for instance,
@@ -1054,6 +1056,36 @@ public:
void ResolveImportedPath(ModuleFile &M, std::string &Filename);
static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
+ /// \brief Returns the first key declaration for the given declaration. This
+ /// is one that is formerly-canonical (or still canonical) and whose module
+ /// did not import any other key declaration of the entity.
+ Decl *getKeyDeclaration(Decl *D) {
+ D = D->getCanonicalDecl();
+ if (D->isFromASTFile())
+ return D;
+
+ auto I = KeyDecls.find(D);
+ if (I == KeyDecls.end() || I->second.empty())
+ return D;
+ return GetExistingDecl(I->second[0]);
+ }
+ const Decl *getKeyDeclaration(const Decl *D) {
+ return getKeyDeclaration(const_cast<Decl*>(D));
+ }
+
+ /// \brief Run a callback on each imported key declaration of \p D.
+ template <typename Fn>
+ void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
+ D = D->getCanonicalDecl();
+ if (D->isFromASTFile())
+ Visit(D);
+
+ auto It = KeyDecls.find(const_cast<Decl*>(D));
+ if (It != KeyDecls.end())
+ for (auto ID : It->second)
+ Visit(GetExistingDecl(ID));
+ }
+
private:
struct ImportedModule {
ModuleFile *Mod;
@@ -1124,18 +1156,6 @@ private:
/// merged into its redecl chain.
Decl *getMostRecentExistingDecl(Decl *D);
- template <typename Fn>
- void forEachFormerlyCanonicalImportedDecl(const Decl *D, Fn Visit) {
- D = D->getCanonicalDecl();
- if (D->isFromASTFile())
- Visit(D);
-
- auto It = MergedDecls.find(const_cast<Decl*>(D));
- if (It != MergedDecls.end())
- for (auto ID : It->second)
- Visit(GetExistingDecl(ID));
- }
-
RecordLocation DeclCursorForID(serialization::DeclID ID,
unsigned &RawLocation);
void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D);
diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h
index c966d3edeb..e830fdcf8f 100644
--- a/include/clang/Serialization/ASTWriter.h
+++ b/include/clang/Serialization/ASTWriter.h
@@ -398,7 +398,7 @@ private:
/// \brief The set of declarations that may have redeclaration chains that
/// need to be serialized.
- llvm::SmallSetVector<Decl *, 4> Redeclarations;
+ llvm::SmallVector<const Decl *, 16> Redeclarations;
/// \brief Statements that we've encountered while serializing a
/// declaration or type.