-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[MCA] Avoid repeated hash lookups (NFC) #129192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MCA] Avoid repeated hash lookups (NFC) #129192
Conversation
|
@llvm/pr-subscribers-tools-llvm-mca Author: Kazu Hirata (kazutakahirata) ChangesFull diff: https://github.com/llvm/llvm-project/pull/129192.diff 1 Files Affected:
diff --git a/llvm/lib/MCA/InstrBuilder.cpp b/llvm/lib/MCA/InstrBuilder.cpp
index 2cb1908695308..2bac99b6309af 100644
--- a/llvm/lib/MCA/InstrBuilder.cpp
+++ b/llvm/lib/MCA/InstrBuilder.cpp
@@ -634,16 +634,14 @@ InstrBuilder::createInstrDescImpl(const MCInst &MCI,
bool IsVariadic = MCDesc.isVariadic();
if ((ID->IsRecyclable = !IsVariadic && !IsVariant)) {
auto DKey = std::make_pair(MCI.getOpcode(), SchedClassID);
- Descriptors[DKey] = std::move(ID);
- return *Descriptors[DKey];
+ return *(Descriptors[DKey] = std::move(ID));
}
auto VDKey = std::make_pair(hashMCInst(MCI), SchedClassID);
assert(
!VariantDescriptors.contains(VDKey) &&
"Expected VariantDescriptors to not already have a value for this key.");
- VariantDescriptors[VDKey] = std::move(ID);
- return *VariantDescriptors[VDKey];
+ return *(VariantDescriptors[VDKey] = std::move(ID));
}
Expected<const InstrDesc &>
|
| auto DKey = std::make_pair(MCI.getOpcode(), SchedClassID); | ||
| Descriptors[DKey] = std::move(ID); | ||
| return *Descriptors[DKey]; | ||
| return *(Descriptors[DKey] = std::move(ID)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies if I am a bit late on this review.
Have you considered using insert_or_assign() ?
https://llvm.org/doxygen/DenseMap_8h_source.html#l00306
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using insert_or_assign() should solve the issue in a nicer way. That is, assuming that my understanding of how insert_or_assign() works is correct :) .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could use insert_or_assign, but that would be a bit mouthful though:
return *(Descriptors[DKey] = std::move(ID));
return *(Descriptors.insert_or_assign(DKey, std::move(ID)).first->second);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm yeah, it forces you to do that annoying first->second to get the iterator from the pair.
Nevermind then. Thanks for the fix!
No description provided.