[llvm] 474238b - [CodeGen] Avoid repeated hash lookups (NFC) (#130388)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 8 00:20:56 PST 2025
Author: Kazu Hirata
Date: 2025-03-08T00:20:53-08:00
New Revision: 474238bbfa194ef8f46ee8b3e8d91258885ceb63
URL: https://github.com/llvm/llvm-project/commit/474238bbfa194ef8f46ee8b3e8d91258885ceb63
DIFF: https://github.com/llvm/llvm-project/commit/474238bbfa194ef8f46ee8b3e8d91258885ceb63.diff
LOG: [CodeGen] Avoid repeated hash lookups (NFC) (#130388)
Added:
Modified:
llvm/lib/CodeGen/RegisterBankInfo.cpp
Removed:
################################################################################
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