[llvm] [NFC] Use references to avoid copying (PR #99863)
Pratyay Pande via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 20:03:24 PDT 2024
https://github.com/pratyay-p updated https://github.com/llvm/llvm-project/pull/99863
>From b15c063a955eaa0547f7a7b6b3ba8cfd946fef4b Mon Sep 17 00:00:00 2001
From: "Pande, Pratyay" <pratyay.pande at intel.com>
Date: Mon, 22 Jul 2024 03:40:48 -0700
Subject: [PATCH 1/5] Modified auto to auto& for MachineOperand objects
---
llvm/lib/CodeGen/RegAllocFast.cpp | 2 +-
llvm/lib/CodeGen/WindowScheduler.cpp | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp
index b4660d4085ffd8..7e9f96a3451f71 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -584,7 +584,7 @@ void RegAllocFastImpl::spill(MachineBasicBlock::iterator Before,
SpilledOperandsMap;
for (MachineOperand *MO : LRIDbgOperands)
SpilledOperandsMap[MO->getParent()].push_back(MO);
- for (auto MISpilledOperands : SpilledOperandsMap) {
+ for (auto& MISpilledOperands : SpilledOperandsMap) {
MachineInstr &DBG = *MISpilledOperands.first;
// We don't have enough support for tracking operands of DBG_VALUE_LISTs.
if (DBG.isDebugValueList())
diff --git a/llvm/lib/CodeGen/WindowScheduler.cpp b/llvm/lib/CodeGen/WindowScheduler.cpp
index 0777480499e55b..15e99bf40c749e 100644
--- a/llvm/lib/CodeGen/WindowScheduler.cpp
+++ b/llvm/lib/CodeGen/WindowScheduler.cpp
@@ -315,7 +315,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()));
@@ -692,7 +692,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)
>From a2c1adac260c0b273974e15388197d0b42be756c Mon Sep 17 00:00:00 2001
From: Pratyay Pande <pratyay.pande at intel.com>
Date: Fri, 2 Aug 2024 11:06:58 +0530
Subject: [PATCH 2/5] Fixed formatting in RegAllocFast.cpp
---
llvm/lib/CodeGen/RegAllocFast.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp
index 58cd550e6bb183..68a8c835082445 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -584,7 +584,7 @@ void RegAllocFastImpl::spill(MachineBasicBlock::iterator Before,
SpilledOperandsMap;
for (MachineOperand *MO : LRIDbgOperands)
SpilledOperandsMap[MO->getParent()].push_back(MO);
- for (auto& MISpilledOperands : SpilledOperandsMap) {
+ for (auto &MISpilledOperands : SpilledOperandsMap) {
MachineInstr &DBG = *MISpilledOperands.first;
// We don't have enough support for tracking operands of DBG_VALUE_LISTs.
if (DBG.isDebugValueList())
>From 6f20f888a272ef85069cf5812d95dd9481f44165 Mon Sep 17 00:00:00 2001
From: Pratyay Pande <pratyay.pande at intel.com>
Date: Fri, 2 Aug 2024 11:08:01 +0530
Subject: [PATCH 3/5] Fixed formatting in WindowScheduler.cpp
---
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 18d0670dc8d38d..6ac1c4c135981e 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 (const 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()));
@@ -700,7 +700,7 @@ unsigned WindowScheduler::getOriStage(MachineInstr *OriMI, unsigned Offset) {
Register WindowScheduler::getAntiRegister(MachineInstr *Phi) {
assert(Phi->isPHI() && "Expecting PHI!");
Register AntiReg;
- for (const auto& MO : Phi->uses()) {
+ for (const auto &MO : Phi->uses()) {
if (MO.isReg())
AntiReg = MO.getReg();
else if (MO.isMBB() && MO.getMBB() == MBB)
>From 995536d6ce7128799706e9240466b304153de233 Mon Sep 17 00:00:00 2001
From: "Pande, Pratyay" <pratyay.pande at intel.com>
Date: Tue, 6 Aug 2024 05:01:52 -0700
Subject: [PATCH 4/5] Add const to MISpilledOperands
---
llvm/include/llvm/CodeGen/MachineInstrBuilder.h | 2 +-
llvm/lib/CodeGen/MachineInstr.cpp | 4 ++--
llvm/lib/CodeGen/RegAllocFast.cpp | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineInstrBuilder.h b/llvm/include/llvm/CodeGen/MachineInstrBuilder.h
index 0a73b0f6b36733..6e058da5515eb6 100644
--- a/llvm/include/llvm/CodeGen/MachineInstrBuilder.h
+++ b/llvm/include/llvm/CodeGen/MachineInstrBuilder.h
@@ -540,7 +540,7 @@ MachineInstr *buildDbgValueForSpill(MachineBasicBlock &BB,
MachineInstr *
buildDbgValueForSpill(MachineBasicBlock &BB, MachineBasicBlock::iterator I,
const MachineInstr &Orig, int FrameIndex,
- SmallVectorImpl<const MachineOperand *> &SpilledOperands);
+ const SmallVectorImpl<const MachineOperand *> &SpilledOperands);
/// Update a DBG_VALUE whose value has been spilled to FrameIndex. Useful when
/// modifying an instruction in place while iterating over a basic block.
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 583bc1bc4a42c0..2b3f499105d29c 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -2298,7 +2298,7 @@ MachineInstrBuilder llvm::BuildMI(MachineBasicBlock &BB,
/// This prepends DW_OP_deref when spilling an indirect DBG_VALUE.
static const DIExpression *
computeExprForSpill(const MachineInstr &MI,
- SmallVectorImpl<const MachineOperand *> &SpilledOperands) {
+ const SmallVectorImpl<const MachineOperand *> &SpilledOperands) {
assert(MI.getDebugVariable()->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
"Expected inlined-at fields to agree");
@@ -2353,7 +2353,7 @@ MachineInstr *llvm::buildDbgValueForSpill(MachineBasicBlock &BB,
MachineInstr *llvm::buildDbgValueForSpill(
MachineBasicBlock &BB, MachineBasicBlock::iterator I,
const MachineInstr &Orig, int FrameIndex,
- SmallVectorImpl<const MachineOperand *> &SpilledOperands) {
+ const SmallVectorImpl<const MachineOperand *> &SpilledOperands) {
const DIExpression *Expr = computeExprForSpill(Orig, SpilledOperands);
MachineInstrBuilder NewMI =
BuildMI(BB, I, Orig.getDebugLoc(), Orig.getDesc());
diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp
index 68a8c835082445..62f7ed29c8c819 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -584,7 +584,7 @@ void RegAllocFastImpl::spill(MachineBasicBlock::iterator Before,
SpilledOperandsMap;
for (MachineOperand *MO : LRIDbgOperands)
SpilledOperandsMap[MO->getParent()].push_back(MO);
- for (auto &MISpilledOperands : SpilledOperandsMap) {
+ for (const auto &MISpilledOperands : SpilledOperandsMap) {
MachineInstr &DBG = *MISpilledOperands.first;
// We don't have enough support for tracking operands of DBG_VALUE_LISTs.
if (DBG.isDebugValueList())
>From 051288b87c2e611be84eed35b09743c4f8fbf035 Mon Sep 17 00:00:00 2001
From: "Pande, Pratyay" <pratyay.pande at intel.com>
Date: Tue, 6 Aug 2024 05:43:09 -0700
Subject: [PATCH 5/5] Fix clang-format issues
---
llvm/include/llvm/CodeGen/MachineInstrBuilder.h | 8 ++++----
llvm/lib/CodeGen/MachineInstr.cpp | 6 +++---
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineInstrBuilder.h b/llvm/include/llvm/CodeGen/MachineInstrBuilder.h
index 6e058da5515eb6..49d9402d0c2732 100644
--- a/llvm/include/llvm/CodeGen/MachineInstrBuilder.h
+++ b/llvm/include/llvm/CodeGen/MachineInstrBuilder.h
@@ -537,10 +537,10 @@ MachineInstr *buildDbgValueForSpill(MachineBasicBlock &BB,
MachineBasicBlock::iterator I,
const MachineInstr &Orig, int FrameIndex,
Register SpillReg);
-MachineInstr *
-buildDbgValueForSpill(MachineBasicBlock &BB, MachineBasicBlock::iterator I,
- const MachineInstr &Orig, int FrameIndex,
- const SmallVectorImpl<const MachineOperand *> &SpilledOperands);
+MachineInstr *buildDbgValueForSpill(
+ MachineBasicBlock &BB, MachineBasicBlock::iterator I,
+ const MachineInstr &Orig, int FrameIndex,
+ const SmallVectorImpl<const MachineOperand *> &SpilledOperands);
/// Update a DBG_VALUE whose value has been spilled to FrameIndex. Useful when
/// modifying an instruction in place while iterating over a basic block.
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 2b3f499105d29c..0f2acdb12389d4 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -2296,9 +2296,9 @@ MachineInstrBuilder llvm::BuildMI(MachineBasicBlock &BB,
/// Compute the new DIExpression to use with a DBG_VALUE for a spill slot.
/// This prepends DW_OP_deref when spilling an indirect DBG_VALUE.
-static const DIExpression *
-computeExprForSpill(const MachineInstr &MI,
- const SmallVectorImpl<const MachineOperand *> &SpilledOperands) {
+static const DIExpression *computeExprForSpill(
+ const MachineInstr &MI,
+ const SmallVectorImpl<const MachineOperand *> &SpilledOperands) {
assert(MI.getDebugVariable()->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
"Expected inlined-at fields to agree");
More information about the llvm-commits
mailing list