1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

add a denser encoding for null terminated strings, add a 6-bit abbrev as

well.  This shrinks kc++ from 2724088 to 2717360 bytes.

llvm-svn: 36821
This commit is contained in:
Chris Lattner 2007-05-06 00:53:07 +00:00
parent 63002bb235
commit 6d0c5eb739
4 changed files with 62 additions and 17 deletions

View File

@ -107,14 +107,15 @@ namespace bitc {
CST_CODE_FLOAT = 6, // FLOAT: [fpval] CST_CODE_FLOAT = 6, // FLOAT: [fpval]
CST_CODE_AGGREGATE = 7, // AGGREGATE: [n x value number] CST_CODE_AGGREGATE = 7, // AGGREGATE: [n x value number]
CST_CODE_STRING = 8, // STRING: [values] CST_CODE_STRING = 8, // STRING: [values]
CST_CODE_CE_BINOP = 9, // CE_BINOP: [opcode, opval, opval] CST_CODE_CSTRING = 9, // CSTRING: [values]
CST_CODE_CE_CAST = 10, // CE_CAST: [opcode, opty, opval] CST_CODE_CE_BINOP = 10, // CE_BINOP: [opcode, opval, opval]
CST_CODE_CE_GEP = 11, // CE_GEP: [n x operands] CST_CODE_CE_CAST = 11, // CE_CAST: [opcode, opty, opval]
CST_CODE_CE_SELECT = 12, // CE_SELECT: [opval, opval, opval] CST_CODE_CE_GEP = 12, // CE_GEP: [n x operands]
CST_CODE_CE_EXTRACTELT = 13, // CE_EXTRACTELT: [opty, opval, opval] CST_CODE_CE_SELECT = 13, // CE_SELECT: [opval, opval, opval]
CST_CODE_CE_INSERTELT = 14, // CE_INSERTELT: [opval, opval, opval] CST_CODE_CE_EXTRACTELT = 14, // CE_EXTRACTELT: [opty, opval, opval]
CST_CODE_CE_SHUFFLEVEC = 15, // CE_SHUFFLEVEC: [opval, opval, opval] CST_CODE_CE_INSERTELT = 15, // CE_INSERTELT: [opval, opval, opval]
CST_CODE_CE_CMP = 16 // CE_CMP: [opty, opval, opval, pred] CST_CODE_CE_SHUFFLEVEC = 16, // CE_SHUFFLEVEC: [opval, opval, opval]
CST_CODE_CE_CMP = 17 // CE_CMP: [opty, opval, opval, pred]
}; };
/// CastOpcodes - These are values used in the bitcode files to encode which /// CastOpcodes - These are values used in the bitcode files to encode which

View File

@ -651,12 +651,26 @@ bool BitcodeReader::ParseConstants() {
unsigned Size = Record.size(); unsigned Size = Record.size();
std::vector<Constant*> Elts; std::vector<Constant*> Elts;
for (unsigned i = 0; i != Size; ++i) for (unsigned i = 0; i != Size; ++i)
Elts.push_back(ConstantInt::get(EltTy, Record[i])); Elts.push_back(ConstantInt::get(EltTy, Record[i]));
V = ConstantArray::get(ATy, Elts); V = ConstantArray::get(ATy, Elts);
break; break;
} }
case bitc::CST_CODE_CSTRING: { // CSTRING: [values]
if (Record.empty())
return Error("Invalid CST_AGGREGATE record");
const ArrayType *ATy = cast<ArrayType>(CurTy);
const Type *EltTy = ATy->getElementType();
unsigned Size = Record.size();
std::vector<Constant*> Elts;
for (unsigned i = 0; i != Size; ++i)
Elts.push_back(ConstantInt::get(EltTy, Record[i]));
Elts.push_back(Constant::getNullValue(EltTy));
V = ConstantArray::get(ATy, Elts);
break;
}
case bitc::CST_CODE_CE_BINOP: { // CE_BINOP: [opcode, opval, opval] case bitc::CST_CODE_CE_BINOP: { // CE_BINOP: [opcode, opval, opval]
if (Record.size() < 3) return Error("Invalid CE_BINOP record"); if (Record.size() < 3) return Error("Invalid CE_BINOP record");
int Opc = GetDecodedBinaryOpcode(Record[0], CurTy); int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);

View File

@ -411,7 +411,9 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
Stream.EnterSubblock(bitc::CONSTANTS_BLOCK_ID, 4); Stream.EnterSubblock(bitc::CONSTANTS_BLOCK_ID, 4);
unsigned AggregateAbbrev = 0; unsigned AggregateAbbrev = 0;
unsigned String7Abbrev = 0; unsigned String8Abbrev = 0;
unsigned CString7Abbrev = 0;
unsigned CString6Abbrev = 0;
// If this is a constant pool for the module, emit module-specific abbrevs. // If this is a constant pool for the module, emit module-specific abbrevs.
if (isGlobal) { if (isGlobal) {
// Abbrev for CST_CODE_AGGREGATE. // Abbrev for CST_CODE_AGGREGATE.
@ -425,8 +427,20 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
Abbv = new BitCodeAbbrev(); Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_STRING)); Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_STRING));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
String8Abbrev = Stream.EmitAbbrev(Abbv);
// Abbrev for CST_CODE_CSTRING.
Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_CSTRING));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
String7Abbrev = Stream.EmitAbbrev(Abbv); CString7Abbrev = Stream.EmitAbbrev(Abbv);
// Abbrev for CST_CODE_CSTRING.
Abbv = new BitCodeAbbrev();
Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_CSTRING));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
CString6Abbrev = Stream.EmitAbbrev(Abbv);
} }
// FIXME: Install and use abbrevs to reduce size. Install them globally so // FIXME: Install and use abbrevs to reduce size. Install them globally so
@ -493,15 +507,29 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
} }
} else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) { } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {
// Emit constant strings specially. // Emit constant strings specially.
Code = bitc::CST_CODE_STRING; unsigned NumOps = C->getNumOperands();
bool isStr7 = true; // If this is a null-terminated string, use the denser CSTRING encoding.
for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) { if (C->getOperand(NumOps-1)->isNullValue()) {
Code = bitc::CST_CODE_CSTRING;
--NumOps; // Don't encode the null, which isn't allowed by char6.
} else {
Code = bitc::CST_CODE_STRING;
AbbrevToUse = String8Abbrev;
}
bool isCStr7 = Code == bitc::CST_CODE_CSTRING;
bool isCStrChar6 = Code == bitc::CST_CODE_CSTRING;
for (unsigned i = 0; i != NumOps; ++i) {
unsigned char V = cast<ConstantInt>(C->getOperand(i))->getZExtValue(); unsigned char V = cast<ConstantInt>(C->getOperand(i))->getZExtValue();
Record.push_back(V); Record.push_back(V);
isStr7 &= (V & 128) == 0; isCStr7 &= (V & 128) == 0;
if (isCStrChar6)
isCStrChar6 = BitCodeAbbrevOp::isChar6(V);
} }
if (isStr7)
AbbrevToUse = String7Abbrev; if (isCStrChar6)
AbbrevToUse = CString6Abbrev;
else if (isCStr7)
AbbrevToUse = CString7Abbrev;
} else if (isa<ConstantArray>(C) || isa<ConstantStruct>(V) || } else if (isa<ConstantArray>(C) || isa<ConstantStruct>(V) ||
isa<ConstantVector>(V)) { isa<ConstantVector>(V)) {
Code = bitc::CST_CODE_AGGREGATE; Code = bitc::CST_CODE_AGGREGATE;

View File

@ -163,6 +163,8 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID) {
case bitc::CST_CODE_WIDE_INTEGER: return "WIDE_INTEGER"; case bitc::CST_CODE_WIDE_INTEGER: return "WIDE_INTEGER";
case bitc::CST_CODE_FLOAT: return "FLOAT"; case bitc::CST_CODE_FLOAT: return "FLOAT";
case bitc::CST_CODE_AGGREGATE: return "AGGREGATE"; case bitc::CST_CODE_AGGREGATE: return "AGGREGATE";
case bitc::CST_CODE_STRING: return "STRING";
case bitc::CST_CODE_CSTRING: return "CSTRING";
case bitc::CST_CODE_CE_BINOP: return "CE_BINOP"; case bitc::CST_CODE_CE_BINOP: return "CE_BINOP";
case bitc::CST_CODE_CE_CAST: return "CE_CAST"; case bitc::CST_CODE_CE_CAST: return "CE_CAST";
case bitc::CST_CODE_CE_GEP: return "CE_GEP"; case bitc::CST_CODE_CE_GEP: return "CE_GEP";