summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-03-25 15:22:27 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-03-25 15:22:27 +0000
commitfc8110041f55483631b9e6f11ea105d41708a512 (patch)
tree40efa02077c3ed0914bd2691471af64bcc659237 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
parentfdbf0a5af805b764927bd8b38da89ddffc67f531 (diff)
downloadbcm5719-llvm-fc8110041f55483631b9e6f11ea105d41708a512.tar.gz
bcm5719-llvm-fc8110041f55483631b9e6f11ea105d41708a512.zip
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
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp85
1 files changed, 24 insertions, 61 deletions
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<const Metadata *> Strings,
- BitstreamWriter &Stream,
- SmallVectorImpl<uint64_t> &Record,
- SmallString<4096> &Blob) {
- for (const Metadata *MD : Strings) {
- StringRef S = cast<MDString>(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<const Metadata *> Strings,
- BitstreamWriter &Stream,
- SmallVectorImpl<uint64_t> &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<uint64_t, 64> Record;
- writeMetadataStrings(VE.getMDStrings(), Stream, Record);
- for (const Metadata *MD : VE.getNonMDStrings()) {
+ for (const Metadata *MD : MDs) {
if (const MDNode *N = dyn_cast<MDNode>(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<ConstantAsMetadata>(MD), VE, Stream, Record);
+ if (const auto *MDC = dyn_cast<ConstantAsMetadata>(MD)) {
+ WriteValueAsMetadata(MDC, VE, Stream, Record);
+ continue;
+ }
+ const MDString *MDS = cast<MDString>(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);
OpenPOWER on IntegriCloud