[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Analyzer.cpp Reader.cpp Reader.h

Chris Lattner sabre at nondot.org
Mon Feb 12 10:54:02 PST 2007



Changes in directory llvm/lib/Bytecode/Reader:

Analyzer.cpp updated: 1.36 -> 1.37
Reader.cpp updated: 1.235 -> 1.236
Reader.h updated: 1.48 -> 1.49
---
Log message:

avoid creating a temporary string when reading the symbol table for a
module.  This speeds up the bcreader 11%.


---
Diffs of the changes:  (+26 -9)

 Analyzer.cpp |    4 ++--
 Reader.cpp   |   30 +++++++++++++++++++++++-------
 Reader.h     |    1 +
 3 files changed, 26 insertions(+), 9 deletions(-)


Index: llvm/lib/Bytecode/Reader/Analyzer.cpp
diff -u llvm/lib/Bytecode/Reader/Analyzer.cpp:1.36 llvm/lib/Bytecode/Reader/Analyzer.cpp:1.37
--- llvm/lib/Bytecode/Reader/Analyzer.cpp:1.36	Sat Feb 10 08:07:56 2007
+++ llvm/lib/Bytecode/Reader/Analyzer.cpp	Mon Feb 12 12:53:42 2007
@@ -250,10 +250,10 @@
   }
 
   virtual void handleSymbolTableValue(unsigned TySlot, unsigned ValSlot, 
-                                      const std::string& name) {
+                                      const char *Name, unsigned NameLen) {
     if (os)
       *os << "        Value " << TySlot << " Slot=" << ValSlot
-         << " Name: " << name << "\n";
+          << " Name: " << std::string(Name, Name+NameLen) << "\n";
     if (ValSlot > bca.maxValueSlot)
       bca.maxValueSlot = ValSlot;
   }


Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.235 llvm/lib/Bytecode/Reader/Reader.cpp:1.236
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.235	Wed Feb  7 15:41:01 2007
+++ llvm/lib/Bytecode/Reader/Reader.cpp	Mon Feb 12 12:53:43 2007
@@ -132,6 +132,17 @@
   return std::string((char*)OldAt, Size);
 }
 
+void BytecodeReader::read_str(SmallVectorImpl<char> &StrData) {
+  StrData.clear();
+  unsigned Size = read_vbr_uint();
+  const unsigned char *OldAt = At;
+  At += Size;
+  if (At > BlockEnd)             // Size invalid?
+    error("Ran out of data reading a string!");
+  StrData.append(OldAt, At);
+}
+
+
 /// Read an arbitrary block of data
 inline void BytecodeReader::read_data(void *Ptr, void *End) {
   unsigned char *Start = (unsigned char *)Ptr;
@@ -943,6 +954,8 @@
            E = CurrentFunction->end(); I != E; ++I)
       BBMap.push_back(I);
 
+  SmallVector<char, 32> NameStr;
+  
   while (moreInBlock()) {
     // Symtab block header: [num entries][type id number]
     unsigned NumEntries = read_vbr_uint();
@@ -951,19 +964,22 @@
     for (unsigned i = 0; i != NumEntries; ++i) {
       // Symtab entry: [def slot #][name]
       unsigned slot = read_vbr_uint();
-      std::string Name = read_str();
+      read_str(NameStr);
       Value *V = 0;
       if (Typ == LabelTySlot) {
-        if (slot < BBMap.size())
-          V = BBMap[slot];
+        V = (slot < BBMap.size()) ? BBMap[slot] : 0;
       } else {
-        V = getValue(Typ, slot, false); // Find mapping...
+        V = getValue(Typ, slot, false); // Find mapping.
       }
-      if (Handler) Handler->handleSymbolTableValue(Typ, slot, Name);
+      if (Handler) Handler->handleSymbolTableValue(Typ, slot,
+                                                   &NameStr[0], NameStr.size());
       if (V == 0)
-        error("Failed value look-up for name '" + Name + "', type #" + 
+        error("Failed value look-up for name '" + 
+              std::string(NameStr.begin(), NameStr.end()) + "', type #" + 
               utostr(Typ) + " slot #" + utostr(slot));
-      V->setName(Name);
+      V->setName(&NameStr[0], NameStr.size());
+      
+      NameStr.clear();
     }
   }
   checkPastBlockEnd("Symbol Table");


Index: llvm/lib/Bytecode/Reader/Reader.h
diff -u llvm/lib/Bytecode/Reader/Reader.h:1.48 llvm/lib/Bytecode/Reader/Reader.h:1.49
--- llvm/lib/Bytecode/Reader/Reader.h:1.48	Wed Feb  7 17:46:55 2007
+++ llvm/lib/Bytecode/Reader/Reader.h	Mon Feb 12 12:53:43 2007
@@ -438,6 +438,7 @@
 
   /// @brief Read a string
   inline std::string read_str();
+  inline void read_str(SmallVectorImpl<char> &StrData);
 
   /// @brief Read a float value
   inline void read_float(float& FloatVal);






More information about the llvm-commits mailing list