[llvm-commits] CVS: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Chris Lattner
sabre at nondot.org
Fri May 4 18:27:07 PDT 2007
Changes in directory llvm/lib/Bitcode/Writer:
BitcodeWriter.cpp updated: 1.37 -> 1.38
---
Log message:
add a char6 abbrev for bbnames and value names. This represents each character
with 6 bits where possible. This shrinks kc++ from 3324164B to 3183584B. The
old VST was:
Block ID #14 (VALUE_SYMTAB):
Total Size: 1.26713e+07b/1.58391e+06B/395978W
Average Size: 5403.53b/675.442B/168.86W
% of file: 47.6484
The new one is:
Block ID #14 (VALUE_SYMTAB):
Total Size: 1.15467e+07b/1.44334e+06B/360834W
Average Size: 4923.96b/615.495B/153.874W
% of file: 45.3368
This is 11% smaller than the VST in the bytecode format.
---
Diffs of the changes: (+30 -12)
BitcodeWriter.cpp | 42 ++++++++++++++++++++++++++++++------------
1 files changed, 30 insertions(+), 12 deletions(-)
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
diff -u llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1.37 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1.38
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1.37 Fri May 4 19:47:19 2007
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp Fri May 4 20:26:50 2007
@@ -33,8 +33,8 @@
// VALUE_SYMTAB_BLOCK abbrev id's.
VST_ENTRY_8_ABBREV = bitc::FIRST_APPLICATION_ABBREV,
VST_ENTRY_7_ABBREV,
- VST_BBENTRY_7_ABBREV
-
+ VST_ENTRY_6_ABBREV,
+ VST_BBENTRY_6_ABBREV
};
@@ -712,7 +712,7 @@
const ValueEnumerator &VE,
BitstreamWriter &Stream) {
if (VST.empty()) return;
- Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 3);
+ Stream.EnterSubblock(bitc::VALUE_SYMTAB_BLOCK_ID, 4);
// FIXME: Set up the abbrev, we know how many values there are!
// FIXME: We know if the type names can use 7-bit ascii.
@@ -725,12 +725,16 @@
// Figure out the encoding to use for the name.
bool is7Bit = true;
- for (unsigned i = 0, e = Name.getKeyLength(); i != e; ++i)
- if ((unsigned char)Name.getKeyData()[i] & 128) {
+ bool isChar6 = true;
+ for (const char *C = Name.getKeyData(), *E = C+Name.getKeyLength();
+ C != E; ++C) {
+ if (isChar6)
+ isChar6 = BitCodeAbbrevOp::isChar6(*C);
+ if ((unsigned char)*C & 128) {
is7Bit = false;
- break;
+ break; // don't bother scanning the rest.
}
-
+ }
unsigned AbbrevToUse = VST_ENTRY_8_ABBREV;
@@ -739,10 +743,14 @@
unsigned Code;
if (isa<BasicBlock>(SI->getValue())) {
Code = bitc::VST_CODE_BBENTRY;
- if (is7Bit) AbbrevToUse = VST_BBENTRY_7_ABBREV;
+ if (isChar6)
+ AbbrevToUse = VST_BBENTRY_6_ABBREV;
} else {
Code = bitc::VST_CODE_ENTRY;
- if (is7Bit) AbbrevToUse = VST_ENTRY_7_ABBREV;
+ if (isChar6)
+ AbbrevToUse = VST_ENTRY_6_ABBREV;
+ else if (is7Bit)
+ AbbrevToUse = VST_ENTRY_7_ABBREV;
}
NameVals.push_back(VE.getValueID(SI->getValue()));
@@ -910,14 +918,24 @@
Abbv) != VST_ENTRY_7_ABBREV)
assert(0 && "Unexpected abbrev ordering!");
}
- { // 7-bit fixed width VST_BBENTRY strings.
+ { // 6-bit char6 VST_ENTRY strings.
+ BitCodeAbbrev *Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_ENTRY));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
+ if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID,
+ Abbv) != VST_ENTRY_6_ABBREV)
+ assert(0 && "Unexpected abbrev ordering!");
+ }
+ { // 6-bit char6 VST_BBENTRY strings.
BitCodeAbbrev *Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::VST_CODE_BBENTRY));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
- Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
if (Stream.EmitBlockInfoAbbrev(bitc::VALUE_SYMTAB_BLOCK_ID,
- Abbv) != VST_BBENTRY_7_ABBREV)
+ Abbv) != VST_BBENTRY_6_ABBREV)
assert(0 && "Unexpected abbrev ordering!");
}
More information about the llvm-commits
mailing list