Skip to content

Commit 9455df9

Browse files
[Transforms] Avoid repeated hash lookups (NFC) (#131556)
1 parent e71686e commit 9455df9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
511511
continue;
512512
DebugVariable Key(DVR.getVariable(), std::nullopt,
513513
DVR.getDebugLoc()->getInlinedAt());
514-
auto VMI = VariableMap.find(Key);
514+
auto [VMI, Inserted] = VariableMap.try_emplace(Key);
515515
// A dbg.assign with no linked instructions can be treated like a
516516
// dbg.value (i.e. can be deleted).
517517
bool IsDbgValueKind =
@@ -520,12 +520,12 @@ DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
520520
// Update the map if we found a new value/expression describing the
521521
// variable, or if the variable wasn't mapped already.
522522
SmallVector<Value *, 4> Values(DVR.location_ops());
523-
if (VMI == VariableMap.end() || VMI->second.first != Values ||
523+
if (Inserted || VMI->second.first != Values ||
524524
VMI->second.second != DVR.getExpression()) {
525525
if (IsDbgValueKind)
526-
VariableMap[Key] = {Values, DVR.getExpression()};
526+
VMI->second = {Values, DVR.getExpression()};
527527
else
528-
VariableMap[Key] = {Values, nullptr};
528+
VMI->second = {Values, nullptr};
529529
continue;
530530
}
531531
// Don't delete dbg.assign intrinsics that are linked to instructions.
@@ -591,7 +591,7 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
591591
if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(&I)) {
592592
DebugVariable Key(DVI->getVariable(), std::nullopt,
593593
DVI->getDebugLoc()->getInlinedAt());
594-
auto VMI = VariableMap.find(Key);
594+
auto [VMI, Inserted] = VariableMap.try_emplace(Key);
595595
auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI);
596596
// A dbg.assign with no linked instructions can be treated like a
597597
// dbg.value (i.e. can be deleted).
@@ -600,15 +600,15 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
600600
// Update the map if we found a new value/expression describing the
601601
// variable, or if the variable wasn't mapped already.
602602
SmallVector<Value *, 4> Values(DVI->getValues());
603-
if (VMI == VariableMap.end() || VMI->second.first != Values ||
603+
if (Inserted || VMI->second.first != Values ||
604604
VMI->second.second != DVI->getExpression()) {
605605
// Use a sentinel value (nullptr) for the DIExpression when we see a
606606
// linked dbg.assign so that the next debug intrinsic will never match
607607
// it (i.e. always treat linked dbg.assigns as if they're unique).
608608
if (IsDbgValueKind)
609-
VariableMap[Key] = {Values, DVI->getExpression()};
609+
VMI->second = {Values, DVI->getExpression()};
610610
else
611-
VariableMap[Key] = {Values, nullptr};
611+
VMI->second = {Values, nullptr};
612612
continue;
613613
}
614614

0 commit comments

Comments
 (0)