Changes in directory llvm/include/llvm/Bitcode:
BitCodes.h updated: 1.4 -> 1.5 BitstreamReader.h updated: 1.13 -> 1.14 BitstreamWriter.h updated: 1.8 -> 1.9 --- Log message: add support for array abbreviations. --- Diffs of the changes: (+101 -59) BitCodes.h | 22 ++++++++++--- BitstreamReader.h | 52 +++++++++++++++++++++----------- BitstreamWriter.h | 86 ++++++++++++++++++++++++++++++------------------------ 3 files changed, 101 insertions(+), 59 deletions(-) Index: llvm/include/llvm/Bitcode/BitCodes.h diff -u llvm/include/llvm/Bitcode/BitCodes.h:1.4 llvm/include/llvm/Bitcode/BitCodes.h:1.5 --- llvm/include/llvm/Bitcode/BitCodes.h:1.4 Fri May 4 13:25:49 2007 +++ llvm/include/llvm/Bitcode/BitCodes.h Fri May 4 15:33:47 2007 @@ -84,13 +84,15 @@ unsigned Enc : 3; // The encoding to use. public: enum Encoding { - FixedWidth = 1, // A fixed with field, Val specifies number of bits. - VBR = 2 // A VBR field where Val specifies the width of each chunk. + Fixed = 1, // A fixed with field, Val specifies number of bits. + VBR = 2, // A VBR field where Val specifies the width of each chunk. + Array = 3 // A sequence of fields, next field species elt encoding. }; BitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {} - BitCodeAbbrevOp(Encoding E, uint64_t Data) + BitCodeAbbrevOp(Encoding E, uint64_t Data = 0) : Val(Data), IsLiteral(false), Enc(E) {} + bool isLiteral() const { return IsLiteral; } bool isEncoding() const { return !IsLiteral; } @@ -100,11 +102,21 @@ // Accessors for encoding info. Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; } - uint64_t getEncodingData() const { assert(isEncoding()); return Val; } + uint64_t getEncodingData() const { + assert(isEncoding() && hasEncodingData()); + return Val; + } bool hasEncodingData() const { return hasEncodingData(getEncoding()); } static bool hasEncodingData(Encoding E) { - return true; + switch (E) { + default: assert(0 && "Unknown encoding"); + case Fixed: + case VBR: + return true; + case Array: + return false; + } } }; Index: llvm/include/llvm/Bitcode/BitstreamReader.h diff -u llvm/include/llvm/Bitcode/BitstreamReader.h:1.13 llvm/include/llvm/Bitcode/BitstreamReader.h:1.14 --- llvm/include/llvm/Bitcode/BitstreamReader.h:1.13 Fri May 4 13:25:49 2007 +++ llvm/include/llvm/Bitcode/BitstreamReader.h Fri May 4 15:33:47 2007 @@ -274,6 +274,26 @@ // Record Processing //===--------------------------------------------------------------------===// +private: + void ReadAbbreviatedField(const BitCodeAbbrevOp &Op, + SmallVectorImpl<uint64_t> &Vals) { + if (Op.isLiteral()) { + // If the abbrev specifies the literal value to use, use it. + Vals.push_back(Op.getLiteralValue()); + } else { + // Decode the value as we are commanded. + switch (Op.getEncoding()) { + default: assert(0 && "Unknown encoding!"); + case BitCodeAbbrevOp::Fixed: + Vals.push_back(Read(Op.getEncodingData())); + break; + case BitCodeAbbrevOp::VBR: + Vals.push_back(ReadVBR64(Op.getEncodingData())); + break; + } + } + } +public: unsigned ReadRecord(unsigned AbbrevID, SmallVectorImpl<uint64_t> &Vals) { if (AbbrevID == bitc::UNABBREV_RECORD) { unsigned Code = ReadVBR(6); @@ -289,20 +309,19 @@ for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); - if (Op.isLiteral()) { - // If the abbrev specifies the literal value to use, use it. - Vals.push_back(Op.getLiteralValue()); + if (Op.isLiteral() || Op.getEncoding() != BitCodeAbbrevOp::Array) { + ReadAbbreviatedField(Op, Vals); } else { - // Decode the value as we are commanded. - switch (Op.getEncoding()) { - default: assert(0 && "Unknown encoding!"); - case BitCodeAbbrevOp::FixedWidth: - Vals.push_back(Read(Op.getEncodingData())); - break; - case BitCodeAbbrevOp::VBR: - Vals.push_back(ReadVBR64(Op.getEncodingData())); - break; - } + // Array case. Read the number of elements as a vbr6. + unsigned NumElts = ReadVBR(6); + + // Get the element encoding. + assert(i+2 == e && "array op not second to last?"); + const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); + + // Read all the elements. + for (; NumElts; --NumElts) + ReadAbbreviatedField(EltEnc, Vals); } } @@ -326,11 +345,10 @@ } BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3); - if (BitCodeAbbrevOp::hasEncodingData(E)) { + if (BitCodeAbbrevOp::hasEncodingData(E)) Abbv->Add(BitCodeAbbrevOp(E, ReadVBR64(5))); - } else { - assert(0 && "unimp"); - } + else + Abbv->Add(BitCodeAbbrevOp(E)); } CurAbbrevs.push_back(Abbv); } Index: llvm/include/llvm/Bitcode/BitstreamWriter.h diff -u llvm/include/llvm/Bitcode/BitstreamWriter.h:1.8 llvm/include/llvm/Bitcode/BitstreamWriter.h:1.9 --- llvm/include/llvm/Bitcode/BitstreamWriter.h:1.8 Fri May 4 13:25:49 2007 +++ llvm/include/llvm/Bitcode/BitstreamWriter.h Fri May 4 15:33:47 2007 @@ -189,6 +189,32 @@ // Record Emission //===--------------------------------------------------------------------===// +private: + /// EmitAbbreviatedField - Emit a single scalar field value with the specified + /// encoding. + template<typename uintty> + void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) { + if (Op.isLiteral()) { + // If the abbrev specifies the literal value to use, don't emit + // anything. + assert(V == Op.getLiteralValue() && + "Invalid abbrev for record!"); + return; + } + + // Encode the value as we are commanded. + switch (Op.getEncoding()) { + default: assert(0 && "Unknown encoding!"); + case BitCodeAbbrevOp::Fixed: + Emit(V, Op.getEncodingData()); + break; + case BitCodeAbbrevOp::VBR: + EmitVBR(V, Op.getEncodingData()); + break; + } + } +public: + /// EmitRecord - Emit the specified record to the stream, using an abbrev if /// we have one to compress the output. void EmitRecord(unsigned Code, SmallVectorImpl<uint64_t> &Vals, @@ -207,27 +233,20 @@ for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { assert(RecordIdx < Vals.size() && "Invalid abbrev/record"); const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); - uint64_t RecordVal = Vals[RecordIdx]; - - if (Op.isLiteral()) { - // If the abbrev specifies the literal value to use, don't emit - // anything. - assert(RecordVal == Op.getLiteralValue() && - "Invalid abbrev for record!"); + if (Op.isLiteral() || Op.getEncoding() != BitCodeAbbrevOp::Array) { + EmitAbbreviatedField(Op, Vals[RecordIdx]); ++RecordIdx; } else { - // Encode the value as we are commanded. - switch (Op.getEncoding()) { - default: assert(0 && "Unknown encoding!"); - case BitCodeAbbrevOp::FixedWidth: - Emit64(RecordVal, Op.getEncodingData()); - ++RecordIdx; - break; - case BitCodeAbbrevOp::VBR: - EmitVBR64(RecordVal, Op.getEncodingData()); - ++RecordIdx; - break; - } + // Array case. + assert(i+2 == e && "array op not second to last?"); + const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); + + // Emit a vbr6 to indicate the number of elements present. + EmitVBR(Vals.size()-RecordIdx, 6); + + // Emit each field. + for (; RecordIdx != Vals.size(); ++RecordIdx) + EmitAbbreviatedField(EltEnc, Vals[RecordIdx]); } } assert(RecordIdx == Vals.size() && "Not all record operands emitted!"); @@ -260,27 +279,20 @@ for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { assert(RecordIdx < Vals.size() && "Invalid abbrev/record"); const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); - unsigned RecordVal = Vals[RecordIdx]; - if (Op.isLiteral()) { - // If the abbrev specifies the literal value to use, don't emit - // anything. - assert(RecordVal == Op.getLiteralValue() && - "Invalid abbrev for record!"); + if (Op.isLiteral() || Op.getEncoding() != BitCodeAbbrevOp::Array) { + EmitAbbreviatedField(Op, Vals[RecordIdx]); ++RecordIdx; } else { - // Encode the value as we are commanded. - switch (Op.getEncoding()) { - default: assert(0 && "Unknown encoding!"); - case BitCodeAbbrevOp::FixedWidth: - Emit(RecordVal, Op.getEncodingData()); - ++RecordIdx; - break; - case BitCodeAbbrevOp::VBR: - EmitVBR(RecordVal, Op.getEncodingData()); - ++RecordIdx; - break; - } + assert(i+2 == e && "array op not second to last?"); + const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); + + // Emit a vbr6 to indicate the number of elements present. + EmitVBR(Vals.size()-RecordIdx, 6); + + // Emit each field. + for (; RecordIdx != Vals.size(); ++RecordIdx) + EmitAbbreviatedField(EltEnc, Vals[RecordIdx]); } } assert(RecordIdx == Vals.size() && "Not all record operands emitted!"); _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits