aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode/Writer
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2009-07-29 22:34:41 +0000
committerDevang Patel <dpatel@apple.com>2009-07-29 22:34:41 +0000
commitaa993142518648c1ffa61e7f52ff6d3a95d413fb (patch)
tree66b8db375a3310bedc27056dba65816ed7d9ac26 /lib/Bitcode/Writer
parentdebcb01b0f0a15f568ca69e8f288fade4bfc7297 (diff)
downloadexternal_llvm-aa993142518648c1ffa61e7f52ff6d3a95d413fb.zip
external_llvm-aa993142518648c1ffa61e7f52ff6d3a95d413fb.tar.gz
external_llvm-aa993142518648c1ffa61e7f52ff6d3a95d413fb.tar.bz2
Read and write NamedMDNode.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77517 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Writer')
-rw-r--r--lib/Bitcode/Writer/BitcodeWriter.cpp30
-rw-r--r--lib/Bitcode/Writer/ValueEnumerator.cpp12
2 files changed, 41 insertions, 1 deletions
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp
index a41b810..ff47cf4 100644
--- a/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -495,6 +495,7 @@ static void WriteModuleMetadata(const ValueEnumerator &VE,
const ValueEnumerator::ValueList &Vals = VE.getValues();
bool StartedMetadataBlock = false;
unsigned MDSAbbrev = 0;
+ unsigned String8Abbrev = 0;
SmallVector<uint64_t, 64> Record;
for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
@@ -525,6 +526,33 @@ static void WriteModuleMetadata(const ValueEnumerator &VE,
// Emit the finished record.
Stream.EmitRecord(bitc::METADATA_STRING, Record, MDSAbbrev);
Record.clear();
+ } else if (const NamedMDNode *NMD = dyn_cast<NamedMDNode>(Vals[i].first)) {
+ if (!StartedMetadataBlock) {
+ Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
+ StartedMetadataBlock = true;
+ BitCodeAbbrev *Abbv = new BitCodeAbbrev();
+ Abbv->Add(BitCodeAbbrevOp(bitc::CST_CODE_STRING));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
+ Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8));
+ String8Abbrev = Stream.EmitAbbrev(Abbv);
+ }
+
+ // Write name.
+ const char *StrBegin = NMD->getName().data();
+ for (unsigned i = 0, e = NMD->getName().size(); i != e; ++i)
+ Record.push_back(StrBegin[i]);
+ Stream.EmitRecord(bitc::METADATA_NAME, Record, String8Abbrev);
+ Record.clear();
+
+ // Write named metadata elements.
+ for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
+ if (NMD->getElement(i))
+ Record.push_back(VE.getValueID(NMD->getElement(i)));
+ else
+ Record.push_back(0);
+ }
+ Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0);
+ Record.clear();
}
}
@@ -578,7 +606,7 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal,
const Type *LastTy = 0;
for (unsigned i = FirstVal; i != LastVal; ++i) {
const Value *V = Vals[i].first;
- if (isa<MDString>(V) || isa<MDNode>(V))
+ if (isa<MetadataBase>(V))
continue;
// If we need to switch types, do so now.
if (V->getType() != LastTy) {
diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp
index 302791a..a980e90 100644
--- a/lib/Bitcode/Writer/ValueEnumerator.cpp
+++ b/lib/Bitcode/Writer/ValueEnumerator.cpp
@@ -221,6 +221,18 @@ void ValueEnumerator::EnumerateValue(const Value *V) {
return;
}
+ if (const NamedMDNode *N = dyn_cast<NamedMDNode>(V)) {
+ Values.push_back(std::make_pair(V, 1U));
+ ValueMap[V] = Values.size();
+ ValueID = Values.size();
+ for(NamedMDNode::const_elem_iterator I = N->elem_begin(),
+ E = N->elem_end(); I != E; ++I) {
+ MetadataBase *M = *I;
+ EnumerateValue(M);
+ }
+ return;
+ }
+
// Add the value.
Values.push_back(std::make_pair(V, 1U));
ValueID = Values.size();