Skip to content

Commit d7858f0

Browse files
committed
[RegAlloc] Add printer and dump for VNInfo [nfc]
Uses the existing format of the LiveRange printer, and just factors it out so that you can do vni->dump() when debugging, or log a vni in a debug print statement.
1 parent ea721e2 commit d7858f0

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

llvm/include/llvm/CodeGen/LiveInterval.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,16 @@ namespace llvm {
8383

8484
/// Mark this value as unused.
8585
void markUnused() { def = SlotIndex(); }
86+
87+
LLVM_ABI void print(raw_ostream &OS) const;
88+
LLVM_ABI void dump() const;
8689
};
8790

91+
inline raw_ostream &operator<<(raw_ostream &OS, const VNInfo &VNI) {
92+
VNI.print(OS);
93+
return OS;
94+
}
95+
8896
/// Result of a LiveRange query. This class hides the implementation details
8997
/// of live ranges, and it should be used as the primary interface for
9098
/// examining live ranges around instructions.

llvm/lib/CodeGen/LiveInterval.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,17 @@ LLVM_DUMP_METHOD void LiveRange::Segment::dump() const {
996996
}
997997
#endif
998998

999+
void VNInfo::print(raw_ostream &OS) const {
1000+
OS << id << '@';
1001+
if (isUnused()) {
1002+
OS << 'x';
1003+
} else {
1004+
OS << def;
1005+
if (isPHIDef())
1006+
OS << "-phi";
1007+
}
1008+
}
1009+
9991010
void LiveRange::print(raw_ostream &OS) const {
10001011
if (empty())
10011012
OS << "EMPTY";
@@ -1014,14 +1025,8 @@ void LiveRange::print(raw_ostream &OS) const {
10141025
++i, ++vnum) {
10151026
const VNInfo *vni = *i;
10161027
if (vnum) OS << ' ';
1017-
OS << vnum << '@';
1018-
if (vni->isUnused()) {
1019-
OS << 'x';
1020-
} else {
1021-
OS << vni->def;
1022-
if (vni->isPHIDef())
1023-
OS << "-phi";
1024-
}
1028+
OS << *vni;
1029+
assert(vnum == vni->id && "Bad VNInfo");
10251030
}
10261031
}
10271032
}
@@ -1041,6 +1046,10 @@ void LiveInterval::print(raw_ostream &OS) const {
10411046
}
10421047

10431048
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1049+
LLVM_DUMP_METHOD void VNInfo::dump() const {
1050+
dbgs() << *this << '\n';
1051+
}
1052+
10441053
LLVM_DUMP_METHOD void LiveRange::dump() const {
10451054
dbgs() << *this << '\n';
10461055
}

0 commit comments

Comments
 (0)