summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp7
-rw-r--r--llvm/lib/Linker/IRMover.cpp32
2 files changed, 20 insertions, 19 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 5a9711e58a4..59e736c18b3 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3081,9 +3081,11 @@ void BitcodeReader::saveMetadataList(
if (!OnlyTempMD || (N && N->isTemporary())) {
// Will call this after materializing each function, in order to
// handle remapping of the function's instructions/metadata.
+ auto IterBool = MetadataToIDs.insert(std::make_pair(MD, ID));
// See if we already have an entry in that case.
- if (OnlyTempMD && MetadataToIDs.count(MD)) {
- assert(MetadataToIDs[MD] == ID && "Inconsistent metadata value id");
+ if (OnlyTempMD && !IterBool.second) {
+ assert(IterBool.first->second == ID &&
+ "Inconsistent metadata value id");
continue;
}
if (N && N->isTemporary())
@@ -3091,7 +3093,6 @@ void BitcodeReader::saveMetadataList(
// metadata while it is the key of a map. The flag will be set back
// to true when the saved metadata list is destroyed.
N->setCanReplace(false);
- MetadataToIDs[MD] = ID;
}
}
}
diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp
index d136af56341..daf3d7c0ca5 100644
--- a/llvm/lib/Linker/IRMover.cpp
+++ b/llvm/lib/Linker/IRMover.cpp
@@ -659,17 +659,15 @@ Metadata *IRLinker::mapTemporaryMetadata(Metadata *MD) {
return nullptr;
// If this temporary metadata has a value id recorded during function
// parsing, record that in the ValIDToTempMDMap if one was provided.
- if (MetadataToIDs.count(MD)) {
- unsigned Idx = MetadataToIDs[MD];
- // Check if we created a temp MD when importing a different function from
- // this module. If so, reuse it the same temporary metadata, otherwise
- // add this temporary metadata to the map.
- if (!ValIDToTempMDMap->count(Idx)) {
- MDNode *Node = cast<MDNode>(MD);
- assert(Node->isTemporary());
- (*ValIDToTempMDMap)[Idx] = Node;
- }
- return (*ValIDToTempMDMap)[Idx];
+ auto I = MetadataToIDs.find(MD);
+ if (I != MetadataToIDs.end()) {
+ unsigned Idx = I->second;
+ MDNode *Node = cast<MDNode>(MD);
+ assert(Node->isTemporary());
+ // If we created a temp MD when importing a different function from
+ // this module, reuse the same temporary metadata.
+ auto IterBool = ValIDToTempMDMap->insert(std::make_pair(Idx, Node));
+ return IterBool.first->second;
}
return nullptr;
}
@@ -686,16 +684,18 @@ void IRLinker::replaceTemporaryMetadata(const Metadata *OrigMD,
// created during function importing was provided, and the source
// metadata has a value id recorded during metadata parsing, replace
// the temporary metadata with the final mapped metadata now.
- if (MetadataToIDs.count(OrigMD)) {
- unsigned Idx = MetadataToIDs[OrigMD];
+ auto I = MetadataToIDs.find(OrigMD);
+ if (I != MetadataToIDs.end()) {
+ unsigned Idx = I->second;
+ auto VI = ValIDToTempMDMap->find(Idx);
// Nothing to do if we didn't need to create a temporary metadata during
// function importing.
- if (!ValIDToTempMDMap->count(Idx))
+ if (VI == ValIDToTempMDMap->end())
return;
- MDNode *TempMD = (*ValIDToTempMDMap)[Idx];
+ MDNode *TempMD = VI->second;
TempMD->replaceAllUsesWith(NewMD);
MDNode::deleteTemporary(TempMD);
- ValIDToTempMDMap->erase(Idx);
+ ValIDToTempMDMap->erase(VI);
}
}
OpenPOWER on IntegriCloud