[Attributor][NFC] Do not create temporary maps during lookup
authorJohannes Doerfert <johannes@jdoerfert.de>
Wed, 15 Apr 2020 07:14:56 +0000 (02:14 -0500)
committerJohannes Doerfert <johannes@jdoerfert.de>
Thu, 16 Apr 2020 07:32:31 +0000 (02:32 -0500)
The AAMap.lookup() call created a temporary value if the key was not
present. Since the value was another map it was not free to create it.
Instead of a lookup we now use find and compare the result against the
end iterator explicitly. The result is the same but we never need to
create a temporary map.

llvm/include/llvm/Transforms/IPO/Attributor.h

index a4b0c6a..2363a74 100644 (file)
@@ -1195,9 +1195,11 @@ private:
 
     // Lookup the abstract attribute of type AAType. If found, return it after
     // registering a dependence of QueryingAA on the one returned attribute.
-    const auto &KindToAbstractAttributeMap = AAMap.lookup(IRP);
+    auto KindToAbstractAttributeMapIt = AAMap.find(IRP);
+    if ( KindToAbstractAttributeMapIt == AAMap.end())
+      return nullptr;
     if (AAType *AA = static_cast<AAType *>(
-            KindToAbstractAttributeMap.lookup(&AAType::ID))) {
+            KindToAbstractAttributeMapIt->second.lookup(&AAType::ID))) {
       // Do not register a dependence on an attribute with an invalid state.
       if (TrackDependence && AA->getState().isValidState())
         recordDependence(*AA, const_cast<AbstractAttribute &>(*QueryingAA),