From 27bcd4da305ed928ac58b4f2349986242846634a Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 24 Mar 2016 16:30:18 +0000 Subject: [PATCH] BitcodeWriter: Move abbreviation for GenericDINode; almost NFC Simplify ValueEnumerator and WriteModuleMetadata by shifting the logic for the METADATA_GENERIC_DEBUG abbreviation into WriteGenericDINode. (This is just like r264302, but for GenericDINode.) The only change is that the abbreviation is emitted later in the bitcode, just before the first `GenericDINode` record. This shouldn't be observable though. llvm-svn: 264303 --- lib/Bitcode/Writer/BitcodeWriter.cpp | 35 +++++++++++++------------- lib/Bitcode/Writer/ValueEnumerator.cpp | 3 +-- lib/Bitcode/Writer/ValueEnumerator.h | 2 -- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index e92b5a98d28..9977be517e7 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -936,11 +936,28 @@ static void WriteDILocation(const DILocation *N, const ValueEnumerator &VE, Record.clear(); } +static unsigned createGenericDINodeAbbrev(BitstreamWriter &Stream) { + // 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)); + return Stream.EmitAbbrev(Abbv); +} + static void WriteGenericDINode(const GenericDINode *N, const ValueEnumerator &VE, BitstreamWriter &Stream, SmallVectorImpl &Record, - unsigned Abbrev) { + unsigned &Abbrev) { + if (!Abbrev) + Abbrev = createGenericDINodeAbbrev(Stream); + Record.push_back(N->isDistinct()); Record.push_back(N->getTag()); Record.push_back(0); // Per-tag version field; unused for now. @@ -1370,22 +1387,6 @@ static void WriteModuleMetadata(const Module &M, #define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0; #include "llvm/IR/Metadata.def" - if (VE.hasGenericDINode()) { - // 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)); - GenericDINodeAbbrev = Stream.EmitAbbrev(Abbv); - } - SmallVector Record; for (const Metadata *MD : MDs) { if (const MDNode *N = dyn_cast(MD)) { diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 3490896a798..b6e8e57577c 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -280,7 +280,7 @@ static bool isIntOrIntVectorValue(const std::pair &V) { ValueEnumerator::ValueEnumerator(const Module &M, bool ShouldPreserveUseListOrder) - : HasMDString(false), HasGenericDINode(false), + : HasMDString(false), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) { if (ShouldPreserveUseListOrder) UseListOrders = predictUseListOrder(M); @@ -532,7 +532,6 @@ void ValueEnumerator::EnumerateMetadata(const Metadata *MD) { EnumerateValue(C->getValue()); HasMDString |= isa(MD); - HasGenericDINode |= isa(MD); // Replace the dummy ID inserted above with the correct one. MetadataMap may // have changed by inserting operands, so we need a fresh lookup here. diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h index 1b870454ad7..7665210d014 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.h +++ b/lib/Bitcode/Writer/ValueEnumerator.h @@ -67,7 +67,6 @@ private: typedef DenseMap MetadataMapType; MetadataMapType MetadataMap; bool HasMDString; - bool HasGenericDINode; bool ShouldPreserveUseListOrder; typedef DenseMap AttributeGroupMapType; @@ -123,7 +122,6 @@ public: unsigned numMDs() const { return MDs.size(); } bool hasMDString() const { return HasMDString; } - bool hasGenericDINode() const { return HasGenericDINode; } bool shouldPreserveUseListOrder() const { return ShouldPreserveUseListOrder; }