summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-03-24 16:16:08 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-03-24 16:16:08 +0000
commitf8ecdf528459b309ea55c593ed2748443d14878e (patch)
tree60f5c2425020115c4abe753b83ddce27bf246f4d
parentb7807a0c8e2a79dda70545e62a09bea24327bbb1 (diff)
downloadbcm5719-llvm-f8ecdf528459b309ea55c593ed2748443d14878e.tar.gz
bcm5719-llvm-f8ecdf528459b309ea55c593ed2748443d14878e.zip
BitcodeWriter: Split out named metadata; almost NFC
Split writeNamedMetadata out of WriteModuleMetadata to write named metadata, and createNamedMetadataAbbrev for the abbreviation. There should be no effective functionality change, although the layout of the bitcode will change. Previously, the abbreviation was emitted at the top of the block, but now it is delayed until immediately before the named metadata records are emitted. llvm-svn: 264301
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp56
1 files changed, 31 insertions, 25 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 83dd5475c24..fa638675593 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -1301,6 +1301,36 @@ static void WriteDIImportedEntity(const DIImportedEntity *N,
Record.clear();
}
+static unsigned createNamedMetadataAbbrev(BitstreamWriter &Stream) {
+ BitCodeAbbrev *Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_NAME));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
+ return Stream.EmitAbbrev(Abbv);
+}
+
+static void writeNamedMetadata(const Module &M, const ValueEnumerator &VE,
+ BitstreamWriter &Stream,
+ SmallVectorImpl<uint64_t> &Record) {
+ if (M.named_metadata_empty())
+ return;
+
+ unsigned Abbrev = createNamedMetadataAbbrev(Stream);
+ for (const NamedMDNode &NMD : M.named_metadata()) {
+ // Write name.
+ StringRef Str = NMD.getName();
+ Record.append(Str.bytes_begin(), Str.bytes_end());
+ Stream.EmitRecord(bitc::METADATA_NAME, Record, Abbrev);
+ Record.clear();
+
+ // Write named metadata operands.
+ for (const MDNode *N : NMD.operands())
+ Record.push_back(VE.getMetadataID(N));
+ Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
+ Record.clear();
+ }
+}
+
static void WriteModuleMetadata(const Module &M,
const ValueEnumerator &VE,
BitstreamWriter &Stream) {
@@ -1355,16 +1385,6 @@ static void WriteModuleMetadata(const Module &M,
GenericDINodeAbbrev = Stream.EmitAbbrev(Abbv);
}
- unsigned NameAbbrev = 0;
- if (!M.named_metadata_empty()) {
- // Abbrev for METADATA_NAME.
- BitCodeAbbrev *Abbv = new BitCodeAbbrev();
- Abbv->Add(BitCodeAbbrevOp(bitc::METADATA_NAME));
- Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
- Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
- NameAbbrev = Stream.EmitAbbrev(Abbv);
- }
-
SmallVector<uint64_t, 64> Record;
for (const Metadata *MD : MDs) {
if (const MDNode *N = dyn_cast<MDNode>(MD)) {
@@ -1393,21 +1413,7 @@ static void WriteModuleMetadata(const Module &M,
Record.clear();
}
- // Write named metadata.
- for (const NamedMDNode &NMD : M.named_metadata()) {
- // Write name.
- StringRef Str = NMD.getName();
- Record.append(Str.bytes_begin(), Str.bytes_end());
- Stream.EmitRecord(bitc::METADATA_NAME, Record, NameAbbrev);
- Record.clear();
-
- // Write named metadata operands.
- for (const MDNode *N : NMD.operands())
- Record.push_back(VE.getMetadataID(N));
- Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
- Record.clear();
- }
-
+ writeNamedMetadata(M, VE, Stream, Record);
Stream.ExitBlock();
}
OpenPOWER on IntegriCloud