From 817f08a0e5b4d5e697956b547a18968e62586479 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 6 May 2007 00:42:18 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36820 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Writer/BitcodeWriter.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index a29f23ddfc..6cfa25ab74 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -411,7 +411,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, 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 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, 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 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, } else if (isa(C) && cast(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(C->getOperand(i))->getZExtValue()); - + bool isStr7 = true; + for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) { + unsigned char V = cast(C->getOperand(i))->getZExtValue(); + Record.push_back(V); + isStr7 &= (V & 128) == 0; + } + if (isStr7) + AbbrevToUse = String7Abbrev; } else if (isa(C) || isa(V) || isa(V)) { Code = bitc::CST_CODE_AGGREGATE; @@ -519,7 +531,6 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, 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; -- cgit v1.2.3-18-g5258