diff options
author | Dan Gohman <gohman@apple.com> | 2010-07-20 21:42:28 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-07-20 21:42:28 +0000 |
commit | 43aa8f03c18459b574d49d6a11616845e1d2ba30 (patch) | |
tree | abcb8b4049feace6a57d4ca54019fe96f2618646 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | c3eb5e3d4bf1152b702a196b903c9c6559b02b1c (diff) | |
download | bcm5719-llvm-43aa8f03c18459b574d49d6a11616845e1d2ba30.tar.gz bcm5719-llvm-43aa8f03c18459b574d49d6a11616845e1d2ba30.zip |
Add support for remapping metadata kind IDs when reading in a
bitcode file, so that two bitcode files where the same metadata kind
name happens to have been assigned a different ID can still be
linked together.
Eliminate the restriction that metadata kind IDs can't be 0.
Change MD_dbg from 1 to 0, because we can now, and because it's
less mysterious that way.
llvm-svn: 108939
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index b3f0776d29d..f486b51caec 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -39,6 +39,7 @@ void BitcodeReader::FreeState() { std::vector<BasicBlock*>().swap(FunctionBBs); std::vector<Function*>().swap(FunctionsWithBodies); DeferredFunctionInfo.clear(); + MDKindMap.clear(); } //===----------------------------------------------------------------------===// @@ -859,13 +860,12 @@ bool BitcodeReader::ParseMetadata() { SmallString<8> Name; Name.resize(RecordLength-1); unsigned Kind = Record[0]; - (void) Kind; for (unsigned i = 1; i != RecordLength; ++i) Name[i-1] = Record[i]; unsigned NewKind = TheModule->getMDKindID(Name.str()); - assert(Kind == NewKind && - "FIXME: Unable to handle custom metadata mismatch!");(void)NewKind; + if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second) + return Error("Conflicting METADATA_KIND records"); break; } } @@ -1621,8 +1621,12 @@ bool BitcodeReader::ParseMetadataAttachment() { Instruction *Inst = InstructionList[Record[0]]; for (unsigned i = 1; i != RecordLength; i = i+2) { unsigned Kind = Record[i]; + DenseMap<unsigned, unsigned>::iterator I = + MDKindMap.find(Kind); + if (I == MDKindMap.end()) + return Error("Invalid metadata kind ID"); Value *Node = MDValueList.getValueFwdRef(Record[i+1]); - Inst->setMetadata(Kind, cast<MDNode>(Node)); + Inst->setMetadata(I->second, cast<MDNode>(Node)); } break; } |