[llvm-commits] CVS: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Chris Lattner
sabre at nondot.org
Fri May 4 23:30:30 PDT 2007
Changes in directory llvm/lib/Bitcode/Writer:
BitcodeWriter.cpp updated: 1.38 -> 1.39
---
Log message:
Add abbreviations to the TYPE_BLOCK for pointers, functions, structs and arrays.
This shrinks the type_block of kc++ from 139901 bits to 99389 bits (0.55% to 0.39%
of the file), a 40% reduction.
This shrink the record from:
Block ID #10 (TYPE_BLOCK):
Num Instances: 1
Total Size: 139901b/17487.6B/4371.91W
% of file: 0.549306
Num Abbrevs: 0
Num Records: 3203
% Abbrev Recs: 0
to:
Block ID #10 (TYPE_BLOCK):
Num Instances: 1
Total Size: 99389b/12423.6B/3105.91W
% of file: 0.390862
Num Abbrevs: 4
Num Records: 3203
% Abbrev Recs: 99.6566
With a common histogram of:
Code Histogram:
1613 POINTER
1100 FUNCTION
255 STRUCT
224 ARRAY
5 INTEGER
2 OPAQUE
1 LABEL
1 DOUBLE
1 VOID
1 NUMENTRY
---
Diffs of the changes: (+40 -3)
BitcodeWriter.cpp | 43 ++++++++++++++++++++++++++++++++++++++++---
1 files changed, 40 insertions(+), 3 deletions(-)
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
diff -u llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1.38 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1.39
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp:1.38 Fri May 4 20:26:50 2007
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp Sat May 5 01:30:12 2007
@@ -121,7 +121,40 @@
Stream.EnterSubblock(bitc::TYPE_BLOCK_ID, 4 /*count from # abbrevs */);
SmallVector<uint64_t, 64> TypeVals;
- // FIXME: Set up abbrevs now that we know the width of the type fields, etc.
+ // Abbrev for TYPE_CODE_POINTER.
+ BitCodeAbbrev *Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_POINTER));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
+ Log2_32_Ceil(VE.getTypes().size()+1)));
+ unsigned PtrAbbrev = Stream.EmitAbbrev(Abbv);
+
+ // Abbrev for TYPE_CODE_FUNCTION.
+ Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_FUNCTION));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isvararg
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
+ Log2_32_Ceil(VE.getParamAttrs().size()+1)));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
+ Log2_32_Ceil(VE.getTypes().size()+1)));
+ unsigned FunctionAbbrev = Stream.EmitAbbrev(Abbv);
+
+ // Abbrev for TYPE_CODE_STRUCT.
+ Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
+ Log2_32_Ceil(VE.getTypes().size()+1)));
+ unsigned StructAbbrev = Stream.EmitAbbrev(Abbv);
+
+ // Abbrev for TYPE_CODE_ARRAY.
+ Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // size
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
+ Log2_32_Ceil(VE.getTypes().size()+1)));
+ unsigned ArrayAbbrev = Stream.EmitAbbrev(Abbv);
// Emit an entry count so the reader can reserve space.
TypeVals.push_back(TypeList.size());
@@ -151,28 +184,31 @@
// POINTER: [pointee type]
Code = bitc::TYPE_CODE_POINTER;
TypeVals.push_back(VE.getTypeID(cast<PointerType>(T)->getElementType()));
+ AbbrevToUse = PtrAbbrev;
break;
case Type::FunctionTyID: {
const FunctionType *FT = cast<FunctionType>(T);
- // FUNCTION: [isvararg, attrid, #pararms, paramty x N]
+ // FUNCTION: [isvararg, attrid, retty, paramty x N]
Code = bitc::TYPE_CODE_FUNCTION;
TypeVals.push_back(FT->isVarArg());
TypeVals.push_back(VE.getParamAttrID(FT->getParamAttrs()));
TypeVals.push_back(VE.getTypeID(FT->getReturnType()));
for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
TypeVals.push_back(VE.getTypeID(FT->getParamType(i)));
+ AbbrevToUse = FunctionAbbrev;
break;
}
case Type::StructTyID: {
const StructType *ST = cast<StructType>(T);
- // STRUCT: [ispacked, #elts, eltty x N]
+ // STRUCT: [ispacked, eltty x N]
Code = bitc::TYPE_CODE_STRUCT;
TypeVals.push_back(ST->isPacked());
// Output all of the element types.
for (StructType::element_iterator I = ST->element_begin(),
E = ST->element_end(); I != E; ++I)
TypeVals.push_back(VE.getTypeID(*I));
+ AbbrevToUse = StructAbbrev;
break;
}
case Type::ArrayTyID: {
@@ -181,6 +217,7 @@
Code = bitc::TYPE_CODE_ARRAY;
TypeVals.push_back(AT->getNumElements());
TypeVals.push_back(VE.getTypeID(AT->getElementType()));
+ AbbrevToUse = ArrayAbbrev;
break;
}
case Type::VectorTyID: {
More information about the llvm-commits
mailing list