diff --git a/llvm/include/llvm/CodeGen/LiveInterval.h b/llvm/include/llvm/CodeGen/LiveInterval.h --- a/llvm/include/llvm/CodeGen/LiveInterval.h +++ b/llvm/include/llvm/CodeGen/LiveInterval.h @@ -81,6 +81,8 @@ /// Mark this value as unused. void markUnused() { def = SlotIndex(); } + + void print(raw_ostream &OS) const; }; /// Result of a LiveRange query. This class hides the implementation details diff --git a/llvm/lib/CodeGen/LiveInterval.cpp b/llvm/lib/CodeGen/LiveInterval.cpp --- a/llvm/lib/CodeGen/LiveInterval.cpp +++ b/llvm/lib/CodeGen/LiveInterval.cpp @@ -1025,18 +1025,22 @@ ++i, ++vnum) { const VNInfo *vni = *i; if (vnum) OS << ' '; - OS << vnum << '@'; - if (vni->isUnused()) { - OS << 'x'; - } else { - OS << vni->def; - if (vni->isPHIDef()) - OS << "-phi"; - } + vni->print(OS); } } } +void VNInfo::print(raw_ostream &OS) const { + OS << id << '@'; + if (isUnused()) { + OS << 'x'; + } else { + OS << def; + if (isPHIDef()) + OS << "-phi"; + } +} + void LiveInterval::SubRange::print(raw_ostream &OS) const { OS << " L" << PrintLaneMask(LaneMask) << ' ' << static_cast(*this); diff --git a/llvm/lib/CodeGen/RegisterCoalescer.cpp b/llvm/lib/CodeGen/RegisterCoalescer.cpp --- a/llvm/lib/CodeGen/RegisterCoalescer.cpp +++ b/llvm/lib/CodeGen/RegisterCoalescer.cpp @@ -2326,6 +2326,26 @@ Val() = default; bool isAnalyzed() const { return WriteLanes.any(); } + + void print(raw_ostream &O) const { + O << " Write:" << PrintLaneMask(WriteLanes) + << " Valid:" << PrintLaneMask(ValidLanes) << ' '; + switch(Resolution) { + case CR_Unresolved: O << "Unresolved"; return; + case CR_Impossible: O << "Impossible"; return; + case CR_Keep: O << "Keep"; break; + case CR_Replace: O << "Replace"; break; + case CR_Merge: O << "Merge"; break; + case CR_Erase: O << "Erase"; + if (Identical) O << " Identical"; + break; + } + if (OtherVNI) O << " Other:", OtherVNI->print(O); + if (RedefVNI) O << " Redef:", RedefVNI->print(O); + if (ErasableImplicitDef) O << " ImpDef"; + if (Pruned || PrunedComputed) O << ' ' << (Pruned ? "Pruned" : "NonPruned"); + if (PrunedComputed) O << 'C'; + } }; /// One entry per value number in LI. @@ -2442,6 +2462,30 @@ ConflictResolution getResolution(unsigned Num) const { return Vals[Num].Resolution; } + + void print(raw_ostream &O) const { + O << printReg(Register(Reg), TRI, SubIdx); + if (SubRangeJoin) O << ':' << PrintLaneMask(LaneMask); + O << ":\n"; + std::string FormBuff; + for (unsigned ValNo = 0, E = Vals.size(); ValNo < E; ++ValNo) { + auto *VNI = LR.getValNumInfo(ValNo); + raw_string_ostream SS(FormBuff); + VNI->print(SS); + O << "\t\t" << right_justify(SS.str(), 20); + FormBuff.clear(); + Vals[ValNo].print(O); + if (Assignments[ValNo] != -1) { + O << " -> "; + NewVNInfo[Assignments[ValNo]]->print(O); + } + O << '\n'; + } + } + + LLVM_DUMP_METHOD void dump() const { + print(dbgs()); + } }; } // end anonymous namespace @@ -3291,6 +3335,12 @@ llvm_unreachable("*** Couldn't join subrange!\n"); } + LLVM_DEBUG( + dbgs() << "\t\tRHSVals "; RHSVals.dump(); + dbgs() << "\n\t\tLHSVals "; LHSVals.dump(); + dbgs() << '\n' + ); + // The merging algorithm in LiveInterval::join() can't handle conflicting // value mappings, so we need to remove any live ranges that overlap a // CR_Replace resolution. Collect a set of end points that can be used to @@ -3383,6 +3433,12 @@ if (!LHSVals.resolveConflicts(RHSVals) || !RHSVals.resolveConflicts(LHSVals)) return false; + LLVM_DEBUG( + dbgs() << "\t\tRHSVals "; RHSVals.dump(); + dbgs() << "\n\t\tLHSVals "; LHSVals.dump(); + dbgs() << '\n' + ); + // All clear, the live ranges can be merged. if (RHS.hasSubRanges() || LHS.hasSubRanges()) { BumpPtrAllocator &Allocator = LIS->getVNInfoAllocator();