junaire created this revision. junaire added a reviewer: v.g.vassilev. Herald added a project: All. junaire requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This patch adds a new method to the clang::Interpreter, enables us to explictly clean up the lookup table when doing recovery. Signed-off-by: Jun Zhang <j...@junz.org> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D126684 Files: clang/include/clang/Interpreter/Interpreter.h clang/lib/Interpreter/IncrementalParser.cpp clang/lib/Interpreter/IncrementalParser.h clang/lib/Interpreter/Interpreter.cpp Index: clang/lib/Interpreter/Interpreter.cpp =================================================================== --- clang/lib/Interpreter/Interpreter.cpp +++ clang/lib/Interpreter/Interpreter.cpp @@ -228,6 +228,10 @@ return llvm::Error::success(); } +void Interpreter::Restore(PartialTranslationUnit& PTU) { + IncrParser->Restore(PTU); +} + llvm::Expected<llvm::JITTargetAddress> Interpreter::getSymbolAddress(GlobalDecl GD) const { if (!IncrExecutor) Index: clang/lib/Interpreter/IncrementalParser.h =================================================================== --- clang/lib/Interpreter/IncrementalParser.h +++ clang/lib/Interpreter/IncrementalParser.h @@ -72,6 +72,8 @@ ///\returns the mangled name of a \c GD. llvm::StringRef GetMangledName(GlobalDecl GD) const; + void Restore(PartialTranslationUnit &PTU); + private: llvm::Expected<PartialTranslationUnit &> ParseOrWrapTopLevelDecl(); }; Index: clang/lib/Interpreter/IncrementalParser.cpp =================================================================== --- clang/lib/Interpreter/IncrementalParser.cpp +++ clang/lib/Interpreter/IncrementalParser.cpp @@ -293,6 +293,24 @@ return PTU; } +void IncrementalParser::Restore(PartialTranslationUnit& PTU) { + TranslationUnitDecl *MostRecentTU = PTU.TUPart; + TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl(); + if (StoredDeclsMap *Map = FirstTU->getLookupPtr()) { + for (auto I = Map->begin(); I != Map->end(); ++I) { + StoredDeclsList &List = I->second; + DeclContextLookupResult R = List.getLookupResult(); + for (NamedDecl *D : R){ + if (D->getTranslationUnitDecl() == MostRecentTU){ + List.remove(D); + } + } + if (List.isNull()) + Map->erase(I); + } + } +} + llvm::StringRef IncrementalParser::GetMangledName(GlobalDecl GD) const { CodeGenerator *CG = getCodeGen(Act.get()); assert(CG); Index: clang/include/clang/Interpreter/Interpreter.h =================================================================== --- clang/include/clang/Interpreter/Interpreter.h +++ clang/include/clang/Interpreter/Interpreter.h @@ -69,6 +69,8 @@ return llvm::Error::success(); } + void Restore(PartialTranslationUnit &PTU); + /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses /// the CodeGenModule's internal mangling cache to avoid recomputing the /// mangled name.
Index: clang/lib/Interpreter/Interpreter.cpp =================================================================== --- clang/lib/Interpreter/Interpreter.cpp +++ clang/lib/Interpreter/Interpreter.cpp @@ -228,6 +228,10 @@ return llvm::Error::success(); } +void Interpreter::Restore(PartialTranslationUnit& PTU) { + IncrParser->Restore(PTU); +} + llvm::Expected<llvm::JITTargetAddress> Interpreter::getSymbolAddress(GlobalDecl GD) const { if (!IncrExecutor) Index: clang/lib/Interpreter/IncrementalParser.h =================================================================== --- clang/lib/Interpreter/IncrementalParser.h +++ clang/lib/Interpreter/IncrementalParser.h @@ -72,6 +72,8 @@ ///\returns the mangled name of a \c GD. llvm::StringRef GetMangledName(GlobalDecl GD) const; + void Restore(PartialTranslationUnit &PTU); + private: llvm::Expected<PartialTranslationUnit &> ParseOrWrapTopLevelDecl(); }; Index: clang/lib/Interpreter/IncrementalParser.cpp =================================================================== --- clang/lib/Interpreter/IncrementalParser.cpp +++ clang/lib/Interpreter/IncrementalParser.cpp @@ -293,6 +293,24 @@ return PTU; } +void IncrementalParser::Restore(PartialTranslationUnit& PTU) { + TranslationUnitDecl *MostRecentTU = PTU.TUPart; + TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl(); + if (StoredDeclsMap *Map = FirstTU->getLookupPtr()) { + for (auto I = Map->begin(); I != Map->end(); ++I) { + StoredDeclsList &List = I->second; + DeclContextLookupResult R = List.getLookupResult(); + for (NamedDecl *D : R){ + if (D->getTranslationUnitDecl() == MostRecentTU){ + List.remove(D); + } + } + if (List.isNull()) + Map->erase(I); + } + } +} + llvm::StringRef IncrementalParser::GetMangledName(GlobalDecl GD) const { CodeGenerator *CG = getCodeGen(Act.get()); assert(CG); Index: clang/include/clang/Interpreter/Interpreter.h =================================================================== --- clang/include/clang/Interpreter/Interpreter.h +++ clang/include/clang/Interpreter/Interpreter.h @@ -69,6 +69,8 @@ return llvm::Error::success(); } + void Restore(PartialTranslationUnit &PTU); + /// \returns the \c JITTargetAddress of a \c GlobalDecl. This interface uses /// the CodeGenModule's internal mangling cache to avoid recomputing the /// mangled name.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits