]> granicus.if.org Git - llvm/commitdiff
[CodeGen] Print live-out register lists as liveout(...) in both MIR and debug output
authorFrancis Visoiu Mistrih <francisvm@yahoo.com>
Thu, 14 Dec 2017 10:03:14 +0000 (10:03 +0000)
committerFrancis Visoiu Mistrih <francisvm@yahoo.com>
Thu, 14 Dec 2017 10:03:14 +0000 (10:03 +0000)
Work towards the unification of MIR and debug output by printing
`liveout(...)` instead of `<regliveout>`.

Only debug syntax is affected.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320683 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MIRPrinter.cpp
lib/CodeGen/MachineOperand.cpp
unittests/CodeGen/MachineOperandTest.cpp

index f625be36a814068214482f7b29ce035c7d1496a4..fcf59adb7b39b4baebdc129109cda2bb8997af63 100644 (file)
@@ -797,7 +797,8 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
   case MachineOperand::MO_TargetIndex:
   case MachineOperand::MO_JumpTableIndex:
   case MachineOperand::MO_ExternalSymbol:
-  case MachineOperand::MO_GlobalAddress: {
+  case MachineOperand::MO_GlobalAddress:
+  case MachineOperand::MO_RegisterLiveOut: {
     unsigned TiedOperandIdx = 0;
     if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef())
       TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx);
@@ -829,21 +830,6 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx,
       printCustomRegMask(Op.getRegMask(), OS, TRI);
     break;
   }
-  case MachineOperand::MO_RegisterLiveOut: {
-    const uint32_t *RegMask = Op.getRegLiveOut();
-    OS << "liveout(";
-    bool IsCommaNeeded = false;
-    for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
-      if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
-        if (IsCommaNeeded)
-          OS << ", ";
-        OS << printReg(Reg, TRI);
-        IsCommaNeeded = true;
-      }
-    }
-    OS << ")";
-    break;
-  }
   case MachineOperand::MO_Metadata:
     Op.getMetadata()->printAsOperand(OS, MST);
     break;
index 7ffdbea08c11b5a4ed7e39f154f761d5c772d8b9..009722b981aae8261c4b5e1df1db1c25e5059681 100644 (file)
@@ -637,9 +637,25 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST,
     OS << ">";
     break;
   }
-  case MachineOperand::MO_RegisterLiveOut:
-    OS << "<regliveout>";
+  case MachineOperand::MO_RegisterLiveOut: {
+    const uint32_t *RegMask = getRegLiveOut();
+    OS << "liveout(";
+    if (!TRI) {
+      OS << "<unknown>";
+    } else {
+      bool IsCommaNeeded = false;
+      for (unsigned Reg = 0, E = TRI->getNumRegs(); Reg < E; ++Reg) {
+        if (RegMask[Reg / 32] & (1U << (Reg % 32))) {
+          if (IsCommaNeeded)
+            OS << ", ";
+          OS << printReg(Reg, TRI);
+          IsCommaNeeded = true;
+        }
+      }
+    }
+    OS << ")";
     break;
+  }
   case MachineOperand::MO_Metadata:
     OS << '<';
     getMetadata()->printAsOperand(OS, MST);
index 96498e681ed083192c52cee2de78faf539bc1764..5c13ddc4b8c645d89cf37842bec7b6f33e015ca7 100644 (file)
@@ -272,4 +272,21 @@ TEST(MachineOperandTest, PrintGlobalAddress) {
   }
 }
 
+TEST(MachineOperandTest, PrintRegisterLiveOut) {
+  // Create a MachineOperand with a register live out list and print it.
+  uint32_t Mask = 0;
+  MachineOperand MO = MachineOperand::CreateRegLiveOut(&Mask);
+
+  // Checking some preconditions on the newly created
+  // MachineOperand.
+  ASSERT_TRUE(MO.isRegLiveOut());
+  ASSERT_TRUE(MO.getRegLiveOut() == &Mask);
+
+  std::string str;
+  // Print a MachineOperand containing a register live out list without a TRI.
+  raw_string_ostream OS(str);
+  MO.print(OS, /*TRI=*/nullptr, /*IntrinsicInfo=*/nullptr);
+  ASSERT_TRUE(OS.str() == "liveout(<unknown>)");
+}
+
 } // end namespace