Save another 30K from 176.gcc by encoding the compaction table a bit more
authorChris Lattner <sabre@nondot.org>
Sun, 18 Jan 2004 22:35:34 +0000 (22:35 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 18 Jan 2004 22:35:34 +0000 (22:35 +0000)
intelligently.

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

lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Writer/Writer.cpp

index 2067f222110a9bb6d5bdf1fee99c008b88feb905..f4b620ed19a0305d8cad922fc2a25b06b5b641d5 100644 (file)
@@ -496,8 +496,22 @@ void BytecodeParser::ParseCompactionTable(const unsigned char *&Buf,
                                           const unsigned char *End) {
 
   while (Buf != End) {
-    unsigned NumEntries = read_vbr_uint(Buf, End);
-    unsigned Ty         = read_vbr_uint(Buf, End);
+    unsigned NumEntries;
+    unsigned Ty;
+
+    NumEntries = read_vbr_uint(Buf, End);
+    switch (NumEntries & 3) {
+    case 0:
+    case 1:
+    case 2:
+      Ty = NumEntries >> 2;
+      NumEntries &= 3;
+      break;
+    case 3:
+      NumEntries >>= 2;
+      Ty = read_vbr_uint(Buf, End);
+      break;
+    }
 
     if (Ty >= CompactionTable.size())
       CompactionTable.resize(Ty+1);
@@ -513,11 +527,10 @@ void BytecodeParser::ParseCompactionTable(const unsigned char *&Buf,
 
       CompactionTable.resize(NumEntries+Type::FirstDerivedTyID);
     } else {
-      assert(NumEntries != 0 && "Cannot read zero entries!");
       const Type *Typ = getType(Ty);
       // Push the implicit zero
       CompactionTable[Ty].push_back(Constant::getNullValue(Typ));
-      for (unsigned i = 1; i != NumEntries; ++i) {
+      for (unsigned i = 0; i != NumEntries; ++i) {
         Value *V = getGlobalTableValue(Typ, read_vbr_uint(Buf, End));
         CompactionTable[Ty].push_back(V);
       }
index d0b04d2dabfdc135be875c34ac459243ccf22cbd..a55508e6e0aa3a977168c1788fdef69528fb06e5 100644 (file)
@@ -293,12 +293,24 @@ void BytecodeWriter::outputCompactionTablePlane(unsigned PlaneNo,
   assert(StartNo < End && "Cannot emit negative range!");
   assert(StartNo < Plane.size() && End <= Plane.size());
 
-  output_vbr(unsigned(End-StartNo), Out);   // Output the number of things.
-  output_vbr(PlaneNo, Out);                 // Emit the type plane this is
-
   // Do not emit the null initializer!
   if (PlaneNo != Type::TypeTyID) ++StartNo;
 
+  // Figure out which encoding to use.  By far the most common case we have is
+  // to emit 0-2 entries in a compaction table plane.
+  switch (End-StartNo) {
+  case 0:         // Avoid emitting two vbr's if possible.
+  case 1:
+  case 2:
+    output_vbr((PlaneNo << 2) | End-StartNo, Out);
+    break;
+  default:
+    // Output the number of things.
+    output_vbr((unsigned(End-StartNo) << 2) | 3, Out);
+    output_vbr(PlaneNo, Out);                 // Emit the type plane this is
+    break;
+  }
+
   for (unsigned i = StartNo; i != End; ++i)
     output_vbr(Table.getGlobalSlot(Plane[i]), Out);
 }