Skip to content

Commit 353a1e5

Browse files
committed
[NFC] Improve debug output of StackColoring
1 parent 5a1a346 commit 353a1e5

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

llvm/lib/CodeGen/StackColoring.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ class StackColoring {
442442
void dump() const;
443443
void dumpIntervals() const;
444444
void dumpBB(MachineBasicBlock *MBB) const;
445-
void dumpBV(const char *tag, const BitVector &BV) const;
446445

447446
/// Removes all of the lifetime marker instructions from the function.
448447
/// \returns true if any markers were removed.
@@ -526,12 +525,39 @@ void StackColoringLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
526525
}
527526

528527
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
529-
LLVM_DUMP_METHOD void StackColoring::dumpBV(const char *tag,
530-
const BitVector &BV) const {
531-
dbgs() << tag << " : { ";
532-
for (unsigned I = 0, E = BV.size(); I != E; ++I)
533-
dbgs() << BV.test(I) << " ";
534-
dbgs() << "}\n";
528+
529+
LLVM_DUMP_METHOD void dumpBV(StringRef tag, const BitVector &BV) {
530+
constexpr unsigned ColumnWidth = 150;
531+
unsigned LineStartOffset = tag.size() + /*" : "*/ 3;
532+
unsigned WidthAfterTag = ColumnWidth - LineStartOffset;
533+
unsigned NumBitsPerColumn = WidthAfterTag / 2;
534+
unsigned BitsCount = BV.size();
535+
for (unsigned Bits = 0; Bits < BitsCount; Bits += NumBitsPerColumn) {
536+
unsigned Start = Bits;
537+
unsigned End = std::min(Start + NumBitsPerColumn, BitsCount);
538+
539+
dbgs() << tag << " : ";
540+
541+
for (unsigned I = Start; I < End; ++I)
542+
dbgs() << BV.test(I) << " ";
543+
dbgs() << '\n';
544+
dbgs() << tag << " : ";
545+
unsigned next = Start;
546+
for (unsigned I = Start; I < End; ++I) {
547+
if (I < next)
548+
continue;
549+
if (BV.test(I)) {
550+
int numDigits = NumDigits(I);
551+
// Make sure number have spacing while staying aligned to the line above
552+
next = I + 1 + numDigits / 2;
553+
dbgs() << I << ' ';
554+
if (numDigits % 2 == 0)
555+
dbgs() << ' ';
556+
} else
557+
dbgs() << " ";
558+
}
559+
dbgs() << '\n';
560+
}
535561
}
536562

537563
LLVM_DUMP_METHOD void StackColoring::dumpBB(MachineBasicBlock *MBB) const {
@@ -553,8 +579,14 @@ LLVM_DUMP_METHOD void StackColoring::dump() const {
553579

554580
LLVM_DUMP_METHOD void StackColoring::dumpIntervals() const {
555581
for (unsigned I = 0, E = Intervals.size(); I != E; ++I) {
556-
dbgs() << "Interval[" << I << "]:\n";
557-
Intervals[I]->dump();
582+
dbgs() << "Interval[" << I << "]:";
583+
if (MFI->getObjectAllocation(I))
584+
dbgs() << *MFI->getObjectAllocation(I);
585+
dbgs() << '\n' << *Intervals[I] << '\n';
586+
dbgs() << "LiveStarts:";
587+
for (SlotIndex SIdx : LiveStarts[I])
588+
dbgs() << ' ' << SIdx;
589+
dbgs() << '\n';
558590
}
559591
}
560592
#endif

0 commit comments

Comments
 (0)