From fc8110041f55483631b9e6f11ea105d41708a512 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 25 Mar 2016 15:22:27 +0000 Subject: Revert "Bitcode: Collect all MDString records into a single blob" This reverts commit r264409 since it failed to bootstrap: http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_build/8302/ llvm-svn: 264410 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 85 +++++++++---------------------- 1 file changed, 24 insertions(+), 61 deletions(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 0108667c9e2..5d051649699 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1347,78 +1347,31 @@ static void writeNamedMetadata(const Module &M, const ValueEnumerator &VE, } } -static unsigned createMDStringDataAbbrev(BitstreamWriter &Stream) { - BitCodeAbbrev *Abbv = new BitCodeAbbrev(); - Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_BULK_STRING_DATA)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); - return Stream.EmitAbbrev(Abbv); -} - -static void emitMDStringBlob(unsigned DataAbbrev, - ArrayRef Strings, - BitstreamWriter &Stream, - SmallVectorImpl &Record, - SmallString<4096> &Blob) { - for (const Metadata *MD : Strings) { - StringRef S = cast(MD)->getString(); - Record.push_back(S.size()); - Blob.append(S.begin(), S.end()); - } - - Stream.EmitRecord(bitc::METADATA_BULK_STRING_SIZES, Record); - Record.clear(); - - Record.push_back(bitc::METADATA_BULK_STRING_DATA); - Stream.EmitRecordWithBlob(DataAbbrev, Record, Blob); - Record.clear(); -} - -/// Write out a section of records for MDString. -/// -/// All the MDString elements in a metadata block are emitted in bulk. They're -/// grouped into blocks, and each block is emitted with pair of records: -/// -/// - SIZES: a list of the sizes of the strings in the block. -/// - DATA: the blob itself. -static void writeMetadataStrings(ArrayRef Strings, - BitstreamWriter &Stream, - SmallVectorImpl &Record) { - if (Strings.empty()) - return; - - // Emit strings in large blocks to reduce record overhead. Somewhat - // arbitrarily, limit this to 512 strings per blob: - // - big enough to eliminate overhead; - // - small enough that the reader's SIZES record will stay within a page. - const size_t NumStringsPerBlob = 512; - Record.reserve(std::min(NumStringsPerBlob, Strings.size())); - - unsigned DataAbbrev = createMDStringDataAbbrev(Stream); - SmallString<4096> Blob; - while (Strings.size() > NumStringsPerBlob) { - emitMDStringBlob(DataAbbrev, Strings.slice(0, NumStringsPerBlob), Stream, - Record, Blob); - Strings = Strings.slice(NumStringsPerBlob); - } - if (!Strings.empty()) - emitMDStringBlob(DataAbbrev, Strings, Stream, Record, Blob); -} - static void WriteModuleMetadata(const Module &M, const ValueEnumerator &VE, BitstreamWriter &Stream) { - if (VE.getMDs().empty() && M.named_metadata_empty()) + const auto &MDs = VE.getMDs(); + if (MDs.empty() && M.named_metadata_empty()) return; Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3); + unsigned MDSAbbrev = 0; + if (VE.hasMDString()) { + // Abbrev for METADATA_STRING. + BitCodeAbbrev *Abbv = new BitCodeAbbrev(); + Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_STRING)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); + MDSAbbrev = Stream.EmitAbbrev(Abbv); + } + // Initialize MDNode abbreviations. #define HANDLE_MDNODE_LEAF(CLASS) unsigned CLASS##Abbrev = 0; #include "llvm/IR/Metadata.def" SmallVector Record; - writeMetadataStrings(VE.getMDStrings(), Stream, Record); - for (const Metadata *MD : VE.getNonMDStrings()) { + for (const Metadata *MD : MDs) { if (const MDNode *N = dyn_cast(MD)) { assert(N->isResolved() && "Expected forward references to be resolved"); @@ -1432,7 +1385,17 @@ static void WriteModuleMetadata(const Module &M, #include "llvm/IR/Metadata.def" } } - WriteValueAsMetadata(cast(MD), VE, Stream, Record); + if (const auto *MDC = dyn_cast(MD)) { + WriteValueAsMetadata(MDC, VE, Stream, Record); + continue; + } + const MDString *MDS = cast(MD); + // Code: [strchar x N] + Record.append(MDS->bytes_begin(), MDS->bytes_end()); + + // Emit the finished record. + Stream.EmitRecord(bitc::METADATA_STRING, Record, MDSAbbrev); + Record.clear(); } writeNamedMetadata(M, VE, Stream, Record); -- cgit v1.2.3