diff options
author | Teresa Johnson <tejohnson@google.com> | 2016-01-21 16:46:40 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2016-01-21 16:46:40 +0000 |
commit | 6f508afce10b4347010b90e91fae94f9fe8bd9f3 (patch) | |
tree | 6e3c695d6c22b651142f2838c393a81fbaab7788 /llvm/lib/Linker | |
parent | cb17d72170cb1bba19ec29ae62cf453aa2015389 (diff) | |
download | bcm5719-llvm-6f508afce10b4347010b90e91fae94f9fe8bd9f3.tar.gz bcm5719-llvm-6f508afce10b4347010b90e91fae94f9fe8bd9f3.zip |
[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
Diffstat (limited to 'llvm/lib/Linker')
-rw-r--r-- | llvm/lib/Linker/IRMover.cpp | 32 |
1 files changed, 16 insertions, 16 deletions
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); } } |