add an abbreviation for the string constants opzn, shrinking the constnats
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.
llvm-svn: 36820
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index a29f23d..6cfa25a 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -411,7 +411,7 @@
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 @@
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 @@
} 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 @@
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;