diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-13 21:10:44 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2015-01-13 21:10:44 +0000 |
commit | 6a4848324bc8ed9789e3d9d99e8715b1667547d3 (patch) | |
tree | 0d7be7c5469f3d78cc75b980930e1f0c72c2d674 /llvm/lib/Bitcode/Writer | |
parent | a4f2925bd10233f143ef92a4df18a5f2457df0dd (diff) | |
download | bcm5719-llvm-6a4848324bc8ed9789e3d9d99e8715b1667547d3.tar.gz bcm5719-llvm-6a4848324bc8ed9789e3d9d99e8715b1667547d3.zip |
AsmParser/Bitcode: Add support for MDLocation
This adds assembly and bitcode support for `MDLocation`. The assembly
side is rather big, since this is the first `MDNode` subclass (that
isn't `MDTuple`). Part of PR21433.
(If you're wondering where the mountains of testcase updates are, we
don't need them until I update `DILocation` and `DebugLoc` to actually
use this class.)
llvm-svn: 225830
Diffstat (limited to 'llvm/lib/Bitcode/Writer')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 39 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/ValueEnumerator.h | 2 |
3 files changed, 44 insertions, 1 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 9d14a1afb61..a96e866ed2c 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -779,6 +779,25 @@ static void WriteMDNode(const MDNode *N, Record.clear(); } +static void WriteMDLocation(const MDLocation *N, const ValueEnumerator &VE, + BitstreamWriter &Stream, + SmallVectorImpl<uint64_t> &Record, + unsigned Abbrev) { + Record.push_back(N->isDistinct()); + Record.push_back(N->getLine()); + Record.push_back(N->getColumn()); + Record.push_back(VE.getMetadataID(N->getScope())); + + // Always emit the inlined-at location, even though it's optional. + if (Metadata *InlinedAt = N->getInlinedAt()) + Record.push_back(VE.getMetadataID(InlinedAt) + 1); + else + Record.push_back(0); + + Stream.EmitRecord(bitc::METADATA_LOCATION, Record, Abbrev); + Record.clear(); +} + static void WriteModuleMetadata(const Module *M, const ValueEnumerator &VE, BitstreamWriter &Stream) { @@ -798,6 +817,22 @@ static void WriteModuleMetadata(const Module *M, MDSAbbrev = Stream.EmitAbbrev(Abbv); } + unsigned LocAbbrev = 0; + if (VE.hasMDLocation()) { + // Abbrev for METADATA_LOCATION. + // + // 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_LOCATION)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + LocAbbrev = Stream.EmitAbbrev(Abbv); + } + unsigned NameAbbrev = 0; if (!M->named_metadata_empty()) { // Abbrev for METADATA_NAME. @@ -810,6 +845,10 @@ static void WriteModuleMetadata(const Module *M, SmallVector<uint64_t, 64> Record; for (const Metadata *MD : MDs) { + if (const MDLocation *Loc = dyn_cast<MDLocation>(MD)) { + WriteMDLocation(Loc, VE, Stream, Record, LocAbbrev); + continue; + } if (const MDNode *N = dyn_cast<MDNode>(MD)) { WriteMDNode(N, VE, Stream, Record); continue; diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp index b117d7bb49a..27a63d8fefc 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -282,7 +282,8 @@ static bool isIntOrIntVectorValue(const std::pair<const Value*, unsigned> &V) { return V.first->getType()->isIntOrIntVectorTy(); } -ValueEnumerator::ValueEnumerator(const Module &M) : HasMDString(false) { +ValueEnumerator::ValueEnumerator(const Module &M) + : HasMDString(false), HasMDLocation(false) { if (shouldPreserveBitcodeUseListOrder()) UseListOrders = predictUseListOrder(M); @@ -547,6 +548,7 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) { EnumerateValue(C->getValue()); HasMDString |= isa<MDString>(MD); + HasMDLocation |= isa<MDLocation>(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 e63394fefa5..d363c1be0dd 100644 --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.h +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.h @@ -65,6 +65,7 @@ private: typedef DenseMap<const Metadata *, unsigned> MetadataMapType; MetadataMapType MDValueMap; bool HasMDString; + bool HasMDLocation; typedef DenseMap<AttributeSet, unsigned> AttributeGroupMapType; AttributeGroupMapType AttributeGroupMap; @@ -111,6 +112,7 @@ public: unsigned getMetadataID(const Metadata *V) const; bool hasMDString() const { return HasMDString; } + bool hasMDLocation() const { return HasMDLocation; } unsigned getTypeID(Type *T) const { TypeMapType::const_iterator I = TypeMap.find(T); |