[llvm] [NFC][LLVM] Adopt ListSeparator in more places (PR #172909)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 18 13:52:52 PST 2025
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/172909
None
>From c5fc7b5288a83b52cda217b897da8f130217185e Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Thu, 18 Dec 2025 13:51:24 -0800
Subject: [PATCH] [NFC][LLVM] Adopt ListSeparator in more places
---
llvm/include/llvm/ADT/GenericCycleInfo.h | 11 ++--
.../llvm/DebugInfo/DWARF/DWARFTypePrinter.h | 7 +--
llvm/include/llvm/IR/ModuleSummaryIndex.h | 24 +++-----
llvm/lib/Analysis/CFGSCCPrinter.cpp | 8 +--
llvm/lib/Analysis/CallGraph.cpp | 14 ++---
llvm/lib/Analysis/InlineAdvisor.cpp | 15 ++---
llvm/lib/Analysis/ScalarEvolution.cpp | 18 ++----
llvm/lib/CodeGen/TargetInstrInfo.cpp | 11 +---
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp | 14 ++---
.../DWARF/DWARFUnwindTablePrinter.cpp | 8 +--
llvm/lib/DebugInfo/GSYM/InlineInfo.cpp | 12 ++--
llvm/lib/DebugInfo/GSYM/LineTable.cpp | 4 +-
llvm/lib/FileCheck/FileCheck.cpp | 10 +---
llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp | 10 +---
llvm/lib/MC/MCInstPrinter.cpp | 13 ++---
.../IPO/MemProfContextDisambiguation.cpp | 10 +---
.../Transforms/Scalar/LoopStrengthReduce.cpp | 55 +++++++------------
llvm/tools/llvm-config/llvm-config.cpp | 6 +-
llvm/tools/llvm-exegesis/lib/Analysis.cpp | 6 +-
llvm/tools/llvm-remarkutil/RemarkSummary.cpp | 10 +---
.../TableGen/Common/PredicateExpander.cpp | 7 +--
21 files changed, 91 insertions(+), 182 deletions(-)
diff --git a/llvm/include/llvm/ADT/GenericCycleInfo.h b/llvm/include/llvm/ADT/GenericCycleInfo.h
index c31bab3c178ca..365992c0be8dc 100644
--- a/llvm/include/llvm/ADT/GenericCycleInfo.h
+++ b/llvm/include/llvm/ADT/GenericCycleInfo.h
@@ -32,6 +32,7 @@
#include "llvm/ADT/GenericSSAContext.h"
#include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@@ -230,13 +231,9 @@ template <typename ContextT> class GenericCycle {
Printable printEntries(const ContextT &Ctx) const {
return Printable([this, &Ctx](raw_ostream &Out) {
- bool First = true;
- for (auto *Entry : Entries) {
- if (!First)
- Out << ' ';
- First = false;
- Out << Ctx.print(Entry);
- }
+ ListSeparator LS(" ");
+ for (auto *Entry : Entries)
+ Out << LS << Ctx.print(Entry);
});
}
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
index 5201870131ce6..4a5afebe42b81 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
@@ -709,7 +709,7 @@ void DWARFTypePrinter<DieType>::appendSubroutineNameAfter(
DieType FirstParamIfArtificial;
OS << '(';
EndedWithTemplate = false;
- bool First = true;
+ ListSeparator LS;
bool RealFirst = true;
for (DieType P : D) {
if (P.getTag() != dwarf::DW_TAG_formal_parameter &&
@@ -722,10 +722,7 @@ void DWARFTypePrinter<DieType>::appendSubroutineNameAfter(
RealFirst = false;
continue;
}
- if (!First) {
- OS << ", ";
- }
- First = false;
+ OS << LS;
if (P.getTag() == dwarf::DW_TAG_unspecified_parameters)
OS << "...";
else
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index eb60bee309cf5..7618525bd46d7 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -454,29 +454,21 @@ struct AllocInfo {
};
inline raw_ostream &operator<<(raw_ostream &OS, const AllocInfo &AE) {
- bool First = true;
+ ListSeparator LS;
OS << "Versions: ";
- for (auto V : AE.Versions) {
- if (!First)
- OS << ", ";
- First = false;
- OS << (unsigned)V;
- }
+ for (auto V : AE.Versions)
+ OS << LS << (unsigned)V;
+
OS << " MIB:\n";
- for (auto &M : AE.MIBs) {
+ for (auto &M : AE.MIBs)
OS << "\t\t" << M << "\n";
- }
if (!AE.ContextSizeInfos.empty()) {
OS << "\tContextSizeInfo per MIB:\n";
for (auto Infos : AE.ContextSizeInfos) {
OS << "\t\t";
- bool FirstInfo = true;
- for (auto [FullStackId, TotalSize] : Infos) {
- if (!FirstInfo)
- OS << ", ";
- FirstInfo = false;
- OS << "{ " << FullStackId << ", " << TotalSize << " }";
- }
+ ListSeparator InfoLS;
+ for (auto [FullStackId, TotalSize] : Infos)
+ OS << InfoLS << "{ " << FullStackId << ", " << TotalSize << " }";
OS << "\n";
}
}
diff --git a/llvm/lib/Analysis/CFGSCCPrinter.cpp b/llvm/lib/Analysis/CFGSCCPrinter.cpp
index 24495eba10dac..e9ed5e49147d7 100644
--- a/llvm/lib/Analysis/CFGSCCPrinter.cpp
+++ b/llvm/lib/Analysis/CFGSCCPrinter.cpp
@@ -8,6 +8,7 @@
#include "llvm/Analysis/CFGSCCPrinter.h"
#include "llvm/ADT/SCCIterator.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/IR/CFG.h"
using namespace llvm;
@@ -19,12 +20,9 @@ PreservedAnalyses CFGSCCPrinterPass::run(Function &F,
for (scc_iterator<Function *> SCCI = scc_begin(&F); !SCCI.isAtEnd(); ++SCCI) {
const std::vector<BasicBlock *> &NextSCC = *SCCI;
OS << "\nSCC #" << ++SccNum << ": ";
- bool First = true;
+ ListSeparator LS;
for (BasicBlock *BB : NextSCC) {
- if (First)
- First = false;
- else
- OS << ", ";
+ OS << LS;
BB->printAsOperand(OS, false);
}
if (NextSCC.size() == 1 && SCCI.hasCycle())
diff --git a/llvm/lib/Analysis/CallGraph.cpp b/llvm/lib/Analysis/CallGraph.cpp
index dd6ee32b80de8..dbdd420b776f2 100644
--- a/llvm/lib/Analysis/CallGraph.cpp
+++ b/llvm/lib/Analysis/CallGraph.cpp
@@ -10,6 +10,7 @@
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/AbstractCallSite.h"
#include "llvm/IR/Function.h"
@@ -273,16 +274,11 @@ PreservedAnalyses CallGraphSCCsPrinterPass::run(Module &M,
++SCCI) {
const std::vector<CallGraphNode *> &nextSCC = *SCCI;
OS << "\nSCC #" << ++sccNum << ": ";
- bool First = true;
- for (CallGraphNode *CGN : nextSCC) {
- if (First)
- First = false;
- else
- OS << ", ";
- OS << (CGN->getFunction() ? CGN->getFunction()->getName()
+ ListSeparator LS;
+ for (CallGraphNode *CGN : nextSCC)
+ OS << LS
+ << (CGN->getFunction() ? CGN->getFunction()->getName()
: "external node");
- }
-
if (nextSCC.size() == 1 && SCCI.hasCycle())
OS << " (Has self-loop).";
}
diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp
index 0fa804f2959e8..4a2825bb12362 100644
--- a/llvm/lib/Analysis/InlineAdvisor.cpp
+++ b/llvm/lib/Analysis/InlineAdvisor.cpp
@@ -473,10 +473,9 @@ std::string llvm::formatCallSiteLocation(DebugLoc DLoc,
const CallSiteFormat &Format) {
std::string Buffer;
raw_string_ostream CallSiteLoc(Buffer);
- bool First = true;
+ ListSeparator LS(" @ ");
for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
- if (!First)
- CallSiteLoc << " @ ";
+ CallSiteLoc << LS;
// Note that negative line offset is actually possible, but we use
// unsigned int to match line offset representation in remarks so
// it's directly consumable by relay advisor.
@@ -491,22 +490,19 @@ std::string llvm::formatCallSiteLocation(DebugLoc DLoc,
CallSiteLoc << ":" << llvm::utostr(DIL->getColumn());
if (Format.outputDiscriminator() && Discriminator)
CallSiteLoc << "." << llvm::utostr(Discriminator);
- First = false;
}
return CallSiteLoc.str();
}
void llvm::addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc) {
- if (!DLoc) {
+ if (!DLoc)
return;
- }
- bool First = true;
+ ListSeparator LS(" @ ");
Remark << " at callsite ";
for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {
- if (!First)
- Remark << " @ ";
+ Remark << LS;
unsigned int Offset = DIL->getLine();
Offset -= DIL->getScope()->getSubprogram()->getLine();
unsigned int Discriminator = DIL->getBaseDiscriminator();
@@ -517,7 +513,6 @@ void llvm::addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc) {
<< ore::NV("Column", DIL->getColumn());
if (Discriminator)
Remark << "." << ore::NV("Disc", Discriminator);
- First = false;
}
Remark << ";";
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index e1f90264be7a2..b621295f9a8aa 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -14091,15 +14091,11 @@ void ScalarEvolution::print(raw_ostream &OS) const {
OS << *ExitValue;
}
+ ListSeparator LS(", ", "\t\t"
+ "LoopDispositions: { ");
bool First = true;
for (const auto *Iter = L; Iter; Iter = Iter->getParentLoop()) {
- if (First) {
- OS << "\t\t" "LoopDispositions: { ";
- First = false;
- } else {
- OS << ", ";
- }
-
+ OS << LS;
Iter->getHeader()->printAsOperand(OS, /*PrintType=*/false);
OS << ": " << SE.getLoopDisposition(SV, Iter);
}
@@ -14107,13 +14103,7 @@ void ScalarEvolution::print(raw_ostream &OS) const {
for (const auto *InnerL : depth_first(L)) {
if (InnerL == L)
continue;
- if (First) {
- OS << "\t\t" "LoopDispositions: { ";
- First = false;
- } else {
- OS << ", ";
- }
-
+ OS << LS;
InnerL->getHeader()->printAsOperand(OS, /*PrintType=*/false);
OS << ": " << SE.getLoopDisposition(SV, InnerL);
}
diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp
index fef3a3663d3a8..2e9ae4e29c9db 100644
--- a/llvm/lib/CodeGen/TargetInstrInfo.cpp
+++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp
@@ -2048,14 +2048,9 @@ std::string TargetInstrInfo::createMIROperandComment(
if (OpIdx == InlineAsm::MIOp_ExtraInfo) {
// Print HasSideEffects, MayLoad, MayStore, IsAlignStack
unsigned ExtraInfo = Op.getImm();
- bool First = true;
- for (StringRef Info : InlineAsm::getExtraInfoNames(ExtraInfo)) {
- if (!First)
- OS << " ";
- First = false;
- OS << Info;
- }
-
+ ListSeparator LS(" ");
+ for (StringRef Info : InlineAsm::getExtraInfoNames(ExtraInfo))
+ OS << LS << Info;
return Flags;
}
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 08b58669b3eb3..e13fc3c9677d5 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -9,6 +9,7 @@
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
@@ -1219,15 +1220,10 @@ Error DWARFDebugLine::LineTable::parse(
}
if (Verbose && !Operands.empty()) {
*OS << " (operands: ";
- bool First = true;
- for (uint64_t Value : Operands) {
- if (!First)
- *OS << ", ";
- First = false;
- *OS << format("0x%16.16" PRIx64, Value);
- }
- if (Verbose)
- *OS << ')';
+ ListSeparator LS;
+ for (uint64_t Value : Operands)
+ *OS << LS << format("0x%16.16" PRIx64, Value);
+ *OS << ')';
}
}
break;
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnwindTablePrinter.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnwindTablePrinter.cpp
index a4bdd1f0a867c..bdcda266ea69d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFUnwindTablePrinter.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFUnwindTablePrinter.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/DWARF/DWARFUnwindTablePrinter.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
#include "llvm/Support/ErrorHandling.h"
@@ -115,13 +116,10 @@ raw_ostream &llvm::dwarf::operator<<(raw_ostream &OS,
/// for certain architectures like x86.
static void printRegisterLocations(const RegisterLocations &RL, raw_ostream &OS,
DIDumpOptions DumpOpts) {
- bool First = true;
+ ListSeparator LS;
for (uint32_t Reg : RL.getRegisters()) {
auto Loc = *RL.getRegisterLocation(Reg);
- if (First)
- First = false;
- else
- OS << ", ";
+ OS << LS;
printRegister(OS, DumpOpts, Reg);
OS << '=';
printUnwindLocation(Loc, OS, DumpOpts);
diff --git a/llvm/lib/DebugInfo/GSYM/InlineInfo.cpp b/llvm/lib/DebugInfo/GSYM/InlineInfo.cpp
index 71dbfff6e24ea..a86f918a97974 100644
--- a/llvm/lib/DebugInfo/GSYM/InlineInfo.cpp
+++ b/llvm/lib/DebugInfo/GSYM/InlineInfo.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/DebugInfo/GSYM/InlineInfo.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/DebugInfo/GSYM/FileEntry.h"
#include "llvm/DebugInfo/GSYM/FileWriter.h"
#include "llvm/DebugInfo/GSYM/GsymReader.h"
@@ -20,14 +21,9 @@ using namespace gsym;
raw_ostream &llvm::gsym::operator<<(raw_ostream &OS, const InlineInfo &II) {
if (!II.isValid())
return OS;
- bool First = true;
- for (auto Range : II.Ranges) {
- if (First)
- First = false;
- else
- OS << ' ';
- OS << Range;
- }
+ ListSeparator LS(" ");
+ for (auto Range : II.Ranges)
+ OS << LS << Range;
OS << " Name = " << HEX32(II.Name) << ", CallFile = " << II.CallFile
<< ", CallLine = " << II.CallFile << '\n';
for (const auto &Child : II.Children)
diff --git a/llvm/lib/DebugInfo/GSYM/LineTable.cpp b/llvm/lib/DebugInfo/GSYM/LineTable.cpp
index 666d9f15f1b43..1c4e01a067d0d 100644
--- a/llvm/lib/DebugInfo/GSYM/LineTable.cpp
+++ b/llvm/lib/DebugInfo/GSYM/LineTable.cpp
@@ -137,9 +137,9 @@ llvm::Error LineTable::encode(FileWriter &Out, uint64_t BaseAddr) const {
int64_t PrevLine = 1;
bool First = true;
for (const auto &line_entry : Lines) {
- if (First)
+ if (First) {
First = false;
- else {
+ } else {
int64_t LineDelta = (int64_t)line_entry.Line - PrevLine;
auto End = DeltaInfos.end();
auto Pos = std::lower_bound(DeltaInfos.begin(), End, LineDelta);
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index 9245db442611c..bd43179704fa0 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -1999,13 +1999,9 @@ bool FileCheck::readCheckFile(
(ImplicitNegativeChecks.empty() || !Req.IsDefaultCheckPrefix)) {
errs() << "error: no check strings found with prefix"
<< (PrefixesNotFound.size() > 1 ? "es " : " ");
- bool First = true;
- for (StringRef MissingPrefix : PrefixesNotFound) {
- if (!First)
- errs() << ", ";
- errs() << "\'" << MissingPrefix << ":'";
- First = false;
- }
+ ListSeparator LS;
+ for (StringRef MissingPrefix : PrefixesNotFound)
+ errs() << LS << "\'" << MissingPrefix << ":'";
errs() << '\n';
return true;
}
diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
index 2b33e560d74ac..417ba27b26d15 100644
--- a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
+++ b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
@@ -209,13 +209,9 @@ raw_ostream &operator<<(raw_ostream &OS, const RootElement &Element) {
void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements) {
OS << " RootElements{";
- bool First = true;
- for (const RootElement &Element : Elements) {
- if (!First)
- OS << ",";
- OS << " " << Element;
- First = false;
- }
+ ListSeparator LS;
+ for (const RootElement &Element : Elements)
+ OS << LS << Element;
OS << "}";
}
diff --git a/llvm/lib/MC/MCInstPrinter.cpp b/llvm/lib/MC/MCInstPrinter.cpp
index ac8f84270ee74..ba24dc96fa7f4 100644
--- a/llvm/lib/MC/MCInstPrinter.cpp
+++ b/llvm/lib/MC/MCInstPrinter.cpp
@@ -8,6 +8,7 @@
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCInst.h"
@@ -24,15 +25,9 @@ using namespace llvm;
void llvm::dumpBytes(ArrayRef<uint8_t> bytes, raw_ostream &OS) {
static const char hex_rep[] = "0123456789abcdef";
- bool First = true;
- for (char i: bytes) {
- if (First)
- First = false;
- else
- OS << ' ';
- OS << hex_rep[(i & 0xF0) >> 4];
- OS << hex_rep[i & 0xF];
- }
+ ListSeparator LS(" ");
+ for (char i : bytes)
+ OS << LS << hex_rep[(i & 0xF0) >> 4] << hex_rep[i & 0xF];
}
MCInstPrinter::~MCInstPrinter() = default;
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index 74daaae8a9952..fc88cc715f076 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -3237,13 +3237,9 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::ContextNode::print(
<< ")\n";
if (!Clones.empty()) {
OS << "\tClones: ";
- bool First = true;
- for (auto *C : Clones) {
- if (!First)
- OS << ", ";
- First = false;
- OS << C << " NodeId: " << C->NodeId;
- }
+ ListSeparator LS;
+ for (auto *C : Clones)
+ OS << LS << C << " NodeId: " << C->NodeId;
OS << "\n";
} else if (CloneOf) {
OS << "\tClone of " << CloneOf << " NodeId: " << CloneOf->NodeId << "\n";
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index e12caa2136962..a89ea2df0ef9c 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -757,39 +757,32 @@ bool Formula::hasRegsUsedByUsesOtherThan(size_t LUIdx,
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void Formula::print(raw_ostream &OS) const {
- bool First = true;
+ ListSeparator Plus(" + ");
if (BaseGV) {
- if (!First) OS << " + "; else First = false;
+ OS << Plus;
BaseGV->printAsOperand(OS, /*PrintType=*/false);
}
- if (BaseOffset.isNonZero()) {
- if (!First) OS << " + "; else First = false;
- OS << BaseOffset;
- }
- for (const SCEV *BaseReg : BaseRegs) {
- if (!First) OS << " + "; else First = false;
- OS << "reg(" << *BaseReg << ')';
- }
- if (HasBaseReg && BaseRegs.empty()) {
- if (!First) OS << " + "; else First = false;
- OS << "**error: HasBaseReg**";
- } else if (!HasBaseReg && !BaseRegs.empty()) {
- if (!First) OS << " + "; else First = false;
- OS << "**error: !HasBaseReg**";
- }
+ if (BaseOffset.isNonZero())
+ OS << Plus << BaseOffset;
+
+ for (const SCEV *BaseReg : BaseRegs)
+ OS << Plus << "reg(" << *BaseReg << ')';
+
+ if (HasBaseReg && BaseRegs.empty())
+ OS << Plus << "**error: HasBaseReg**";
+ else if (!HasBaseReg && !BaseRegs.empty())
+ OS << Plus << "**error: !HasBaseReg**";
+
if (Scale != 0) {
- if (!First) OS << " + "; else First = false;
- OS << Scale << "*reg(";
+ OS << Plus << Scale << "*reg(";
if (ScaledReg)
OS << *ScaledReg;
else
OS << "<unknown>";
OS << ')';
}
- if (UnfoldedOffset.isNonZero()) {
- if (!First) OS << " + ";
- OS << "imm(" << UnfoldedOffset << ')';
- }
+ if (UnfoldedOffset.isNonZero())
+ OS << Plus << "imm(" << UnfoldedOffset << ')';
}
LLVM_DUMP_METHOD void Formula::dump() const {
@@ -6277,19 +6270,13 @@ void LSRInstance::print_factors_and_types(raw_ostream &OS) const {
if (Factors.empty() && Types.empty()) return;
OS << "LSR has identified the following interesting factors and types: ";
- bool First = true;
+ ListSeparator LS;
- for (int64_t Factor : Factors) {
- if (!First) OS << ", ";
- First = false;
- OS << '*' << Factor;
- }
+ for (int64_t Factor : Factors)
+ OS << LS << '*' << Factor;
- for (Type *Ty : Types) {
- if (!First) OS << ", ";
- First = false;
- OS << '(' << *Ty << ')';
- }
+ for (Type *Ty : Types)
+ OS << LS << '(' << *Ty << ')';
OS << '\n';
}
diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp
index 5300c5c83e5ce..eb2b9409481c6 100644
--- a/llvm/tools/llvm-config/llvm-config.cpp
+++ b/llvm/tools/llvm-config/llvm-config.cpp
@@ -520,13 +520,11 @@ int main(int argc, char **argv) {
// Render include paths and associated flags
auto RenderFlags = [&](StringRef Flags) {
- bool First = true;
+ ListSeparator LS(" ");
for (auto &Include : ActiveIncludeOptions) {
- if (!First)
- OS << ' ';
+ OS << LS;
std::string FlagsStr = "-I" + Include;
MaybePrintQuoted(FlagsStr);
- First = false;
}
OS << ' ' << Flags << '\n';
};
diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp
index f3bf9690d2a6e..6d67a46cdb490 100644
--- a/llvm/tools/llvm-exegesis/lib/Analysis.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp
@@ -244,12 +244,10 @@ static void writeParallelSnippetHtml(raw_ostream &OS,
static void writeLatencySnippetHtml(raw_ostream &OS,
const std::vector<MCInst> &Instructions,
const MCInstrInfo &InstrInfo) {
+ ListSeparator LS(" → ");
bool First = true;
for (const MCInst &Instr : Instructions) {
- if (First)
- First = false;
- else
- OS << " → ";
+ OS << LS;
writeEscaped<kEscapeHtml>(OS, InstrInfo.getName(Instr.getOpcode()));
}
}
diff --git a/llvm/tools/llvm-remarkutil/RemarkSummary.cpp b/llvm/tools/llvm-remarkutil/RemarkSummary.cpp
index 124bd51720d17..73d7f4e3ed7de 100644
--- a/llvm/tools/llvm-remarkutil/RemarkSummary.cpp
+++ b/llvm/tools/llvm-remarkutil/RemarkSummary.cpp
@@ -163,13 +163,9 @@ class InlineCalleeSummary : public SummaryStrategy {
RB << "Incoming Calls (";
SmallVector<StringRef> StatKeys(V.Stats.keys());
llvm::sort(StatKeys);
- bool First = true;
- for (StringRef StatK : StatKeys) {
- if (!First)
- RB << ", ";
- RB << StatK << ": " << NV(StatK, V.Stats[StatK]);
- First = false;
- }
+ ListSeparator LS;
+ for (StringRef StatK : StatKeys)
+ RB << LS << StatK << ": " << NV(StatK, V.Stats[StatK]);
RB << ")";
if (V.LeastProfit && V.MostProfit != V.LeastProfit) {
RB << "\nLeast profitable (cost="
diff --git a/llvm/utils/TableGen/Common/PredicateExpander.cpp b/llvm/utils/TableGen/Common/PredicateExpander.cpp
index 03252ed465b75..c6d73f9c6721b 100644
--- a/llvm/utils/TableGen/Common/PredicateExpander.cpp
+++ b/llvm/utils/TableGen/Common/PredicateExpander.cpp
@@ -177,18 +177,15 @@ void PredicateExpander::expandPredicateSequence(
return expandPredicate(OS, Sequence[0]);
// Okay, there is more than one predicate in the set.
- bool First = true;
+ ListSeparator LS(IsCheckAll ? "&& " : "|| ");
OS << (shouldNegate() ? "!(" : "(");
++Indent;
bool OldValue = shouldNegate();
setNegatePredicate(false);
for (const Record *Rec : Sequence) {
- OS << '\n' << Indent;
- if (!First)
- OS << (IsCheckAll ? "&& " : "|| ");
+ OS << '\n' << Indent << LS;
expandPredicate(OS, Rec);
- First = false;
}
--Indent;
OS << '\n' << Indent << ')';
More information about the llvm-commits
mailing list