[cfe-commits] r140521 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Sep 26 03:01:50 CDT 2011


Author: akirtzidis
Date: Mon Sep 26 03:01:50 2011
New Revision: 140521

URL: http://llvm.org/viewvc/llvm-project?rev=140521&view=rev
Log:
Associate the macro arguments location map with a FileID instead
of a ContentCache, since multiple FileIDs can have the same ContentCache
but the expanded macro arguments locations will be different.

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceManager.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=140521&r1=140520&r2=140521&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Mon Sep 26 03:01:50 2011
@@ -104,11 +104,6 @@
     /// if SourceLineCache is non-null.
     unsigned NumLines;
 
-    /// \brief Lazily computed map of macro argument chunks to their expanded
-    /// source location.
-    typedef std::map<unsigned, SourceLocation> MacroArgsMap;
-    MacroArgsMap *MacroArgsCache;
-
     /// getBuffer - Returns the memory buffer for the associated content.
     ///
     /// \param Diag Object through which diagnostics will be emitted if the
@@ -166,11 +161,11 @@
 
     ContentCache(const FileEntry *Ent = 0)
       : Buffer(0, false), OrigEntry(Ent), ContentsEntry(Ent),
-        SourceLineCache(0), NumLines(0), MacroArgsCache(0) {}
+        SourceLineCache(0), NumLines(0) {}
 
     ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
       : Buffer(0, false), OrigEntry(Ent), ContentsEntry(contentEnt),
-        SourceLineCache(0), NumLines(0), MacroArgsCache(0) {}
+        SourceLineCache(0), NumLines(0) {}
 
     ~ContentCache();
 
@@ -178,14 +173,13 @@
     ///  a non-NULL Buffer or SourceLineCache.  Ownership of allocated memory
     ///  is not transferred, so this is a logical error.
     ContentCache(const ContentCache &RHS)
-      : Buffer(0, false), SourceLineCache(0), MacroArgsCache(0)
+      : Buffer(0, false), SourceLineCache(0)
     {
       OrigEntry = RHS.OrigEntry;
       ContentsEntry = RHS.ContentsEntry;
 
       assert (RHS.Buffer.getPointer() == 0 && RHS.SourceLineCache == 0 &&
-              RHS.MacroArgsCache == 0
-              && "Passed ContentCache object cannot own a buffer.");
+              "Passed ContentCache object cannot own a buffer.");
 
       NumLines = RHS.NumLines;
     }
@@ -571,6 +565,12 @@
   // Cache for the "fake" buffer used for error-recovery purposes.
   mutable llvm::MemoryBuffer *FakeBufferForRecovery;
 
+  /// \brief Lazily computed map of macro argument chunks to their expanded
+  /// source location.
+  typedef std::map<unsigned, SourceLocation> MacroArgsMap;
+
+  mutable llvm::DenseMap<FileID, MacroArgsMap *> MacroArgsCacheMap; 
+
   // SourceManager doesn't support copy construction.
   explicit SourceManager(const SourceManager&);
   void operator=(const SourceManager&);
@@ -1301,7 +1301,7 @@
   std::pair<FileID, unsigned>
   getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
                                    unsigned Offset) const;
-  void computeMacroArgsCache(SrcMgr::ContentCache *Content, FileID FID) const;
+  void computeMacroArgsCache(MacroArgsMap *&MacroArgsCache, FileID FID) const;
 
   friend class ASTReader;
   friend class ASTWriter;

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=140521&r1=140520&r2=140521&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Mon Sep 26 03:01:50 2011
@@ -39,7 +39,6 @@
 ContentCache::~ContentCache() {
   if (shouldFreeBuffer())
     delete Buffer.getPointer();
-  delete MacroArgsCache;
 }
 
 /// getSizeBytesMapped - Returns the number of bytes actually mapped for this
@@ -389,6 +388,11 @@
   }
   
   delete FakeBufferForRecovery;
+
+  for (llvm::DenseMap<FileID, MacroArgsMap *>::iterator
+         I = MacroArgsCacheMap.begin(),E = MacroArgsCacheMap.end(); I!=E; ++I) {
+    delete I->second;
+  }
 }
 
 void SourceManager::clearIDTables() {
@@ -1503,13 +1507,13 @@
 ///     0   -> SourceLocation()
 ///     100 -> Expanded macro arg location
 ///     110 -> SourceLocation()
-void SourceManager::computeMacroArgsCache(ContentCache *Content,
+void SourceManager::computeMacroArgsCache(MacroArgsMap *&CachePtr,
                                           FileID FID) const {
-  assert(!Content->MacroArgsCache);
   assert(!FID.isInvalid());
+  assert(!CachePtr);
 
-  Content->MacroArgsCache = new ContentCache::MacroArgsMap();
-  ContentCache::MacroArgsMap &MacroArgsCache = *Content->MacroArgsCache;
+  CachePtr = new MacroArgsMap();
+  MacroArgsMap &MacroArgsCache = *CachePtr;
   // Initially no macro argument chunk is present.
   MacroArgsCache.insert(std::make_pair(0, SourceLocation()));
 
@@ -1566,7 +1570,7 @@
     // previous chunks, we only need to find where the ending of the new macro
     // chunk is mapped to and update the map with new begin/end mappings.
 
-    ContentCache::MacroArgsMap::iterator I= MacroArgsCache.upper_bound(EndOffs);
+    MacroArgsMap::iterator I = MacroArgsCache.upper_bound(EndOffs);
     --I;
     SourceLocation EndOffsMappedLoc = I->second;
     MacroArgsCache[BeginOffs] = SourceLocation::getMacroLoc(Entry.getOffset());
@@ -1594,15 +1598,12 @@
   if (FID.isInvalid())
     return Loc;
 
-  ContentCache *Content
-    = const_cast<ContentCache *>(getSLocEntry(FID).getFile().getContentCache());
-  if (!Content->MacroArgsCache)
-    computeMacroArgsCache(Content, FID);
-
-  assert(Content->MacroArgsCache);
-  assert(!Content->MacroArgsCache->empty());
-  ContentCache::MacroArgsMap::iterator
-      I = Content->MacroArgsCache->upper_bound(Offset);
+  MacroArgsMap *&MacroArgsCache = MacroArgsCacheMap[FID];
+  if (!MacroArgsCache)
+    computeMacroArgsCache(MacroArgsCache, FID);
+
+  assert(!MacroArgsCache->empty());
+  MacroArgsMap::iterator I = MacroArgsCache->upper_bound(Offset);
   --I;
   
   unsigned MacroArgBeginOffs = I->first;
@@ -1720,13 +1721,12 @@
                << "B of Sloc address space used.\n";
   
   unsigned NumLineNumsComputed = 0;
-  unsigned NumMacroArgsComputed = 0;
   unsigned NumFileBytesMapped = 0;
   for (fileinfo_iterator I = fileinfo_begin(), E = fileinfo_end(); I != E; ++I){
     NumLineNumsComputed += I->second->SourceLineCache != 0;
-    NumMacroArgsComputed += I->second->MacroArgsCache != 0;
     NumFileBytesMapped  += I->second->getSizeBytesMapped();
   }
+  unsigned NumMacroArgsComputed = MacroArgsCacheMap.size();
 
   llvm::errs() << NumFileBytesMapped << " bytes of files mapped, "
                << NumLineNumsComputed << " files with line #'s computed, "




More information about the cfe-commits mailing list