diff options
author | Dan Gohman <gohman@apple.com> | 2010-07-21 23:38:33 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-07-21 23:38:33 +0000 |
commit | 17aa92c92a925b4a674440c7ef088c223990e854 (patch) | |
tree | bc129644ee9db39dc25a41c22ce01b14ede5728f /lib/Bitcode | |
parent | fcbd1a749f9db4bf144a3343c4d707e1de087a7e (diff) | |
download | external_llvm-17aa92c92a925b4a674440c7ef088c223990e854.zip external_llvm-17aa92c92a925b4a674440c7ef088c223990e854.tar.gz external_llvm-17aa92c92a925b4a674440c7ef088c223990e854.tar.bz2 |
Make NamedMDNode not be a subclass of Value, and simplify the interface
for creating and populating NamedMDNodes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109061 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r-- | lib/Bitcode/Reader/BitcodeReader.cpp | 7 | ||||
-rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 44 | ||||
-rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.cpp | 29 | ||||
-rw-r--r-- | lib/Bitcode/Writer/ValueEnumerator.h | 2 |
4 files changed, 35 insertions, 47 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 7d82321..8f999a6 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -801,16 +801,13 @@ bool BitcodeReader::ParseMetadata() { // Read named metadata elements. unsigned Size = Record.size(); - SmallVector<MDNode *, 8> Elts; + NamedMDNode *NMD = TheModule->getOrInsertNamedMetadata(Name); for (unsigned i = 0; i != Size; ++i) { MDNode *MD = dyn_cast<MDNode>(MDValueList.getValueFwdRef(Record[i])); if (MD == 0) return Error("Malformed metadata record"); - Elts.push_back(MD); + NMD->addOperand(MD); } - Value *V = NamedMDNode::Create(Context, Name.str(), Elts.data(), - Elts.size(), TheModule); - MDValueList.AssignValue(V, NextMDValueNo++); break; } case bitc::METADATA_FN_NODE: diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index f594e0f..93ca8cd 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -509,7 +509,8 @@ static void WriteMDNode(const MDNode *N, Record.clear(); } -static void WriteModuleMetadata(const ValueEnumerator &VE, +static void WriteModuleMetadata(const Module *M, + const ValueEnumerator &VE, BitstreamWriter &Stream) { const ValueEnumerator::ValueList &Vals = VE.getMDValues(); bool StartedMetadataBlock = false; @@ -544,25 +545,30 @@ 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; - } - - // Write name. - StringRef Str = NMD->getName(); - for (unsigned i = 0, e = Str.size(); i != e; ++i) - Record.push_back(Str[i]); - Stream.EmitRecord(bitc::METADATA_NAME, Record, 0/*TODO*/); - Record.clear(); + } + } - // Write named metadata operands. - for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) - Record.push_back(VE.getValueID(NMD->getOperand(i))); - Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0); - Record.clear(); + // Write named metadata. + for (Module::const_named_metadata_iterator I = M->named_metadata_begin(), + E = M->named_metadata_end(); I != E; ++I) { + const NamedMDNode *NMD = I; + if (!StartedMetadataBlock) { + Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3); + StartedMetadataBlock = true; } + + // Write name. + StringRef Str = NMD->getName(); + for (unsigned i = 0, e = Str.size(); i != e; ++i) + Record.push_back(Str[i]); + Stream.EmitRecord(bitc::METADATA_NAME, Record, 0/*TODO*/); + Record.clear(); + + // Write named metadata operands. + for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) + Record.push_back(VE.getValueID(NMD->getOperand(i))); + Stream.EmitRecord(bitc::METADATA_NAMED_NODE, Record, 0); + Record.clear(); } if (StartedMetadataBlock) @@ -1530,7 +1536,7 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) { WriteModuleConstants(VE, Stream); // Emit metadata. - WriteModuleMetadata(VE, Stream); + WriteModuleMetadata(M, VE, Stream); // Emit function bodies. for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) diff --git a/lib/Bitcode/Writer/ValueEnumerator.cpp b/lib/Bitcode/Writer/ValueEnumerator.cpp index 7be6dda..930c521 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -75,7 +75,7 @@ ValueEnumerator::ValueEnumerator(const Module *M) { // Insert constants and metadata that are named at module level into the slot // pool so that the module symbol table can refer to them... EnumerateValueSymbolTable(M->getValueSymbolTable()); - EnumerateMDSymbolTable(M->getMDSymbolTable()); + EnumerateNamedMetadata(M); SmallVector<std::pair<unsigned, MDNode*>, 8> MDs; @@ -207,31 +207,18 @@ void ValueEnumerator::EnumerateValueSymbolTable(const ValueSymbolTable &VST) { EnumerateValue(VI->getValue()); } -/// EnumerateMDSymbolTable - Insert all of the values in the specified metadata -/// table. -void ValueEnumerator::EnumerateMDSymbolTable(const MDSymbolTable &MST) { - for (MDSymbolTable::const_iterator MI = MST.begin(), ME = MST.end(); - MI != ME; ++MI) - EnumerateValue(MI->getValue()); +/// EnumerateNamedMetadata - Insert all of the values referenced by +/// named metadata in the specified module. +void ValueEnumerator::EnumerateNamedMetadata(const Module *M) { + for (Module::const_named_metadata_iterator I = M->named_metadata_begin(), + E = M->named_metadata_end(); I != E; ++I) + EnumerateNamedMDNode(I); } void ValueEnumerator::EnumerateNamedMDNode(const NamedMDNode *MD) { - // Check to see if it's already in! - unsigned &MDValueID = MDValueMap[MD]; - if (MDValueID) { - // Increment use count. - MDValues[MDValueID-1].second++; - return; - } - - // Enumerate the type of this value. - EnumerateType(MD->getType()); - for (unsigned i = 0, e = MD->getNumOperands(); i != e; ++i) if (MDNode *E = MD->getOperand(i)) EnumerateValue(E); - MDValues.push_back(std::make_pair(MD, 1U)); - MDValueMap[MD] = Values.size(); } void ValueEnumerator::EnumerateMetadata(const Value *MD) { @@ -272,8 +259,6 @@ void ValueEnumerator::EnumerateValue(const Value *V) { assert(!V->getType()->isVoidTy() && "Can't insert void values!"); if (isa<MDNode>(V) || isa<MDString>(V)) return EnumerateMetadata(V); - else if (const NamedMDNode *NMD = dyn_cast<NamedMDNode>(V)) - return EnumerateNamedMDNode(NMD); // Check to see if it's already in! unsigned &ValueID = ValueMap[V]; diff --git a/lib/Bitcode/Writer/ValueEnumerator.h b/lib/Bitcode/Writer/ValueEnumerator.h index 2b9b15f..2453b72 100644 --- a/lib/Bitcode/Writer/ValueEnumerator.h +++ b/lib/Bitcode/Writer/ValueEnumerator.h @@ -141,7 +141,7 @@ private: void EnumerateTypeSymbolTable(const TypeSymbolTable &ST); void EnumerateValueSymbolTable(const ValueSymbolTable &ST); - void EnumerateMDSymbolTable(const MDSymbolTable &ST); + void EnumerateNamedMetadata(const Module *M); }; } // End llvm namespace |