aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2025-03-17 07:43:12 -0700
committerGitHub <noreply@github.com>2025-03-17 07:43:12 -0700
commit9455df969ef34681d08b2118a2ca2e8b0bd0155b (patch)
treefc0461f91bd49045d1f3efb56a4fd7544a54ae95 /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
parente71686ed1539abe8ec68a4efa010f5ede13e9888 (diff)
downloadllvm-9455df969ef34681d08b2118a2ca2e8b0bd0155b.zip
llvm-9455df969ef34681d08b2118a2ca2e8b0bd0155b.tar.gz
llvm-9455df969ef34681d08b2118a2ca2e8b0bd0155b.tar.bz2
[Transforms] Avoid repeated hash lookups (NFC) (#131556)
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/BasicBlockUtils.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index f814204..04b2d1a 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -511,7 +511,7 @@ DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
continue;
DebugVariable Key(DVR.getVariable(), std::nullopt,
DVR.getDebugLoc()->getInlinedAt());
- auto VMI = VariableMap.find(Key);
+ auto [VMI, Inserted] = VariableMap.try_emplace(Key);
// A dbg.assign with no linked instructions can be treated like a
// dbg.value (i.e. can be deleted).
bool IsDbgValueKind =
@@ -520,12 +520,12 @@ DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
// Update the map if we found a new value/expression describing the
// variable, or if the variable wasn't mapped already.
SmallVector<Value *, 4> Values(DVR.location_ops());
- if (VMI == VariableMap.end() || VMI->second.first != Values ||
+ if (Inserted || VMI->second.first != Values ||
VMI->second.second != DVR.getExpression()) {
if (IsDbgValueKind)
- VariableMap[Key] = {Values, DVR.getExpression()};
+ VMI->second = {Values, DVR.getExpression()};
else
- VariableMap[Key] = {Values, nullptr};
+ VMI->second = {Values, nullptr};
continue;
}
// Don't delete dbg.assign intrinsics that are linked to instructions.
@@ -591,7 +591,7 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(&I)) {
DebugVariable Key(DVI->getVariable(), std::nullopt,
DVI->getDebugLoc()->getInlinedAt());
- auto VMI = VariableMap.find(Key);
+ auto [VMI, Inserted] = VariableMap.try_emplace(Key);
auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI);
// A dbg.assign with no linked instructions can be treated like a
// dbg.value (i.e. can be deleted).
@@ -600,15 +600,15 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
// Update the map if we found a new value/expression describing the
// variable, or if the variable wasn't mapped already.
SmallVector<Value *, 4> Values(DVI->getValues());
- if (VMI == VariableMap.end() || VMI->second.first != Values ||
+ if (Inserted || VMI->second.first != Values ||
VMI->second.second != DVI->getExpression()) {
// Use a sentinel value (nullptr) for the DIExpression when we see a
// linked dbg.assign so that the next debug intrinsic will never match
// it (i.e. always treat linked dbg.assigns as if they're unique).
if (IsDbgValueKind)
- VariableMap[Key] = {Values, DVI->getExpression()};
+ VMI->second = {Values, DVI->getExpression()};
else
- VariableMap[Key] = {Values, nullptr};
+ VMI->second = {Values, nullptr};
continue;
}