[PATCH] D126684: [Interpreter] Implment Interpreter::Restore to clean up lookup table

Jun Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 30 23:31:09 PDT 2022


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 <jun at 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126684.433021.patch
Type: text/x-patch
Size: 2450 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220531/ea22b43f/attachment-0001.bin>


More information about the cfe-commits mailing list