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

Pratyay Pande via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 01:21:32 PDT 2024


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

>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 1/2] [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  ";
 

>From a6e6e75ceba9ae37138a9364ecd4b38a22f30644 Mon Sep 17 00:00:00 2001
From: "Pande, Pratyay" <pratyay.pande at intel.com>
Date: Mon, 30 Sep 2024 01:20:14 -0700
Subject: [PATCH 2/2] Removing reference as enumerate returns a ref. Fixed
 clang-format issues

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

diff --git a/llvm/utils/TableGen/IntrinsicEmitter.cpp b/llvm/utils/TableGen/IntrinsicEmitter.cpp
index 469d0bbf3ae4b6..c3a547ee862631 100644
--- a/llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ b/llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -230,7 +230,8 @@ struct IntrinsicTargetInfo {
 static constexpr IntrinsicTargetInfo TargetInfos[] = {
 )";
   for (const auto &Target : Ints.Targets)
-    OS << formatv("  {{\"{}\", {}, {}},\n", Target.Name, Target.Offset, Target.Count);
+    OS << formatv("  {{\"{}\", {}, {}},\n", Target.Name, Target.Offset,
+                  Target.Count);
   OS << R"(};
 #endif
 
@@ -255,7 +256,7 @@ void IntrinsicEmitter::EmitIntrinsicToOverloadTable(
 static constexpr uint8_t OTable[] = {
   0
   )";
-  for (const 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;
 
@@ -345,7 +346,8 @@ static constexpr {} IIT_Table[] = {{
                 FixedEncodingTypeName);
 
   unsigned MaxOffset = 0;
-  for (const 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