[llvm] Changing `auto` to `auto&` to avoid unnecessary copies (PR #108335)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 23:18:12 PDT 2024
https://github.com/abhishek-kaushik22 created https://github.com/llvm/llvm-project/pull/108335
Changing `auto` to `auto&` to avoid unnecessary copies
>From 4724ed6a6567613faa7a3daffc1719fe7dfdfaaf Mon Sep 17 00:00:00 2001
From: abhishek-kaushik22 <abhishek.kaushik at intel.com>
Date: Thu, 12 Sep 2024 11:42:47 +0530
Subject: [PATCH] Optimize loop by changing `auto` to `auto&` to avoid
unnecessary copies
---
llvm/lib/CodeGen/WindowScheduler.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/WindowScheduler.cpp b/llvm/lib/CodeGen/WindowScheduler.cpp
index f1658e36ae1e92..ae3cc627aa7f0e 100644
--- a/llvm/lib/CodeGen/WindowScheduler.cpp
+++ b/llvm/lib/CodeGen/WindowScheduler.cpp
@@ -318,7 +318,7 @@ void WindowScheduler::generateTripleMBB() {
auto *NewMI = MF->CloneMachineInstr(MI);
DenseMap<Register, Register> NewDefs;
// New defines are updated.
- for (auto MO : NewMI->all_defs())
+ for (const auto &MO : NewMI->all_defs())
if (MO.isReg() && MO.getReg().isVirtual()) {
Register NewDef =
MRI->createVirtualRegister(MRI->getRegClass(MO.getReg()));
@@ -699,7 +699,7 @@ unsigned WindowScheduler::getOriStage(MachineInstr *OriMI, unsigned Offset) {
Register WindowScheduler::getAntiRegister(MachineInstr *Phi) {
assert(Phi->isPHI() && "Expecting PHI!");
Register AntiReg;
- for (auto MO : Phi->uses()) {
+ for (const auto &MO : Phi->uses()) {
if (MO.isReg())
AntiReg = MO.getReg();
else if (MO.isMBB() && MO.getMBB() == MBB)
More information about the llvm-commits
mailing list