Skip to content

[CodeGen] Use DenseMap::operator[] (NFC) #108489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

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].

@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2024

@llvm/pr-subscribers-llvm-regalloc

Author: Kazu Hirata (kazutakahirata)

Changes

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].


Full diff: https://github.com/llvm/llvm-project/pull/108489.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/MachineCopyPropagation.cpp (+4-4)
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;

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].
@kazutakahirata kazutakahirata force-pushed the cleanup_001_DenseMap_sqbr_MachineCopyPropagation branch from 853f97e to 0bfd3cc Compare September 13, 2024 14:46
@kazutakahirata kazutakahirata merged commit b9d85b1 into llvm:main Sep 13, 2024
8 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_DenseMap_sqbr_MachineCopyPropagation branch September 13, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants