Skip to content

[llvm] Use llvm::interleaved (NFC) #145839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

Note that llvm::interleaved constructs a string with the elements from
a given range with a given separator.

Note that llvm::interleaved constructs a string with the elements from
a given range with a given separator.
@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-tools-llvm-exegesis

@llvm/pr-subscribers-debuginfo

Author: Kazu Hirata (kazutakahirata)

Changes

Note that llvm::interleaved constructs a string with the elements from
a given range with a given separator.


Full diff: https://github.com/llvm/llvm-project/pull/145839.diff

3 Files Affected:

  • (modified) llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp (+2-7)
  • (modified) llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp (+3-9)
  • (modified) llvm/tools/llvm-remarkutil/RemarkCounter.cpp (+3-14)
diff --git a/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp b/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
index 8cd4e22d34fcf..4af8d3044f4de 100644
--- a/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
+++ b/llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
@@ -12,6 +12,7 @@
 #include "llvm/DebugInfo/GSYM/GsymCreator.h"
 #include "llvm/MC/StringTableBuilder.h"
 #include "llvm/Support/DataExtractor.h"
+#include "llvm/Support/InterleavedRange.h"
 #include "llvm/Support/YAMLParser.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
@@ -231,13 +232,7 @@ Error CallSiteInfoLoader::processYAMLFunctions(
 raw_ostream &gsym::operator<<(raw_ostream &OS, const CallSiteInfo &CSI) {
   OS << "  Return=" << HEX64(CSI.ReturnOffset);
   OS << "  Flags=" << HEX8(CSI.Flags);
-
-  OS << "  RegEx=";
-  for (uint32_t i = 0; i < CSI.MatchRegex.size(); ++i) {
-    if (i > 0)
-      OS << ",";
-    OS << CSI.MatchRegex[i];
-  }
+  OS << "  RegEx=" << llvm::interleaved(CSI.MatchRegex, ",");
   return OS;
 }
 
diff --git a/llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp b/llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp
index e0e796cee8040..66c770d9ca86b 100644
--- a/llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp
+++ b/llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp
@@ -12,6 +12,7 @@
 #include <tuple>
 
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/InterleavedRange.h"
 
 namespace llvm {
 namespace exegesis {
@@ -293,15 +294,8 @@ void Instruction::dump(const MCRegisterInfo &RegInfo,
   }
   for (const auto &Var : Variables) {
     Stream << "- Var" << Var.getIndex();
-    Stream << " [";
-    bool IsFirst = true;
-    for (auto OperandIndex : Var.TiedOperands) {
-      if (!IsFirst)
-        Stream << ",";
-      Stream << "Op" << OperandIndex;
-      IsFirst = false;
-    }
-    Stream << "]";
+    Stream << " ";
+    Stream << llvm::interleaved_array(Var.TiedOperands, ",");
     Stream << "\n";
   }
   if (hasMemoryOperands())
diff --git a/llvm/tools/llvm-remarkutil/RemarkCounter.cpp b/llvm/tools/llvm-remarkutil/RemarkCounter.cpp
index 0e6198cbb5203..7d5c84815b3bb 100644
--- a/llvm/tools/llvm-remarkutil/RemarkCounter.cpp
+++ b/llvm/tools/llvm-remarkutil/RemarkCounter.cpp
@@ -13,6 +13,7 @@
 #include "RemarkCounter.h"
 #include "RemarkUtilRegistry.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/InterleavedRange.h"
 #include "llvm/Support/Regex.h"
 
 using namespace llvm;
@@ -197,23 +198,11 @@ Error ArgumentCounter::print(StringRef OutputFileName) {
 
   auto OF = std::move(*MaybeOF);
   OF->os() << groupByToStr(Group) << ",";
-  unsigned Idx = 0;
-  for (auto [Key, _] : ArgumentSetIdxMap) {
-    OF->os() << Key;
-    if (Idx != ArgumentSetIdxMap.size() - 1)
-      OF->os() << ",";
-    Idx++;
-  }
+  OF->os() << llvm::interleaved(llvm::make_first_range(ArgumentSetIdxMap), ",");
   OF->os() << "\n";
   for (auto [Header, CountVector] : CountByKeysMap) {
     OF->os() << Header << ",";
-    unsigned Idx = 0;
-    for (auto Count : CountVector) {
-      OF->os() << Count;
-      if (Idx != ArgumentSetIdxMap.size() - 1)
-        OF->os() << ",";
-      Idx++;
-    }
+    OF->os() << llvm::interleaved(CountVector, ",");
     OF->os() << "\n";
   }
   return Error::success();

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - cheers!

@kazutakahirata kazutakahirata merged commit 620dbf1 into llvm:main Jun 26, 2025
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250625_interleaved_llvm branch June 26, 2025 15:41
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
Note that llvm::interleaved constructs a string with the elements from
a given range with a given separator.
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
Note that llvm::interleaved constructs a string with the elements from
a given range with a given separator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants