]> granicus.if.org Git - clang/commitdiff
Cache results computed by CGDebugInfo::getOrCreateFile() in a DenseMap.
authorTed Kremenek <kremenek@apple.com>
Tue, 30 Mar 2010 00:27:51 +0000 (00:27 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 30 Mar 2010 00:27:51 +0000 (00:27 +0000)
This reduces '-c -g' time on one file in 403.gcc by 12%.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99857 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h

index d8a9f36c8250677fb7b208224a15e685734e79fc..0e789c92d67240956d272d302057061f828372c7 100644 (file)
@@ -88,17 +88,35 @@ llvm::StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) {
 
 /// getOrCreateFile - Get the file debug info descriptor for the input location.
 llvm::DIFile CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
-  if (!Loc.isValid()) 
+  if (!Loc.isValid())
     // If Location is not valid then use main input file.
     return DebugFactory.CreateFile(TheCU.getFilename(), TheCU.getDirectory(),
                                    TheCU);
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(Loc);
+
+  // Cache the results.
+  const char *fname = PLoc.getFilename();
+  llvm::DenseMap<const char *, llvm::WeakVH>::iterator it =
+    DIFileCache.find(fname);
+
+  if (it != DIFileCache.end()) {
+    // Verify that the information still exists.
+    if (&*it->second)
+      return llvm::DIFile(cast<llvm::MDNode>(it->second));
+  }
+
+  // FIXME: We shouldn't even need to call 'makeAbsolute()' in the cases
+  // where we can consult the FileEntry.
   llvm::sys::Path AbsFileName(PLoc.getFilename());
   AbsFileName.makeAbsolute();
 
-  return DebugFactory.CreateFile(AbsFileName.getLast(),
-                                 AbsFileName.getDirname(), TheCU);
+  llvm::DIFile F = DebugFactory.CreateFile(AbsFileName.getLast(),
+                                           AbsFileName.getDirname(), TheCU);
+
+  DIFileCache[fname] = F.getNode();
+  return F;
+
 }
 /// CreateCompileUnit - Create new compile unit.
 void CGDebugInfo::CreateCompileUnit() {
index 9b10aba90ee592d5b51d02da37861754b81f3445..e4f21f4d1399c1e11f4ad9f0f26bdef89ea9285c 100644 (file)
@@ -64,6 +64,7 @@ class CGDebugInfo {
   /// constructed on demand. For example, C++ destructors, C++ operators etc..
   llvm::BumpPtrAllocator DebugInfoNames;
 
+  llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache;
   llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
   llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;