[llvm] [NFC] Use references to avoid copying (PR #110462)

Pratyay Pande via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 00:59:22 PDT 2024


https://github.com/pratyay-p created https://github.com/llvm/llvm-project/pull/110462

Modifying some uses of `auto` to `auto&` to avoid unnecessary copying.

>From 3f014992ff86092f3caee271e884ada60cf9500c Mon Sep 17 00:00:00 2001
From: "Pande, Pratyay" <pratyay.pande at intel.com>
Date: Sun, 29 Sep 2024 22:54:18 -0700
Subject: [PATCH] [NFC] Use references to avoid copying Modifying auto to const
 auto& to avoid unnecessary copying

---
 llvm/utils/TableGen/IntrinsicEmitter.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index 51c2e9a12e00cf..ecd722ca0cfe74 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -229,8 +229,8 @@ struct IntrinsicTargetInfo {
 };
 static constexpr IntrinsicTargetInfo TargetInfos[] = {
 )";
-  for (const auto [Name, Offset, Count] : Ints.Targets)
-    OS << formatv("  {{\"{}\", {}, {}},\n", Name, Offset, Count);
+  for (const auto &Target : Ints.Targets)
+    OS << formatv("  {{\"{}\", {}, {}},\n", Target.Name, Target.Offset, Target.Count);
   OS << R"(};
 #endif
 
@@ -255,7 +255,7 @@ void IntrinsicEmitter::EmitIntrinsicToOverloadTable(
 static constexpr uint8_t OTable[] = {
   0
   )";
-  for (auto [I, Int] : enumerate(Ints)) {
+  for (const auto& [I, Int] : enumerate(Ints)) {
     // Add one to the index so we emit a null bit for the invalid #0 intrinsic.
     size_t Idx = I + 1;
 
@@ -347,7 +347,7 @@ static constexpr {} IIT_Table[] = {{
                 FixedEncodingTypeName);
 
   unsigned MaxOffset = 0;
-  for (auto [Idx, FixedEncoding, Int] : enumerate(FixedEncodings, Ints)) {
+  for (const auto& [Idx, FixedEncoding, Int] : enumerate(FixedEncodings, Ints)) {
     if ((Idx & 7) == 7)
       OS << "\n  ";
 



More information about the llvm-commits mailing list