llvm.org GIT mirror llvm / 19538d1
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108939 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 9 years ago
5 changed file(s) with 19 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
3939 // Pinned metadata names, which always have the same value. This is a
4040 // compile-time performance optimization, not a correctness optimization.
4141 enum {
42 MD_dbg = 1 // "dbg" -> 1.
42 MD_dbg = 0 // "dbg"
4343 };
4444
4545 /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
3838 std::vector().swap(FunctionBBs);
3939 std::vector().swap(FunctionsWithBodies);
4040 DeferredFunctionInfo.clear();
41 MDKindMap.clear();
4142 }
4243
4344 //===----------------------------------------------------------------------===//
858859 SmallString<8> Name;
859860 Name.resize(RecordLength-1);
860861 unsigned Kind = Record[0];
861 (void) Kind;
862862 for (unsigned i = 1; i != RecordLength; ++i)
863863 Name[i-1] = Record[i];
864864
865865 unsigned NewKind = TheModule->getMDKindID(Name.str());
866 assert(Kind == NewKind &&
867 "FIXME: Unable to handle custom metadata mismatch!");(void)NewKind;
866 if (!MDKindMap.insert(std::make_pair(Kind, NewKind)).second)
867 return Error("Conflicting METADATA_KIND records");
868868 break;
869869 }
870870 }
16201620 Instruction *Inst = InstructionList[Record[0]];
16211621 for (unsigned i = 1; i != RecordLength; i = i+2) {
16221622 unsigned Kind = Record[i];
1623 DenseMap::iterator I =
1624 MDKindMap.find(Kind);
1625 if (I == MDKindMap.end())
1626 return Error("Invalid metadata kind ID");
16231627 Value *Node = MDValueList.getValueFwdRef(Record[i+1]);
1624 Inst->setMetadata(Kind, cast(Node));
1628 Inst->setMetadata(I->second, cast(Node));
16251629 }
16261630 break;
16271631 }
155155 // stored here with their replacement function.
156156 typedef std::vector > UpgradedIntrinsicMap;
157157 UpgradedIntrinsicMap UpgradedIntrinsics;
158
159 // Map the bitcode's custom MDKind ID to the Module's MDKind ID.
160 DenseMap MDKindMap;
158161
159162 // After the module header has been read, the FunctionsWithBodies list is
160163 // reversed. This keeps track of whether we've done this yet.
633633 SmallVector Names;
634634 M->getMDKindNames(Names);
635635
636 assert(Names[0] == "" && "MDKind #0 is invalid");
637 if (Names.size() == 1) return;
636 if (Names.empty()) return;
638637
639638 Stream.EnterSubblock(bitc::METADATA_BLOCK_ID, 3);
640639
641 for (unsigned MDKindID = 1, e = Names.size(); MDKindID != e; ++MDKindID) {
640 for (unsigned MDKindID = 0, e = Names.size(); MDKindID != e; ++MDKindID) {
642641 Record.push_back(MDKindID);
643642 StringRef KName = Names[MDKindID];
644643 Record.append(KName.begin(), KName.end());
109109 /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
110110 unsigned LLVMContext::getMDKindID(StringRef Name) const {
111111 assert(isValidName(Name) && "Invalid MDNode name");
112
113 unsigned &Entry = pImpl->CustomMDKindNames[Name];
114
112
115113 // If this is new, assign it its ID.
116 if (Entry == 0) Entry = pImpl->CustomMDKindNames.size();
117 return Entry;
114 return
115 pImpl->CustomMDKindNames.GetOrCreateValue(
116 Name, pImpl->CustomMDKindNames.size()).second;
118117 }
119118
120119 /// getHandlerNames - Populate client supplied smallvector using custome
121120 /// metadata name and ID.
122121 void LLVMContext::getMDKindNames(SmallVectorImpl &Names) const {
123 Names.resize(pImpl->CustomMDKindNames.size()+1);
124 Names[0] = "";
122 Names.resize(pImpl->CustomMDKindNames.size());
125123 for (StringMap::const_iterator I = pImpl->CustomMDKindNames.begin(),
126124 E = pImpl->CustomMDKindNames.end(); I != E; ++I)
127 // MD Handlers are numbered from 1.
128125 Names[I->second] = I->first();
129126 }