]> granicus.if.org Git - clang/commitdiff
Refactor ASTSourceDescriptor to not store copies of all strings. (NFC)
authorAdrian Prantl <aprantl@apple.com>
Thu, 24 Sep 2015 16:10:00 +0000 (16:10 +0000)
committerAdrian Prantl <aprantl@apple.com>
Thu, 24 Sep 2015 16:10:00 +0000 (16:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248509 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExternalASTSource.h
lib/AST/ExternalASTSource.cpp
lib/CodeGen/CGDebugInfo.cpp

index ec7978fcc8dee49ab123d13316182693829baa67..e3db1ee4c5380cb05f5b536aef25fcb2acee22b4 100644 (file)
@@ -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.
index 8d32dd23bbe4cb790ff01024c2683d0b1a4944e7..f3b15fc58c822c4fb7cd94c1102fc344870abc4f 100644 (file)
@@ -29,13 +29,20 @@ ExternalASTSource::getSourceDescriptor(unsigned ID) {
 }
 
 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) {}
index 72ddf4efc7c84e0f7ed5be9187d73c9e1f1fb226..04d6876076b3058cf5b903172681c88d1ea34456 100644 (file)
@@ -1676,7 +1676,8 @@ llvm::DIType *CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
 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(ExternalASTSource::ASTSourceDescriptor Mod,
 
   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;