add an abbreviation for the string constants opzn, shrinking the constnats
authorChris Lattner <sabre@nondot.org>
Sun, 6 May 2007 00:42:18 +0000 (00:42 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 6 May 2007 00:42:18 +0000 (00:42 +0000)
block from:

  Block ID #11 (CONSTANTS_BLOCK):
      Num Instances: 1722
         Total Size: 3.85976e+06b/482470B/120617W
          % of file: 16.7609
       Average Size: 2241.44b/280.18B/70.045W
  Tot/Avg SubBlocks: 0/0
    Tot/Avg Abbrevs: 1/0.00058072
    Tot/Avg Records: 26423/15.3444
      % Abbrev Recs: 69.1746

to:

 Block ID #11 (CONSTANTS_BLOCK):
      Num Instances: 1724
         Total Size: 2.62406e+06b/328008B/82001.9W
          % of file: 12.041
       Average Size: 1522.08b/190.26B/47.5649W
  Tot/Avg SubBlocks: 0/0
    Tot/Avg Abbrevs: 2/0.00116009
    Tot/Avg Records: 26280/15.2436
      % Abbrev Recs: 68.9992

This shrinks kc++ from 2815788 to 2724088 bytes, which means the bitcode
file is now smaller than the bytecode file.

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

lib/Bitcode/Writer/BitcodeWriter.cpp

index a29f23ddfc1a76727abd33d6c8e5e5fb9872eb89..6cfa25ab74e0155f4d6d876f49f8b09ca72e0c40 100644 (file)
@@ -411,7 +411,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
   Stream.EnterSubblock(bitc::CONSTANTS_BLOCK_ID, 4);
 
   unsigned AggregateAbbrev = 0;
-  unsigned GEPAbbrev = 0;
+  unsigned String7Abbrev = 0;
   // If this is a constant pool for the module, emit module-specific abbrevs.
   if (isGlobal) {
     // Abbrev for CST_CODE_AGGREGATE.
@@ -420,6 +420,13 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
     Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
     Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, Log2_32_Ceil(LastVal+1)));
     AggregateAbbrev = Stream.EmitAbbrev(Abbv);
+
+    // Abbrev for CST_CODE_STRING.
+    Abbv = new BitCodeAbbrev();
+    Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_STRING));
+    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
+    Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
+    String7Abbrev = Stream.EmitAbbrev(Abbv);
   }  
   
   // FIXME: Install and use abbrevs to reduce size.  Install them globally so
@@ -487,9 +494,14 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
     } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {
       // Emit constant strings specially.
       Code = bitc::CST_CODE_STRING;
-      for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
-        Record.push_back(cast<ConstantInt>(C->getOperand(i))->getZExtValue());
-      
+      bool isStr7 = true;
+      for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
+        unsigned char V = cast<ConstantInt>(C->getOperand(i))->getZExtValue();
+        Record.push_back(V);
+        isStr7 &= (V & 128) == 0;
+      }
+      if (isStr7)
+        AbbrevToUse = String7Abbrev;
     } else if (isa<ConstantArray>(C) || isa<ConstantStruct>(V) ||
                isa<ConstantVector>(V)) {
       Code = bitc::CST_CODE_AGGREGATE;
@@ -519,7 +531,6 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
           Record.push_back(VE.getTypeID(C->getOperand(i)->getType()));
           Record.push_back(VE.getValueID(C->getOperand(i)));
         }
-        AbbrevToUse = GEPAbbrev;
         break;
       case Instruction::Select:
         Code = bitc::CST_CODE_CE_SELECT;