[llvm] [CodeGen] Avoid repeated hash lookups (NFC) (PR #130388)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 7 19:53:25 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/130388
None
>From dbed1d77d2ec2d355780745a2cc46d74ba2254bb Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 7 Mar 2025 01:03:10 -0800
Subject: [PATCH] [CodeGen] Avoid repeated hash lookups (NFC)
---
llvm/lib/CodeGen/RegisterBankInfo.cpp | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/CodeGen/RegisterBankInfo.cpp b/llvm/lib/CodeGen/RegisterBankInfo.cpp
index a0061ece8add6..eaef13969a7a1 100644
--- a/llvm/lib/CodeGen/RegisterBankInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterBankInfo.cpp
@@ -282,13 +282,13 @@ RegisterBankInfo::getPartialMapping(unsigned StartIdx, unsigned Length,
++NumPartialMappingsAccessed;
hash_code Hash = hashPartialMapping(StartIdx, Length, &RegBank);
- const auto &It = MapOfPartialMappings.find(Hash);
- if (It != MapOfPartialMappings.end())
+ auto [It, Inserted] = MapOfPartialMappings.try_emplace(Hash);
+ if (!Inserted)
return *It->second;
++NumPartialMappingsCreated;
- auto &PartMapping = MapOfPartialMappings[Hash];
+ auto &PartMapping = It->second;
PartMapping = std::make_unique<PartialMapping>(StartIdx, Length, RegBank);
return *PartMapping;
}
@@ -316,13 +316,13 @@ RegisterBankInfo::getValueMapping(const PartialMapping *BreakDown,
++NumValueMappingsAccessed;
hash_code Hash = hashValueMapping(BreakDown, NumBreakDowns);
- const auto &It = MapOfValueMappings.find(Hash);
- if (It != MapOfValueMappings.end())
+ auto [It, Inserted] = MapOfValueMappings.try_emplace(Hash);
+ if (!Inserted)
return *It->second;
++NumValueMappingsCreated;
- auto &ValMapping = MapOfValueMappings[Hash];
+ auto &ValMapping = It->second;
ValMapping = std::make_unique<ValueMapping>(BreakDown, NumBreakDowns);
return *ValMapping;
}
@@ -390,13 +390,13 @@ RegisterBankInfo::getInstructionMappingImpl(
hash_code Hash =
hashInstructionMapping(ID, Cost, OperandsMapping, NumOperands);
- const auto &It = MapOfInstructionMappings.find(Hash);
- if (It != MapOfInstructionMappings.end())
+ auto [It, Inserted] = MapOfInstructionMappings.try_emplace(Hash);
+ if (!Inserted)
return *It->second;
++NumInstructionMappingsCreated;
- auto &InstrMapping = MapOfInstructionMappings[Hash];
+ auto &InstrMapping = It->second;
InstrMapping = std::make_unique<InstructionMapping>(
ID, Cost, OperandsMapping, NumOperands);
return *InstrMapping;
More information about the llvm-commits
mailing list