[llvm] [CodeGen] Use DenseMap::operator[] (NFC) (PR #108489)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 12 22:47:56 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/108489
Once we modernize CopyInfo with default member initializations,
Copies.insert({Unit, ...})
becomes equivalent to:
Copies.try_emplace(Unit)
which we can simplify further down to Copies[Unit].
>From 853f97ee1fa1ba00e6343dda78b3eab24afcf0c4 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 12 Sep 2024 21:32:33 -0700
Subject: [PATCH] [CodeGen] Use DenseMap::operator[] (NFC)
Once we modernize CopyInfo with default member initializations,
Copies.insert({Unit, ...})
becomes equivalent to:
Copies.try_emplace(Unit)
which we can simplify further down to Copies[Unit].
---
llvm/lib/CodeGen/MachineCopyPropagation.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index fab36f4858e093..8bcc437cbfb865 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -108,9 +108,10 @@ static std::optional<DestSourcePair> isCopyInstr(const MachineInstr &MI,
class CopyTracker {
struct CopyInfo {
- MachineInstr *MI, *LastSeenUseInCopy;
+ MachineInstr *MI = nullptr;
+ MachineInstr *LastSeenUseInCopy = nullptr;
SmallVector<MCRegister, 4> DefRegs;
- bool Avail;
+ bool Avail = false;
};
DenseMap<MCRegUnit, CopyInfo> Copies;
@@ -240,8 +241,7 @@ class CopyTracker {
// Remember source that's copied to Def. Once it's clobbered, then
// it's no longer available for copy propagation.
for (MCRegUnit Unit : TRI.regunits(Src)) {
- auto I = Copies.insert({Unit, {nullptr, nullptr, {}, false}});
- auto &Copy = I.first->second;
+ auto &Copy = Copies[Unit];
if (!is_contained(Copy.DefRegs, Def))
Copy.DefRegs.push_back(Def);
Copy.LastSeenUseInCopy = MI;
More information about the llvm-commits
mailing list