1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[ThinLTO] Avoid unnecesary hash lookups during metadata linking (NFC)

Replace sequences of count() followed by operator[] with either
find() or insert(), depending on the context.

llvm-svn: 258405
This commit is contained in:
Teresa Johnson 2016-01-21 16:46:40 +00:00
parent 14b16e7ee1
commit 29f701563c
2 changed files with 20 additions and 19 deletions

View File

@ -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;
}
}
}

View File

@ -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);
}
}