[llvm-commits] [llvm] r173065 - in /llvm/trunk: include/llvm/Bitcode/BitstreamReader.h lib/Bitcode/Reader/BitstreamReader.cpp

Chris Lattner sabre at nondot.org
Mon Jan 21 10:24:49 PST 2013


Author: lattner
Date: Mon Jan 21 12:24:49 2013
New Revision: 173065

URL: http://llvm.org/viewvc/llvm-project?rev=173065&view=rev
Log:
Fix a heinous inefficiency introduced in r149918, wherein reading each byte of a
BLOB (i.e., large, performance intensive data) in a bitcode file was switched to
invoking one virtual method call per byte read.  Now we do one virtual call per
BLOB.

Modified:
    llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
    llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp

Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=173065&r1=173064&r2=173065&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Mon Jan 21 12:24:49 2013
@@ -237,12 +237,6 @@
         static_cast<uint64_t>(pos - 1));
   }
 
-  unsigned char getByte(size_t pos) {
-    uint8_t byte = -1;
-    BitStream->getBitcodeBytes().readByte(pos, &byte);
-    return byte;
-  }
-
   uint32_t getWord(size_t pos) {
     uint8_t buf[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
     BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf, NULL);

Modified: llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp?rev=173065&r1=173064&r2=173065&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp Mon Jan 21 12:24:49 2013
@@ -255,18 +255,17 @@
       break;
     }
     
-    // Otherwise, read the number of bytes.  If we can return a reference to
-    // the data, do so to avoid copying it.
+    // Otherwise, inform the streamer that we need these bytes in memory.
+    const char *Ptr = (const char*)
+      BitStream->getBitcodeBytes().getPointer(CurBitPos/8, NumElts);
+    
+    // If we can return a reference to the data, do so to avoid copying it.
     if (Blob) {
-      *Blob =
-        StringRef((const char*)BitStream->getBitcodeBytes().getPointer(
-                                                          CurBitPos/8, NumElts),
-                  NumElts);
+      *Blob = StringRef(Ptr, NumElts);
     } else {
-      // FIXME: This is a brutally inefficient way to do this.  Why isn't this
-      // just using getPointer?      
+      // Otherwise, unpack into Vals with zero extension.
       for (; NumElts; --NumElts)
-        Vals.push_back(Read(8));
+        Vals.push_back((unsigned char)*Ptr++);
     }
     // Skip over tail padding.
     JumpToBit(NewEnd);





More information about the llvm-commits mailing list