[cfe-commits] r58055 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h

Daniel Dunbar daniel at zuster.org
Thu Oct 23 17:46:53 PDT 2008


Author: ddunbar
Date: Thu Oct 23 19:46:51 2008
New Revision: 58055

URL: http://llvm.org/viewvc/llvm-project?rev=58055&view=rev
Log:
Map compilation units using FileEntry pointers instead of
FileIDs. This seems better conceptually and lets the SourceManager
handle details of mapping the location to a file ID.
 - In practice, fixes an assert because this code wasn't using
   getPhysicalLoc.

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=58055&r1=58054&r2=58055&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Oct 23 19:46:51 2008
@@ -64,7 +64,7 @@
   delete SR;
 
   // Free CompileUnitCache.
-  for (std::map<unsigned, llvm::CompileUnitDesc *>::iterator I 
+  for (std::map<const FileEntry*, llvm::CompileUnitDesc *>::iterator I 
        = CompileUnitCache.begin(); I != CompileUnitCache.end(); ++I) {
     delete I->second;
   }
@@ -134,15 +134,17 @@
 /// one if necessary.
 llvm::CompileUnitDesc 
 *CGDebugInfo::getOrCreateCompileUnit(const SourceLocation Loc) {
+  SourceManager &SM = M->getContext().getSourceManager();
+  const FileEntry *FE = SM.getFileEntryForLoc(Loc);
 
   // See if this compile unit has been used before.
-  llvm::CompileUnitDesc *&Slot = CompileUnitCache[Loc.getFileID()];
-  if (Slot) return Slot;
-
+  llvm::CompileUnitDesc *&Unit = CompileUnitCache[FE];
+  if (Unit) return Unit;
+  
   // Create new compile unit.
   // FIXME: Where to free these?
   // One way is to iterate over the CompileUnitCache in ~CGDebugInfo.
-  llvm::CompileUnitDesc *Unit = new llvm::CompileUnitDesc();
+  Unit = new llvm::CompileUnitDesc();
 
   // Make sure we have an anchor.
   if (!CompileUnitAnchor) {
@@ -150,8 +152,6 @@
   }
 
   // Get source file information.
-  SourceManager &SM = M->getContext().getSourceManager();
-  const FileEntry *FE = SM.getFileEntryForLoc(Loc);
   const char *FileName, *DirName;
   if (FE) {
     FileName = FE->getName();
@@ -173,9 +173,6 @@
   // FIXME: Handle other languages as well.
   Unit->setLanguage(llvm::dwarf::DW_LANG_C89);
 
-  // Update cache.
-  Slot = Unit;
-
   return Unit;
 }
 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=58055&r1=58054&r2=58055&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Oct 23 19:46:51 2008
@@ -57,7 +57,7 @@
   typedef llvm::IRBuilder<> BuilderType;
 
   /// CompileUnitCache - Cache of previously constructed CompileUnits.
-  std::map<unsigned, llvm::CompileUnitDesc *> CompileUnitCache;
+  std::map<const FileEntry*, llvm::CompileUnitDesc *> CompileUnitCache;
 
   /// TypeCache - Cache of previously constructed Types.
   std::map<void *, llvm::TypeDesc *> TypeCache;





More information about the cfe-commits mailing list