diff options
author | Chris Lattner <sabre@nondot.org> | 2007-05-06 00:35:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-05-06 00:35:24 +0000 |
commit | ff7fc5dabef6931e7d23ee0613aa60e1d09dfbb0 (patch) | |
tree | 165c552417676e3b6ad51b6eecb27e089668cfac /lib/Bitcode | |
parent | abfbf85004b2114ee33e05fc9efe3a7bd044e402 (diff) |
implement the 'string constant' optimization. This shrinks kc.bit from
2878544 to 2815788
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36818 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 14 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 6 | ||||
-rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.cpp | 9 |
3 files changed, 25 insertions, 4 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 5a7c84da93..b1a001e1af 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -642,7 +642,21 @@ bool BitcodeReader::ParseConstants() { } break; } + case bitc::CST_CODE_STRING: { // STRING: [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])); + V = ConstantArray::get(ATy, Elts); + break; + } case bitc::CST_CODE_CE_BINOP: { // CE_BINOP: [opcode, opval, opval] if (Record.size() < 3) return Error("Invalid CE_BINOP record"); int Opc = GetDecodedBinaryOpcode(Record[0], CurTy); diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 7198bc0060..a29f23ddfc 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -484,6 +484,12 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, assert (CFP->getType() == Type::DoubleTy && "Unknown FP type!"); Record.push_back(DoubleToBits((double)CFP->getValue())); } + } else if (isa<ConstantArray>(C) && cast<ConstantArray>(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<ConstantInt>(C->getOperand(i))->getZExtValue()); + } else if (isa<ConstantArray>(C) || isa<ConstantStruct>(V) || isa<ConstantVector>(V)) { Code = bitc::CST_CODE_AGGREGATE; diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 6b753b2386..ae9e67c826 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "ValueEnumerator.h" +#include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/TypeSymbolTable.h" @@ -65,8 +66,6 @@ ValueEnumerator::ValueEnumerator(const Module *M) { I != E; ++I) EnumerateValue(I->getAliasee()); - // FIXME: Implement the 'string constant' optimization. - // Enumerate types used by the type symbol table. EnumerateTypeSymbolTable(M->getTypeSymbolTable()); @@ -105,8 +104,6 @@ ValueEnumerator::ValueEnumerator(const Module *M) { // Now that we rearranged the type table, rebuild TypeMap. for (unsigned i = 0, e = Types.size(); i != e; ++i) TypeMap[Types[i].first] = i+1; - - // FIXME: Sort value tables by frequency. } // Optimize constant ordering. @@ -176,6 +173,10 @@ void ValueEnumerator::EnumerateValue(const Value *V) { if (const Constant *C = dyn_cast<Constant>(V)) { if (isa<GlobalValue>(C)) { // Initializers for globals are handled explicitly elsewhere. + } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) { + // Do not enumerate the initializers for an array of simple characters. + // The initializers just polute the value table, and we emit the strings + // specially. } else { // This makes sure that if a constant has uses (for example an array of // const ints), that they are inserted also. |