aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2026-02-21 08:50:57 +0100
committerMatt Arsenault <arsenm2@gmail.com>2026-02-21 11:41:07 +0100
commitf875f8feab0ae23081590dad7f4d655a910597e9 (patch)
treebd881db026ef9b177e0e29facab031884dfe707b
parentfa1cda8f091f34301d956bcf6c789865e619a5ee (diff)
downloadllvm-users/arsenm/attributor/avoid-double-map-lookup-updateAttrMap.tar.gz
llvm-users/arsenm/attributor/avoid-double-map-lookup-updateAttrMap.tar.bz2
llvm-users/arsenm/attributor/avoid-double-map-lookup-updateAttrMap.zip
Attributor: Avoid double map lookup in updateAttrMapusers/arsenm/attributor/avoid-double-map-lookup-updateAttrMap
This will leave behind the map entry in the unchanged case, but this seems to not matter. Could erase the newly inserted entry if that happens, but that also doesn't seem to make a difference.
-rw-r--r--llvm/lib/Transforms/IPO/Attributor.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 9a35696b7627..daaaf4176946 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1136,13 +1136,11 @@ Attributor::updateAttrMap(const IRPosition &IRP, ArrayRef<DescTy> AttrDescs,
break;
};
- AttributeList AL;
+ AttributeList AL = IRP.getAttrList();
Value *AttrListAnchor = IRP.getAttrListAnchor();
- auto It = AttrsMap.find(AttrListAnchor);
- if (It == AttrsMap.end())
- AL = IRP.getAttrList();
- else
- AL = It->getSecond();
+ auto [Iter, Inserted] = AttrsMap.insert({AttrListAnchor, AL});
+ if (!Inserted)
+ AL = Iter->second;
LLVMContext &Ctx = IRP.getAnchorValue().getContext();
auto AttrIdx = IRP.getAttrIdx();
@@ -1160,8 +1158,9 @@ Attributor::updateAttrMap(const IRPosition &IRP, ArrayRef<DescTy> AttrDescs,
AL = AL.removeAttributesAtIndex(Ctx, AttrIdx, AM);
AL = AL.addAttributesAtIndex(Ctx, AttrIdx, AB);
- AttrsMap[AttrListAnchor] = AL;
- return ChangeStatus::CHANGED;
+
+ Iter->second = AL;
+ return HasChanged;
}
bool Attributor::hasAttr(const IRPosition &IRP,