diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-02-03 21:54:14 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-02-03 21:54:14 +0000 |
| commit | 4e4aa7053503a00c29fadaec82e2f399bc9da492 (patch) | |
| tree | d96c4bb1895e44a477fa4131e76d73bbbea3836d /llvm/lib/Bitcode | |
| parent | 37cd4d0f42c31cc0c933069e528e65deaeb94477 (diff) | |
| download | bcm5719-llvm-4e4aa7053503a00c29fadaec82e2f399bc9da492.tar.gz bcm5719-llvm-4e4aa7053503a00c29fadaec82e2f399bc9da492.zip | |
IR: Assembly and bitcode for GenericDebugNode
llvm-svn: 228041
Diffstat (limited to 'llvm/lib/Bitcode')
| -rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 32 | ||||
| -rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 36 | ||||
| -rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.h | 2 |
4 files changed, 67 insertions, 6 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index d2ee73f61cc..b4831d921cf 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1181,6 +1181,17 @@ std::error_code BitcodeReader::ParseMetadata() { SmallVector<uint64_t, 64> Record; + auto getMDString = [&](unsigned ID) -> MDString *{ + // This requires that the ID is not really a forward reference. In + // particular, the MDString must already have been resolved. + if (ID) + return cast<MDString>(MDValueList.getValueFwdRef(ID - 1)); + return nullptr; + }; + +#define GET_OR_DISTINCT(CLASS, DISTINCT, ARGS) \ + (DISTINCT ? CLASS::getDistinct ARGS : CLASS::get ARGS) + // Read all the records. while (1) { BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); @@ -1318,6 +1329,26 @@ std::error_code BitcodeReader::ParseMetadata() { NextMDValueNo++); break; } + case bitc::METADATA_GENERIC_DEBUG: { + if (Record.size() < 4) + return Error("Invalid record"); + + unsigned Tag = Record[1]; + unsigned Version = Record[2]; + + if (Tag >= 1u << 16 || Version != 0) + return Error("Invalid record"); + + auto *Header = getMDString(Record[3]); + SmallVector<Metadata *, 8> DwarfOps; + for (unsigned I = 4, E = Record.size(); I != E; ++I) + DwarfOps.push_back(Record[I] ? MDValueList.getValueFwdRef(Record[I] - 1) + : nullptr); + MDValueList.AssignValue(GET_OR_DISTINCT(GenericDebugNode, Record[0], + (Context, Tag, Header, DwarfOps)), + NextMDValueNo++); + break; + } case bitc::METADATA_STRING: { std::string String(Record.begin(), Record.end()); llvm::UpgradeMDStringConstant(String); @@ -1339,6 +1370,7 @@ std::error_code BitcodeReader::ParseMetadata() { } } } +#undef GET_OR_DISTINCT } /// decodeSignRotatedValue - Decode a signed value stored with the sign bit in diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 2f1c74ae01d..3aa1ef9a707 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -792,10 +792,20 @@ static void WriteMDLocation(const MDLocation *N, const ValueEnumerator &VE, Record.clear(); } -static void WriteGenericDebugNode(const GenericDebugNode *, - const ValueEnumerator &, BitstreamWriter &, - SmallVectorImpl<uint64_t> &, unsigned) { - llvm_unreachable("unimplemented"); +static void WriteGenericDebugNode(const GenericDebugNode *N, + const ValueEnumerator &VE, + BitstreamWriter &Stream, + SmallVectorImpl<uint64_t> &Record, + unsigned Abbrev) { + Record.push_back(N->isDistinct()); + Record.push_back(N->getTag()); + Record.push_back(0); // Per-tag version field; unused for now. + + for (auto &I : N->operands()) + Record.push_back(VE.getMetadataOrNullID(I)); + + Stream.EmitRecord(bitc::METADATA_GENERIC_DEBUG, Record, Abbrev); + Record.clear(); } static void WriteModuleMetadata(const Module *M, @@ -833,6 +843,23 @@ static void WriteModuleMetadata(const Module *M, MDLocationAbbrev = Stream.EmitAbbrev(Abbv); } + unsigned GenericDebugNodeAbbrev = 0; + if (VE.hasGenericDebugNode()) { + // Abbrev for METADATA_GENERIC_DEBUG. + // + // Assume the column is usually under 128, and always output the inlined-at + // location (it's never more expensive than building an array size 1). + BitCodeAbbrev *Abbv = new BitCodeAbbrev(); + Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_GENERIC_DEBUG)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + GenericDebugNodeAbbrev = Stream.EmitAbbrev(Abbv); + } + unsigned NameAbbrev = 0; if (!M->named_metadata_empty()) { // Abbrev for METADATA_NAME. @@ -844,7 +871,6 @@ static void WriteModuleMetadata(const Module *M, } unsigned MDTupleAbbrev = 0; - unsigned GenericDebugNodeAbbrev = 0; SmallVector<uint64_t, 64> Record; for (const Metadata *MD : MDs) { if (const MDNode *N = dyn_cast<MDNode>(MD)) { diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index 2a7916b6da0..24b077bbcef 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -284,7 +284,7 @@ static bool isIntOrIntVectorValue(const std::pair<const Value*, unsigned> &V) { } ValueEnumerator::ValueEnumerator(const Module &M) - : HasMDString(false), HasMDLocation(false) { + : HasMDString(false), HasMDLocation(false), HasGenericDebugNode(false) { if (shouldPreserveBitcodeUseListOrder()) UseListOrders = predictUseListOrder(M); @@ -544,6 +544,7 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) { HasMDString |= isa<MDString>(MD); HasMDLocation |= isa<MDLocation>(MD); + HasGenericDebugNode |= isa<GenericDebugNode>(MD); // Replace the dummy ID inserted above with the correct one. MDValueMap may // have changed by inserting operands, so we need a fresh lookup here. diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.h b/llvm/lib/Bitcode/Writer/ValueEnumerator.h index 043c4925b39..ab61584baad 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.h +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.h @@ -66,6 +66,7 @@ private: MetadataMapType MDValueMap; bool HasMDString; bool HasMDLocation; + bool HasGenericDebugNode; typedef DenseMap<AttributeSet, unsigned> AttributeGroupMapType; AttributeGroupMapType AttributeGroupMap; @@ -120,6 +121,7 @@ public: bool hasMDString() const { return HasMDString; } bool hasMDLocation() const { return HasMDLocation; } + bool hasGenericDebugNode() const { return HasGenericDebugNode; } unsigned getTypeID(Type *T) const { TypeMapType::const_iterator I = TypeMap.find(T); |

