llvm.org GIT mirror llvm / cb3d91b
add a denser encoding for null terminated strings, add a 6-bit abbrev as well. This shrinks kc++ from 2724088 to 2717360 bytes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36821 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
4 changed file(s) with 62 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
106106 CST_CODE_FLOAT = 6, // FLOAT: [fpval]
107107 CST_CODE_AGGREGATE = 7, // AGGREGATE: [n x value number]
108108 CST_CODE_STRING = 8, // STRING: [values]
109 CST_CODE_CE_BINOP = 9, // CE_BINOP: [opcode, opval, opval]
110 CST_CODE_CE_CAST = 10, // CE_CAST: [opcode, opty, opval]
111 CST_CODE_CE_GEP = 11, // CE_GEP: [n x operands]
112 CST_CODE_CE_SELECT = 12, // CE_SELECT: [opval, opval, opval]
113 CST_CODE_CE_EXTRACTELT = 13, // CE_EXTRACTELT: [opty, opval, opval]
114 CST_CODE_CE_INSERTELT = 14, // CE_INSERTELT: [opval, opval, opval]
115 CST_CODE_CE_SHUFFLEVEC = 15, // CE_SHUFFLEVEC: [opval, opval, opval]
116 CST_CODE_CE_CMP = 16 // CE_CMP: [opty, opval, opval, pred]
109 CST_CODE_CSTRING = 9, // CSTRING: [values]
110 CST_CODE_CE_BINOP = 10, // CE_BINOP: [opcode, opval, opval]
111 CST_CODE_CE_CAST = 11, // CE_CAST: [opcode, opty, opval]
112 CST_CODE_CE_GEP = 12, // CE_GEP: [n x operands]
113 CST_CODE_CE_SELECT = 13, // CE_SELECT: [opval, opval, opval]
114 CST_CODE_CE_EXTRACTELT = 14, // CE_EXTRACTELT: [opty, opval, opval]
115 CST_CODE_CE_INSERTELT = 15, // CE_INSERTELT: [opval, opval, opval]
116 CST_CODE_CE_SHUFFLEVEC = 16, // CE_SHUFFLEVEC: [opval, opval, opval]
117 CST_CODE_CE_CMP = 17 // CE_CMP: [opty, opval, opval, pred]
117118 };
118119
119120 /// CastOpcodes - These are values used in the bitcode files to encode which
650650
651651 unsigned Size = Record.size();
652652 std::vector Elts;
653
654653 for (unsigned i = 0; i != Size; ++i)
655654 Elts.push_back(ConstantInt::get(EltTy, Record[i]));
655 V = ConstantArray::get(ATy, Elts);
656 break;
657 }
658 case bitc::CST_CODE_CSTRING: { // CSTRING: [values]
659 if (Record.empty())
660 return Error("Invalid CST_AGGREGATE record");
661
662 const ArrayType *ATy = cast(CurTy);
663 const Type *EltTy = ATy->getElementType();
664
665 unsigned Size = Record.size();
666 std::vector Elts;
667 for (unsigned i = 0; i != Size; ++i)
668 Elts.push_back(ConstantInt::get(EltTy, Record[i]));
669 Elts.push_back(Constant::getNullValue(EltTy));
656670 V = ConstantArray::get(ATy, Elts);
657671 break;
658672 }
410410 Stream.EnterSubblock(bitc::CONSTANTS_BLOCK_ID, 4);
411411
412412 unsigned AggregateAbbrev = 0;
413 unsigned String7Abbrev = 0;
413 unsigned String8Abbrev = 0;
414 unsigned CString7Abbrev = 0;
415 unsigned CString6Abbrev = 0;
414416 // If this is a constant pool for the module, emit module-specific abbrevs.
415417 if (isGlobal) {
416418 // Abbrev for CST_CODE_AGGREGATE.
424426 Abbv = new BitCodeAbbrev();
425427 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_STRING));
426428 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
429 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
430 String8Abbrev = Stream.EmitAbbrev(Abbv);
431 // Abbrev for CST_CODE_CSTRING.
432 Abbv = new BitCodeAbbrev();
433 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_CSTRING));
434 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
427435 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
428 String7Abbrev = Stream.EmitAbbrev(Abbv);
436 CString7Abbrev = Stream.EmitAbbrev(Abbv);
437 // Abbrev for CST_CODE_CSTRING.
438 Abbv = new BitCodeAbbrev();
439 Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_CSTRING));
440 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
441 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6));
442 CString6Abbrev = Stream.EmitAbbrev(Abbv);
429443 }
430444
431445 // FIXME: Install and use abbrevs to reduce size. Install them globally so
492506 }
493507 } else if (isa(C) && cast(C)->isString()) {
494508 // Emit constant strings specially.
495 Code = bitc::CST_CODE_STRING;
496 bool isStr7 = true;
497 for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
509 unsigned NumOps = C->getNumOperands();
510 // If this is a null-terminated string, use the denser CSTRING encoding.
511 if (C->getOperand(NumOps-1)->isNullValue()) {
512 Code = bitc::CST_CODE_CSTRING;
513 --NumOps; // Don't encode the null, which isn't allowed by char6.
514 } else {
515 Code = bitc::CST_CODE_STRING;
516 AbbrevToUse = String8Abbrev;
517 }
518 bool isCStr7 = Code == bitc::CST_CODE_CSTRING;
519 bool isCStrChar6 = Code == bitc::CST_CODE_CSTRING;
520 for (unsigned i = 0; i != NumOps; ++i) {
498521 unsigned char V = cast(C->getOperand(i))->getZExtValue();
499522 Record.push_back(V);
500 isStr7 &= (V & 128) == 0;
523 isCStr7 &= (V & 128) == 0;
524 if (isCStrChar6)
525 isCStrChar6 = BitCodeAbbrevOp::isChar6(V);
501526 }
502 if (isStr7)
503 AbbrevToUse = String7Abbrev;
527
528 if (isCStrChar6)
529 AbbrevToUse = CString6Abbrev;
530 else if (isCStr7)
531 AbbrevToUse = CString7Abbrev;
504532 } else if (isa(C) || isa(V) ||
505533 isa(V)) {
506534 Code = bitc::CST_CODE_AGGREGATE;
162162 case bitc::CST_CODE_WIDE_INTEGER: return "WIDE_INTEGER";
163163 case bitc::CST_CODE_FLOAT: return "FLOAT";
164164 case bitc::CST_CODE_AGGREGATE: return "AGGREGATE";
165 case bitc::CST_CODE_STRING: return "STRING";
166 case bitc::CST_CODE_CSTRING: return "CSTRING";
165167 case bitc::CST_CODE_CE_BINOP: return "CE_BINOP";
166168 case bitc::CST_CODE_CE_CAST: return "CE_CAST";
167169 case bitc::CST_CODE_CE_GEP: return "CE_GEP";