Browse Source

[CodeGen] Unify printing format of debug-location in both MIR and -debug

Use "debug-location" instead of "; dbg:" in MI::print.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322936 91177308-0d34-0410-b5e6-96231b3b80d8
Francis Visoiu Mistrih 7 years ago
parent
commit
e97eca6f69

+ 2 - 2
lib/CodeGen/MIRPrinter.cpp

@@ -686,11 +686,11 @@ void MIPrinter::print(const MachineInstr &MI) {
     NeedComma = true;
     NeedComma = true;
   }
   }
 
 
-  if (MI.getDebugLoc()) {
+  if (const DebugLoc &DL = MI.getDebugLoc()) {
     if (NeedComma)
     if (NeedComma)
       OS << ',';
       OS << ',';
     OS << " debug-location ";
     OS << " debug-location ";
-    MI.getDebugLoc()->printAsOperand(OS, MST);
+    DL->printAsOperand(OS, MST);
   }
   }
 
 
   if (!MI.memoperands_empty()) {
   if (!MI.memoperands_empty()) {

+ 12 - 7
lib/CodeGen/MachineInstr.cpp

@@ -1425,6 +1425,15 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST,
     }
     }
   }
   }
 
 
+  if (!SkipDebugLoc) {
+    if (const DebugLoc &DL = getDebugLoc()) {
+      if (!FirstOp)
+        OS << ',';
+      OS << " debug-location ";
+      DL->printAsOperand(OS, MST);
+    }
+  }
+
   bool HaveSemi = false;
   bool HaveSemi = false;
   if (!memoperands_empty()) {
   if (!memoperands_empty()) {
     if (!HaveSemi) {
     if (!HaveSemi) {
@@ -1441,6 +1450,9 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST,
     }
     }
   }
   }
 
 
+  if (SkipDebugLoc)
+    return;
+
   // Print debug location information.
   // Print debug location information.
   if (isDebugValue() && getOperand(e - 2).isMetadata()) {
   if (isDebugValue() && getOperand(e - 2).isMetadata()) {
     if (!HaveSemi)
     if (!HaveSemi)
@@ -1457,13 +1469,6 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST,
     }
     }
     if (isIndirectDebugValue())
     if (isIndirectDebugValue())
       OS << " indirect";
       OS << " indirect";
-  } else if (SkipDebugLoc) {
-    return;
-  } else if (debugLoc && MF) {
-    if (!HaveSemi)
-      OS << ";";
-    OS << " dbg:";
-    debugLoc.print(OS);
   }
   }
 
 
   OS << '\n';
   OS << '\n';

+ 23 - 0
unittests/CodeGen/MachineInstrTest.cpp

@@ -14,6 +14,8 @@
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetInstrInfo.h"
 #include "llvm/CodeGen/TargetLowering.h"
 #include "llvm/CodeGen/TargetLowering.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/ModuleSlotTracker.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetMachine.h"
@@ -244,4 +246,25 @@ TEST(MachineInstrExpressionTraitTest, IsEqualAgreesWithGetHashValue) {
 
 
   checkHashAndIsEqualMatch(VD2PU, VD2PD);
   checkHashAndIsEqualMatch(VD2PU, VD2PD);
 }
 }
+
+TEST(MachineInstrPrintingTest, DebugLocPrinting) {
+  auto MF = createMachineFunction();
+
+  MCOperandInfo OpInfo{0, 0, MCOI::OPERAND_REGISTER, 0};
+  MCInstrDesc MCID = {0, 1,       1,       0,       0, 0,
+                      0, nullptr, nullptr, &OpInfo, 0, nullptr};
+
+  LLVMContext Ctx;
+  DILocation *DIL = DILocation::get(Ctx, 1, 5, (Metadata *)nullptr, nullptr);
+  DebugLoc DL(DIL);
+  MachineInstr *MI = MF->CreateMachineInstr(MCID, DL);
+  MI->addOperand(*MF, MachineOperand::CreateReg(0, /*isDef*/ true));
+
+  std::string str;
+  raw_string_ostream OS(str);
+  MI->print(OS);
+  ASSERT_TRUE(
+      StringRef(OS.str()).startswith("%noreg = UNKNOWN debug-location "));
+}
+
 } // end namespace
 } // end namespace