[llvm] [llvm] Use llvm::interleaved (NFC) (PR #145839)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 25 22:55:20 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/145839
Note that llvm::interleaved constructs a string with the elements from
a given range with a given separator.
>From 7624dacec1e62f5b28a8c57d8232a595506dcf25 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 25 Jun 2025 00:09:34 -0700
Subject: [PATCH] [llvm] Use llvm::interleaved (NFC)
Note that llvm::interleaved constructs a string with the elements from
a given range with a given separator.
---
llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp | 9 ++-------
.../tools/llvm-exegesis/lib/MCInstrDescView.cpp | 12 +++---------
llvm/tools/llvm-remarkutil/RemarkCounter.cpp | 17 +++--------------
3 files changed, 8 insertions(+), 30 deletions(-)
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();
More information about the llvm-commits
mailing list