[llvm] r272207 - [RegisterBankInfo] Add dump/print methods for OperandsMapper.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 8 14:55:23 PDT 2016


Author: qcolombet
Date: Wed Jun  8 16:55:23 2016
New Revision: 272207

URL: http://llvm.org/viewvc/llvm-project?rev=272207&view=rev
Log:
[RegisterBankInfo] Add dump/print methods for OperandsMapper.

Improve debuggability of the OperandsMapper helper class.

Modified:
    llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
    llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp

Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h?rev=272207&r1=272206&r2=272207&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h Wed Jun  8 16:55:23 2016
@@ -262,10 +262,19 @@ public:
     /// called.
     /// The iterator may be invalidated by a call to setVRegs or createVRegs.
     ///
+    /// When \p ForDebug is true, we will not check that the list of new virtual
+    /// registers does not contain uninitialized values.
+    ///
     /// \pre getMI().getOperand(OpIdx).isReg()
-    /// \pre All partial mappings have been set a register
+    /// \pre ForDebug || All partial mappings have been set a register
     iterator_range<SmallVectorImpl<unsigned>::const_iterator>
-    getVRegs(unsigned OpIdx) const;
+    getVRegs(unsigned OpIdx, bool ForDebug = false) const;
+
+    /// Print this operands mapper on dbgs() stream.
+    void dump() const;
+
+    /// Print this operands mapper on \p OS stream.
+    void print(raw_ostream &OS, bool ForDebug = false) const;
   };
 
 protected:
@@ -574,6 +583,12 @@ operator<<(raw_ostream &OS,
   InstrMapping.print(OS);
   return OS;
 }
+
+inline raw_ostream &
+operator<<(raw_ostream &OS, const RegisterBankInfo::OperandsMapper &OpdMapper) {
+  OpdMapper.print(OS, /*ForDebug*/ false);
+  return OS;
+}
 } // End namespace llvm.
 
 #endif

Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp?rev=272207&r1=272206&r2=272207&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegisterBankInfo.cpp Wed Jun  8 16:55:23 2016
@@ -576,7 +576,9 @@ void RegisterBankInfo::OperandsMapper::s
 }
 
 iterator_range<SmallVectorImpl<unsigned>::const_iterator>
-RegisterBankInfo::OperandsMapper::getVRegs(unsigned OpIdx) const {
+RegisterBankInfo::OperandsMapper::getVRegs(unsigned OpIdx,
+                                           bool ForDebug) const {
+  (void)ForDebug;
   assert(OpIdx < getMI().getNumOperands() && "Out-of-bound access");
   int StartIdx = OpToNewVRegIdx[OpIdx];
 
@@ -593,7 +595,58 @@ RegisterBankInfo::OperandsMapper::getVRe
       make_range(&NewVRegs[StartIdx], End);
 #ifndef NDEBUG
   for (unsigned VReg : Res)
-    assert(VReg && "Some registers are uninitialized");
+    assert((VReg || ForDebug) && "Some registers are uninitialized");
 #endif
   return Res;
 }
+
+void RegisterBankInfo::OperandsMapper::dump() const {
+  print(dbgs(), true);
+  dbgs() << '\n';
+}
+
+void RegisterBankInfo::OperandsMapper::print(raw_ostream &OS,
+                                             bool ForDebug) const {
+  unsigned NumOpds = getMI().getNumOperands();
+  if (ForDebug) {
+    OS << "Mapping for " << getMI() << "\nwith " << getInstrMapping() << '\n';
+    // Print out the internal state of the index table.
+    OS << "Populated indices (CellNumber, IndexInNewVRegs): ";
+    bool IsFirst = true;
+    for (unsigned Idx = 0; Idx != NumOpds; ++Idx) {
+      if (OpToNewVRegIdx[Idx] != DontKnowIdx) {
+        if (!IsFirst)
+          OS << ", ";
+        OS << '(' << Idx << ", " << OpToNewVRegIdx[Idx] << ')';
+        IsFirst = false;
+      }
+    }
+    OS << '\n';
+  } else
+    OS << "Mapping ID: " << getInstrMapping().getID() << ' ';
+
+  OS << "Operand Mapping: ";
+  // If we have a function, we can pretty print the name of the registers.
+  // Otherwise we will print the raw numbers.
+  const TargetRegisterInfo *TRI =
+      getMI().getParent() && getMI().getParent()->getParent()
+          ? getMI().getParent()->getParent()->getSubtarget().getRegisterInfo()
+          : nullptr;
+  bool IsFirst = true;
+  for (unsigned Idx = 0; Idx != NumOpds; ++Idx) {
+    if (OpToNewVRegIdx[Idx] == DontKnowIdx)
+      continue;
+    if (!IsFirst)
+      OS << ", ";
+    IsFirst = false;
+    OS << '(' << PrintReg(getMI().getOperand(Idx).getReg(), TRI) << ", [";
+    bool IsFirstNewVReg = true;
+    for (unsigned VReg : getVRegs(Idx)) {
+      if (!IsFirstNewVReg)
+        OS << ", ";
+      IsFirstNewVReg = false;
+      OS << PrintReg(VReg, TRI);
+    }
+    OS << "])";
+  }
+}




More information about the llvm-commits mailing list