Skip to content

Commit 611fdf7

Browse files
committed
[NFC] Improve BitVector dump
1 parent 3979f27 commit 611fdf7

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

llvm/lib/CodeGen/StackColoring.cpp

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "llvm/Support/raw_ostream.h"
5858
#include <algorithm>
5959
#include <cassert>
60+
#include <cmath>
6061
#include <limits>
6162
#include <memory>
6263
#include <utility>
@@ -442,7 +443,6 @@ class StackColoring {
442443
void dump() const;
443444
void dumpIntervals() const;
444445
void dumpBB(MachineBasicBlock *MBB) const;
445-
void dumpBV(const char *tag, const BitVector &BV) const;
446446

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

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

537564
LLVM_DUMP_METHOD void StackColoring::dumpBB(MachineBasicBlock *MBB) const {
@@ -553,8 +580,15 @@ LLVM_DUMP_METHOD void StackColoring::dump() const {
553580

554581
LLVM_DUMP_METHOD void StackColoring::dumpIntervals() const {
555582
for (unsigned I = 0, E = Intervals.size(); I != E; ++I) {
556-
dbgs() << "Interval[" << I << "]:\n";
583+
dbgs() << "Interval[" << I << "]:";
584+
if (MFI->getObjectAllocation(I))
585+
dbgs() << *MFI->getObjectAllocation(I);
586+
dbgs() << "\n";
557587
Intervals[I]->dump();
588+
dbgs() << "LiveStarts:";
589+
for (SlotIndex SIdx : LiveStarts[I])
590+
dbgs() << " " << SIdx;
591+
dbgs() << "\n";
558592
}
559593
}
560594
#endif

0 commit comments

Comments
 (0)