Skip to content

Commit 474238b

Browse files
[CodeGen] Avoid repeated hash lookups (NFC) (#130388)
1 parent e85e44c commit 474238b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

llvm/lib/CodeGen/RegisterBankInfo.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,13 @@ RegisterBankInfo::getPartialMapping(unsigned StartIdx, unsigned Length,
282282
++NumPartialMappingsAccessed;
283283

284284
hash_code Hash = hashPartialMapping(StartIdx, Length, &RegBank);
285-
const auto &It = MapOfPartialMappings.find(Hash);
286-
if (It != MapOfPartialMappings.end())
285+
auto [It, Inserted] = MapOfPartialMappings.try_emplace(Hash);
286+
if (!Inserted)
287287
return *It->second;
288288

289289
++NumPartialMappingsCreated;
290290

291-
auto &PartMapping = MapOfPartialMappings[Hash];
291+
auto &PartMapping = It->second;
292292
PartMapping = std::make_unique<PartialMapping>(StartIdx, Length, RegBank);
293293
return *PartMapping;
294294
}
@@ -316,13 +316,13 @@ RegisterBankInfo::getValueMapping(const PartialMapping *BreakDown,
316316
++NumValueMappingsAccessed;
317317

318318
hash_code Hash = hashValueMapping(BreakDown, NumBreakDowns);
319-
const auto &It = MapOfValueMappings.find(Hash);
320-
if (It != MapOfValueMappings.end())
319+
auto [It, Inserted] = MapOfValueMappings.try_emplace(Hash);
320+
if (!Inserted)
321321
return *It->second;
322322

323323
++NumValueMappingsCreated;
324324

325-
auto &ValMapping = MapOfValueMappings[Hash];
325+
auto &ValMapping = It->second;
326326
ValMapping = std::make_unique<ValueMapping>(BreakDown, NumBreakDowns);
327327
return *ValMapping;
328328
}
@@ -390,13 +390,13 @@ RegisterBankInfo::getInstructionMappingImpl(
390390

391391
hash_code Hash =
392392
hashInstructionMapping(ID, Cost, OperandsMapping, NumOperands);
393-
const auto &It = MapOfInstructionMappings.find(Hash);
394-
if (It != MapOfInstructionMappings.end())
393+
auto [It, Inserted] = MapOfInstructionMappings.try_emplace(Hash);
394+
if (!Inserted)
395395
return *It->second;
396396

397397
++NumInstructionMappingsCreated;
398398

399-
auto &InstrMapping = MapOfInstructionMappings[Hash];
399+
auto &InstrMapping = It->second;
400400
InstrMapping = std::make_unique<InstructionMapping>(
401401
ID, Cost, OperandsMapping, NumOperands);
402402
return *InstrMapping;

0 commit comments

Comments
 (0)