r248509 - Refactor ASTSourceDescriptor to not store copies of all strings. (NFC)

Adrian Prantl via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 24 09:10:01 PDT 2015


Author: adrian
Date: Thu Sep 24 11:10:00 2015
New Revision: 248509

URL: http://llvm.org/viewvc/llvm-project?rev=248509&view=rev
Log:
Refactor ASTSourceDescriptor to not store copies of all strings. (NFC)

Modified:
    cfe/trunk/include/clang/AST/ExternalASTSource.h
    cfe/trunk/lib/AST/ExternalASTSource.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/include/clang/AST/ExternalASTSource.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTSource.h?rev=248509&r1=248508&r2=248509&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExternalASTSource.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTSource.h Thu Sep 24 11:10:00 2015
@@ -145,17 +145,24 @@ public:
   /// Abstracts clang modules and precompiled header files and holds
   /// everything needed to generate debug info for an imported module
   /// or PCH.
-  struct ASTSourceDescriptor {
+  class ASTSourceDescriptor {
+    StringRef PCHModuleName;
+    StringRef Path;
+    StringRef ASTFile;
+    uint64_t Signature = 0;
+    const Module *ClangModule = nullptr;
+
+  public:
     ASTSourceDescriptor(){};
-    ASTSourceDescriptor(std::string Name, std::string Path, std::string ASTFile,
+    ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
                         uint64_t Signature)
-        : FullModuleName(std::move(Name)), Path(std::move(Path)),
+        : PCHModuleName(std::move(Name)), Path(std::move(Path)),
           ASTFile(std::move(ASTFile)), Signature(Signature){};
     ASTSourceDescriptor(const Module &M);
-    std::string FullModuleName;
-    std::string Path;
-    std::string ASTFile;
-    uint64_t Signature = 0;
+    std::string getFullModuleName() const;
+    StringRef getPath() const { return Path; }
+    StringRef getASTFile() const { return ASTFile; }
+    uint64_t getSignature() const { return Signature; }
   };
 
   /// Return a descriptor for the corresponding module, if one exists.

Modified: cfe/trunk/lib/AST/ExternalASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTSource.cpp?rev=248509&r1=248508&r2=248509&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExternalASTSource.cpp (original)
+++ cfe/trunk/lib/AST/ExternalASTSource.cpp Thu Sep 24 11:10:00 2015
@@ -29,13 +29,20 @@ ExternalASTSource::getSourceDescriptor(u
 }
 
 ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M)
-    : FullModuleName(M.getFullModuleName()), Signature(M.Signature) {
+  : Signature(M.Signature), ClangModule(&M) {
   if (M.Directory)
     Path = M.Directory->getName();
   if (auto *File = M.getASTFile())
     ASTFile = File->getName();
 }
 
+std::string ExternalASTSource::ASTSourceDescriptor::getFullModuleName() const {
+  if (ClangModule)
+    return ClangModule->getFullModuleName();
+  else
+    return PCHModuleName;
+}
+
 void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
                                             unsigned Length,
                                             SmallVectorImpl<Decl *> &Decls) {}

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=248509&r1=248508&r2=248509&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Sep 24 11:10:00 2015
@@ -1676,7 +1676,8 @@ llvm::DIType *CGDebugInfo::CreateType(co
 llvm::DIModule *
 CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
                                   bool CreateSkeletonCU) {
-  auto &ModRef = ModuleRefCache[Mod.FullModuleName];
+  std::string FullModuleName = Mod.getFullModuleName();
+  auto &ModRef = ModuleRefCache[FullModuleName];
   if (ModRef)
     return cast<llvm::DIModule>(ModRef);
 
@@ -1705,14 +1706,14 @@ CGDebugInfo::getOrCreateModuleRef(Extern
 
   if (CreateSkeletonCU) {
     llvm::DIBuilder DIB(CGM.getModule());
-    DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.FullModuleName,
-                          Mod.Path, TheCU->getProducer(), true, StringRef(), 0,
-                          Mod.ASTFile, llvm::DIBuilder::FullDebug,
-                          Mod.Signature);
+    DIB.createCompileUnit(TheCU->getSourceLanguage(), FullModuleName,
+                          Mod.getPath(), TheCU->getProducer(), true,
+                          StringRef(), 0, Mod.getASTFile(),
+                          llvm::DIBuilder::FullDebug, Mod.getSignature());
     DIB.finalize();
   }
   llvm::DIModule *M =
-      DBuilder.createModule(TheCU, Mod.FullModuleName, ConfigMacros, Mod.Path,
+      DBuilder.createModule(TheCU, FullModuleName, ConfigMacros, Mod.getPath(),
                             CGM.getHeaderSearchOpts().Sysroot);
   ModRef.reset(M);
   return M;




More information about the cfe-commits mailing list