[llvm] [BOLT] Use const reference in range-based for loop (PR #92931)

Heewon Cho via llvm-commits llvm-commits at lists.llvm.org
Tue May 21 09:45:11 PDT 2024


https://github.com/Pribess updated https://github.com/llvm/llvm-project/pull/92931

>From a4acc5ca4425dd2e59694ebf9e8362fc37c38261 Mon Sep 17 00:00:00 2001
From: Heewon Cho <heewon6752 at gmail.com>
Date: Tue, 21 May 2024 21:52:25 +0900
Subject: [PATCH 1/2] [BOLT] Use const reference in range-based for loop

---
 bolt/include/bolt/Passes/StokeInfo.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bolt/include/bolt/Passes/StokeInfo.h b/bolt/include/bolt/Passes/StokeInfo.h
index 76417e6a2c3ba..a18c2a05d0153 100644
--- a/bolt/include/bolt/Passes/StokeInfo.h
+++ b/bolt/include/bolt/Passes/StokeInfo.h
@@ -87,10 +87,10 @@ struct StokeFuncInfo {
               << "," << NumBlocks << "," << IsLoopFree << "," << NumLoops << ","
               << MaxLoopDepth << "," << HotSize << "," << TotalSize << ","
               << Score << "," << HasCall << ",\"{ ";
-      for (std::string S : DefIn)
+      for (const std::string &S : DefIn)
         Outfile << "%" << S << " ";
       Outfile << "}\",\"{ ";
-      for (std::string S : LiveOut)
+      for (const std::string &S : LiveOut)
         Outfile << "%" << S << " ";
       Outfile << "}\"," << HeapOut << "," << StackOut << "," << HasRipAddr
               << "," << Omitted << "\n";

>From 401338ba5ec96ccbf2dca47d2ac1e59088b85c17 Mon Sep 17 00:00:00 2001
From: Heewon Cho <heewon6752 at gmail.com>
Date: Wed, 22 May 2024 01:45:00 +0900
Subject: [PATCH 2/2] [BOLT] Remove dead initialization code

---
 bolt/runtime/instr.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/bolt/runtime/instr.cpp b/bolt/runtime/instr.cpp
index 16e0bbd55f90b..d1f8a216badcf 100644
--- a/bolt/runtime/instr.cpp
+++ b/bolt/runtime/instr.cpp
@@ -1245,7 +1245,6 @@ void Graph::computeEdgeFrequencies(const uint64_t *Counters,
       continue;
 
     assert(SpanningTreeNodes[Cur].NumInEdges == 1, "must have 1 parent");
-    const uint32_t Parent = SpanningTreeNodes[Cur].InEdges[0].Node;
     const uint32_t ParentEdge = SpanningTreeNodes[Cur].InEdges[0].ID;
 
     // Calculate parent edge freq.
@@ -1464,9 +1463,8 @@ void visitCallFlowEntry(CallFlowHashTable::MapEntry &Entry, int FD,
 int openProfile() {
   // Build the profile name string by appending our PID
   char Buf[BufSize];
-  char *Ptr = Buf;
   uint64_t PID = __getpid();
-  Ptr = strCopy(Buf, __bolt_instr_filename, BufSize);
+  char *Ptr = strCopy(Buf, __bolt_instr_filename, BufSize);
   if (__bolt_instr_use_pid) {
     Ptr = strCopy(Ptr, ".", BufSize - (Ptr - Buf + 1));
     Ptr = intToStr(Ptr, PID, 10);



More information about the llvm-commits mailing list