Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llvm/include/llvm/ADT/StringExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,15 @@ inline std::string join_items(Sep Separator, Args &&... Items) {
class ListSeparator {
bool First = true;
StringRef Separator;
StringRef Prefix;

public:
ListSeparator(StringRef Separator = ", ") : Separator(Separator) {}
ListSeparator(StringRef Separator = ", ", StringRef Prefix = "")
: Separator(Separator), Prefix(Prefix) {}
operator StringRef() {
if (First) {
First = false;
return {};
return Prefix;
}
return Separator;
}
Expand Down
30 changes: 14 additions & 16 deletions llvm/lib/CodeGen/MIRPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,48 +866,46 @@ static void printMI(raw_ostream &OS, MFPrintState &State,

OS << TII->getName(MI.getOpcode());

LS = ListSeparator();
// Print a space after the opcode if any additional tokens are printed.
LS = ListSeparator(", ", " ");

if (I < E) {
OS << ' ';
for (; I < E; ++I) {
OS << LS;
printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
PrintedTypes, MRI, /*PrintDef=*/true);
}
for (; I < E; ++I) {
OS << LS;
printMIOperand(OS, State, MI, I, TRI, TII, ShouldPrintRegisterTies,
PrintedTypes, MRI, /*PrintDef=*/true);
}

// Print any optional symbols attached to this instruction as-if they were
// operands.
if (MCSymbol *PreInstrSymbol = MI.getPreInstrSymbol()) {
OS << LS << " pre-instr-symbol ";
OS << LS << "pre-instr-symbol ";
MachineOperand::printSymbol(OS, *PreInstrSymbol);
}
if (MCSymbol *PostInstrSymbol = MI.getPostInstrSymbol()) {
OS << LS << " post-instr-symbol ";
OS << LS << "post-instr-symbol ";
MachineOperand::printSymbol(OS, *PostInstrSymbol);
}
if (MDNode *HeapAllocMarker = MI.getHeapAllocMarker()) {
OS << LS << " heap-alloc-marker ";
OS << LS << "heap-alloc-marker ";
HeapAllocMarker->printAsOperand(OS, State.MST);
}
if (MDNode *PCSections = MI.getPCSections()) {
OS << LS << " pcsections ";
OS << LS << "pcsections ";
PCSections->printAsOperand(OS, State.MST);
}
if (MDNode *MMRA = MI.getMMRAMetadata()) {
OS << LS << " mmra ";
OS << LS << "mmra ";
MMRA->printAsOperand(OS, State.MST);
}
if (uint32_t CFIType = MI.getCFIType())
OS << LS << " cfi-type " << CFIType;
OS << LS << "cfi-type " << CFIType;

if (auto Num = MI.peekDebugInstrNum())
OS << LS << " debug-instr-number " << Num;
OS << LS << "debug-instr-number " << Num;

if (PrintLocations) {
if (const DebugLoc &DL = MI.getDebugLoc()) {
OS << LS << " debug-location ";
OS << LS << "debug-location ";
DL->printAsOperand(OS, State.MST);
}
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/MIR/AArch64/return-address-signing.mir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RUN: llc -mtriple=aarch64 -run-pass=prologepilog -run-pass=aarch64-ptrauth -o - %s 2>&1 | FileCheck %s
# RUN: llc -mtriple=aarch64 -run-pass=prologepilog -run-pass=aarch64-ptrauth -o - %s 2>&1 | FileCheck --strict-whitespace %s
--- |
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64"
Expand Down
6 changes: 6 additions & 0 deletions llvm/unittests/ADT/StringExtrasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ TEST(StringExtrasTest, ListSeparator) {
EXPECT_EQ(S, "");
S = LS2;
EXPECT_EQ(S, " ");

ListSeparator LS3(",", "{");
S = LS3;
EXPECT_EQ(S, "{");
S = LS3;
EXPECT_EQ(S, ",");
}

TEST(StringExtrasTest, toStringAPInt) {
Expand Down