@@ -519,6 +519,36 @@ class SILPrinter : public SILVisitor<SILPrinter> {
519
519
// ===--------------------------------------------------------------------===//
520
520
// SILInstruction Printing Logic
521
521
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
+
522
552
void print (SILValue V) {
523
553
if (auto *FRI = dyn_cast<FunctionRefInst>(V))
524
554
*this << " // function_ref "
@@ -537,32 +567,9 @@ class SILPrinter : public SILVisitor<SILPrinter> {
537
567
// Print the value.
538
568
visit (V);
539
569
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);
566
573
567
574
// Print SIL location.
568
575
if (Verbose) {
0 commit comments