Skip to content

Commit 727b6c0

Browse files
committed
[sil-printer] Refactor out printing of silvalue use lists into its own function and do some small cleanups. NFC.
1 parent 7778955 commit 727b6c0

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

lib/SIL/SILPrinter.cpp

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,36 @@ class SILPrinter : public SILVisitor<SILPrinter> {
519519
//===--------------------------------------------------------------------===//
520520
// SILInstruction Printing Logic
521521

522+
/// Print out the users of the SILValue \p V. Return true if we printed out
523+
/// either an id or a use list. Return false otherwise.
524+
bool printUsersOfSILValue(SILValue V) {
525+
if (!V->hasValue()) {
526+
PrintState.OS.PadToColumn(50);
527+
*this << "// id: " << getID(V);
528+
return true;
529+
}
530+
531+
if (V->use_empty())
532+
return false;
533+
534+
PrintState.OS.PadToColumn(50);
535+
*this << "// user";
536+
if (std::next(V->use_begin()) != V->use_end())
537+
*this << 's';
538+
*this << ": ";
539+
540+
// Display the user ids sorted to give a stable use order in the printer's
541+
// output. This makes diffing large sections of SIL significantly easier.
542+
llvm::SmallVector<ID, 32> UserIDs;
543+
for (auto *Op : V->getUses())
544+
UserIDs.push_back(getID(Op->getUser()));
545+
std::sort(UserIDs.begin(), UserIDs.end());
546+
547+
interleave(UserIDs.begin(), UserIDs.end(), [&](ID id) { *this << id; },
548+
[&] { *this << ", "; });
549+
return true;
550+
}
551+
522552
void print(SILValue V) {
523553
if (auto *FRI = dyn_cast<FunctionRefInst>(V))
524554
*this << " // function_ref "
@@ -537,32 +567,9 @@ class SILPrinter : public SILVisitor<SILPrinter> {
537567
// Print the value.
538568
visit(V);
539569

540-
// Print users, or id for valueless instructions.
541-
bool printedSlashes = false;
542-
543-
if (!V->hasValue()) {
544-
PrintState.OS.PadToColumn(50);
545-
*this << "// id: " << getID(V);
546-
printedSlashes = true;
547-
} else if (!V->use_empty()) {
548-
PrintState.OS.PadToColumn(50);
549-
*this << "// user";
550-
if (std::next(V->use_begin()) != V->use_end())
551-
*this << 's';
552-
*this << ": ";
553-
554-
// Display the user ids sorted to give a stable use order in the printer's
555-
// output. This makes diffing large sections of SIL significantly easier.
556-
llvm::SmallVector<ID, 32> UserIDs;
557-
for (auto *Op : V->getUses())
558-
UserIDs.push_back(getID(Op->getUser()));
559-
std::sort(UserIDs.begin(), UserIDs.end());
560-
561-
interleave(UserIDs.begin(), UserIDs.end(),
562-
[&] (ID id) { *this << id; },
563-
[&] { *this << ", "; });
564-
printedSlashes = true;
565-
}
570+
// Print users, or id for valueless instructions. Return true if we emitted
571+
// any output.
572+
bool printedSlashes = printUsersOfSILValue(V);
566573

567574
// Print SIL location.
568575
if (Verbose) {

0 commit comments

Comments
 (0)