]> granicus.if.org Git - clang/commitdiff
Start implementing the PTH IdentifierInfo-saving trick in PCH,
authorDouglas Gregor <dgregor@apple.com>
Sat, 25 Apr 2009 20:21:25 +0000 (20:21 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 25 Apr 2009 20:21:25 +0000 (20:21 +0000)
allocating IdentifierInfos with a pointer into the string data stored
in the PCH file rather than having an entry in the identifier table's
string map. However, we don't actually get these savings at the
moment, because we go through the IdentifierTable when loading
identifiers from the on-disk hash table.

This commit is for record-keeping purposes only. I'll be reverting
this change (and the PCH layout tweak that preceded it) because it
appears that implementing this optimization will collide with another,
future optimization to reduce the size of the on-disk hash table for
identifiers. That optimization is likely to provide more benefit (with
less voodoo).

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

include/clang/Basic/IdentifierTable.h
include/clang/Frontend/PCHReader.h
lib/Frontend/PCHReader.cpp

index 235c19081cda208942ddcf27818fc14660fde339..99580a17fe4ddbc0fc434d1deffee049581f76b2 100644 (file)
@@ -293,34 +293,6 @@ public:
     return *II;
   }
   
-  /// \brief Creates a new IdentifierInfo from the given string.
-  ///
-  /// This is a lower-level version of get() that requires that this
-  /// identifier not be known previously and that does not consult an
-  /// external source for identifiers. In particular, external
-  /// identifier sources can use this routine to build IdentifierInfo
-  /// nodes and then introduce additional information about those
-  /// identifiers.
-  IdentifierInfo &CreateIdentifierInfo(const char *NameStart, 
-                                       const char *NameEnd) {
-    llvm::StringMapEntry<IdentifierInfo*> &Entry =
-      HashTable.GetOrCreateValue(NameStart, NameEnd);
-    
-    IdentifierInfo *II = Entry.getValue();
-    assert(!II && "IdentifierInfo already exists");
-    
-    // Lookups failed, make a new IdentifierInfo.
-    void *Mem = getAllocator().Allocate<IdentifierInfo>();
-    II = new (Mem) IdentifierInfo();
-    Entry.setValue(II);
-
-    // Make sure getName() knows how to find the IdentifierInfo
-    // contents.
-    II->Entry = &Entry;
-
-    return *II;
-  }
-
   IdentifierInfo &get(const char *Name) {
     return get(Name, Name+strlen(Name));
   }
index 0c8520ceb44fa5db27dc60a8b32e610475163c1a..c6f7ad9301cde14f28dd02cac252828f8d7f1c90 100644 (file)
@@ -27,6 +27,7 @@
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Bitcode/BitstreamReader.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/DataTypes.h"
 #include <map>
 #include <string>
@@ -85,6 +86,9 @@ private:
   /// \brief The bitstream reader from which we'll read the PCH file.
   llvm::BitstreamReader Stream;
 
+  /// \brief Allocator used for IdentifierInfo objects.
+  llvm::BumpPtrAllocator Alloc;
+
   /// \brief The file name of the PCH file.
   std::string FileName;
 
@@ -370,6 +374,13 @@ public:
   IdentifierInfo *GetIdentifierInfo(const RecordData &Record, unsigned &Idx) {
     return DecodeIdentifierInfo(Record[Idx++]);
   }
+
+  /// \brief Builds a new IdentifierInfo object that refers to a
+  /// string stored within the PCH file.
+  ///
+  /// \brief Str must be a pointer into the start of a string within
+  /// IdentifierTableData.
+  IdentifierInfo &BuildIdentifierInfoInsidePCH(const unsigned char *Str);
   
   Selector DecodeSelector(unsigned Idx);
   
index 2d894774a165a8fab1ed605d9680e7829dae8324..918fd93fdd347236d30d084ce92154a1a607774d 100644 (file)
@@ -1282,8 +1282,7 @@ public:
     // the new IdentifierInfo.
     IdentifierInfo *II = KnownII;
     if (!II)
-      II = &Reader.getIdentifierTable().CreateIdentifierInfo(
-                                                 k.first, k.first + k.second);
+      II = &Reader.BuildIdentifierInfoInsidePCH((const unsigned char *)k.first);
     Reader.SetIdentifierInfo(ID, II);
 
     // Set or check the various bits in the IdentifierInfo structure.
@@ -2849,6 +2848,19 @@ IdentifierInfo *PCHReader::DecodeIdentifierInfo(unsigned ID) {
   return IdentifiersLoaded[ID - 1];
 }
 
+IdentifierInfo &
+PCHReader::BuildIdentifierInfoInsidePCH(const unsigned char *Str) {
+  // Allocate the object.
+  std::pair<IdentifierInfo,const unsigned char*> *Mem =
+    Alloc.Allocate<std::pair<IdentifierInfo,const unsigned char*> >();
+
+  // Build the IdentifierInfo itself.
+  Mem->second = Str;
+  assert(Str[0] != '\0');
+  IdentifierInfo *II = new ((void*) Mem) IdentifierInfo();
+  return *II;
+}
+
 Selector PCHReader::DecodeSelector(unsigned ID) {
   if (ID == 0)
     return Selector();