r268817 - [modules] Attempt to improve performance for declaration merging without a Sema
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Fri May 6 16:14:07 PDT 2016
Author: rsmith
Date: Fri May 6 18:14:07 2016
New Revision: 268817
URL: http://llvm.org/viewvc/llvm-project?rev=268817&view=rev
Log:
[modules] Attempt to improve performance for declaration merging without a Sema
object in C. Rather than using the DeclContext (which is very slow because it
triggers us to build a lookup table for the DeclContext), use a separate map
from identifiers to decls for this case, containing only the ones we've
actually deserialized. For convenience, this map is implemented as an
IdentifierResolver.
Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=268817&r1=268816&r2=268817&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri May 6 18:14:07 2016
@@ -27,6 +27,7 @@
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/PreprocessingRecord.h"
#include "clang/Sema/ExternalSemaSource.h"
+#include "clang/Sema/IdentifierResolver.h"
#include "clang/Serialization/ASTBitCodes.h"
#include "clang/Serialization/ContinuousRangeMap.h"
#include "clang/Serialization/Module.h"
@@ -390,6 +391,11 @@ private:
/// \brief The module manager which manages modules and their dependencies
ModuleManager ModuleMgr;
+ /// \brief A dummy identifier resolver used to merge TU-scope declarations in
+ /// C, for the cases where we don't have a Sema object to provide a real
+ /// identifier resolver.
+ IdentifierResolver DummyIdResolver;
+
/// A mapping from extension block names to module file extensions.
llvm::StringMap<IntrusiveRefCntPtr<ModuleFileExtension>> ModuleFileExtensions;
@@ -2100,6 +2106,11 @@ public:
/// imported.
Sema *getSema() { return SemaObj; }
+ /// \brief Get the identifier resolver used for name lookup / updates
+ /// in the translation unit scope. We have one of these even if we don't
+ /// have a Sema object.
+ IdentifierResolver &getIdResolver();
+
/// \brief Retrieve the identifier table associated with the
/// preprocessor.
IdentifierTable &getIdentifierTable();
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=268817&r1=268816&r2=268817&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri May 6 18:14:07 2016
@@ -8695,6 +8695,7 @@ ASTReader::ASTReader(
FileMgr(PP.getFileManager()), PCHContainerRdr(PCHContainerRdr),
Diags(PP.getDiagnostics()), SemaObj(nullptr), PP(PP), Context(Context),
Consumer(nullptr), ModuleMgr(PP.getFileManager(), PCHContainerRdr),
+ DummyIdResolver(PP),
ReadTimer(std::move(ReadTimer)),
PragmaMSStructState(-1),
PragmaMSPointersToMembersState(-1),
@@ -8733,3 +8734,7 @@ ASTReader::~ASTReader() {
if (OwnsDeserializationListener)
delete DeserializationListener;
}
+
+IdentifierResolver &ASTReader::getIdResolver() {
+ return SemaObj ? SemaObj->IdResolver : DummyIdResolver;
+}
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=268817&r1=268816&r2=268817&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Fri May 6 18:14:07 2016
@@ -23,7 +23,6 @@
#include "clang/AST/DeclVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/Sema/IdentifierResolver.h"
-#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "llvm/Support/SaveAndRestore.h"
@@ -2814,9 +2813,9 @@ ASTDeclReader::FindExistingResult::~Find
if (needsAnonymousDeclarationNumber(New)) {
setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
AnonymousDeclNumber, New);
- } else if (DC->isTranslationUnit() && Reader.SemaObj &&
+ } else if (DC->isTranslationUnit() &&
!Reader.getContext().getLangOpts().CPlusPlus) {
- if (Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, Name))
+ if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name))
Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
.push_back(New);
} else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
@@ -2919,9 +2918,9 @@ ASTDeclReader::FindExistingResult ASTDec
if (isSameEntity(Existing, D))
return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
TypedefNameForLinkage);
- } else if (DC->isTranslationUnit() && Reader.SemaObj &&
+ } else if (DC->isTranslationUnit() &&
!Reader.getContext().getLangOpts().CPlusPlus) {
- IdentifierResolver &IdResolver = Reader.SemaObj->IdResolver;
+ IdentifierResolver &IdResolver = Reader.getIdResolver();
// Temporarily consider the identifier to be up-to-date. We don't want to
// cause additional lookups here.
More information about the cfe-commits
mailing list