Skip to content

Commit 620dbf1

Browse files
[llvm] Use llvm::interleaved (NFC) (llvm#145839)
Note that llvm::interleaved constructs a string with the elements from a given range with a given separator.
1 parent 7eec132 commit 620dbf1

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
lines changed

llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/DebugInfo/GSYM/GsymCreator.h"
1313
#include "llvm/MC/StringTableBuilder.h"
1414
#include "llvm/Support/DataExtractor.h"
15+
#include "llvm/Support/InterleavedRange.h"
1516
#include "llvm/Support/YAMLParser.h"
1617
#include "llvm/Support/YAMLTraits.h"
1718
#include "llvm/Support/raw_ostream.h"
@@ -231,13 +232,7 @@ Error CallSiteInfoLoader::processYAMLFunctions(
231232
raw_ostream &gsym::operator<<(raw_ostream &OS, const CallSiteInfo &CSI) {
232233
OS << " Return=" << HEX64(CSI.ReturnOffset);
233234
OS << " Flags=" << HEX8(CSI.Flags);
234-
235-
OS << " RegEx=";
236-
for (uint32_t i = 0; i < CSI.MatchRegex.size(); ++i) {
237-
if (i > 0)
238-
OS << ",";
239-
OS << CSI.MatchRegex[i];
240-
}
235+
OS << " RegEx=" << llvm::interleaved(CSI.MatchRegex, ",");
241236
return OS;
242237
}
243238

llvm/tools/llvm-exegesis/lib/MCInstrDescView.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <tuple>
1313

1414
#include "llvm/ADT/STLExtras.h"
15+
#include "llvm/Support/InterleavedRange.h"
1516

1617
namespace llvm {
1718
namespace exegesis {
@@ -293,15 +294,8 @@ void Instruction::dump(const MCRegisterInfo &RegInfo,
293294
}
294295
for (const auto &Var : Variables) {
295296
Stream << "- Var" << Var.getIndex();
296-
Stream << " [";
297-
bool IsFirst = true;
298-
for (auto OperandIndex : Var.TiedOperands) {
299-
if (!IsFirst)
300-
Stream << ",";
301-
Stream << "Op" << OperandIndex;
302-
IsFirst = false;
303-
}
304-
Stream << "]";
297+
Stream << " ";
298+
Stream << llvm::interleaved_array(Var.TiedOperands, ",");
305299
Stream << "\n";
306300
}
307301
if (hasMemoryOperands())

llvm/tools/llvm-remarkutil/RemarkCounter.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "RemarkCounter.h"
1414
#include "RemarkUtilRegistry.h"
1515
#include "llvm/Support/CommandLine.h"
16+
#include "llvm/Support/InterleavedRange.h"
1617
#include "llvm/Support/Regex.h"
1718

1819
using namespace llvm;
@@ -197,23 +198,11 @@ Error ArgumentCounter::print(StringRef OutputFileName) {
197198

198199
auto OF = std::move(*MaybeOF);
199200
OF->os() << groupByToStr(Group) << ",";
200-
unsigned Idx = 0;
201-
for (auto [Key, _] : ArgumentSetIdxMap) {
202-
OF->os() << Key;
203-
if (Idx != ArgumentSetIdxMap.size() - 1)
204-
OF->os() << ",";
205-
Idx++;
206-
}
201+
OF->os() << llvm::interleaved(llvm::make_first_range(ArgumentSetIdxMap), ",");
207202
OF->os() << "\n";
208203
for (auto [Header, CountVector] : CountByKeysMap) {
209204
OF->os() << Header << ",";
210-
unsigned Idx = 0;
211-
for (auto Count : CountVector) {
212-
OF->os() << Count;
213-
if (Idx != ArgumentSetIdxMap.size() - 1)
214-
OF->os() << ",";
215-
Idx++;
216-
}
205+
OF->os() << llvm::interleaved(CountVector, ",");
217206
OF->os() << "\n";
218207
}
219208
return Error::success();

0 commit comments

Comments
 (0)