[PATCH] D45992: [CodeGen] Print user-friendly debug locations as MI comments

Francis Visoiu Mistrih via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 24 04:04:28 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL330709: [CodeGen] Print user-friendly debug locations as MI comments (authored by thegameg, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45992?vs=143656&id=143708#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D45992

Files:
  llvm/trunk/lib/CodeGen/MachineInstr.cpp
  llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp


Index: llvm/trunk/lib/CodeGen/MachineInstr.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp
@@ -1469,10 +1469,23 @@
     return;
 
   bool HaveSemi = false;
+
   // Print debug location information.
+  if (const DebugLoc &DL = getDebugLoc()) {
+    if (!HaveSemi) {
+      OS << ';';
+      HaveSemi = true;
+    }
+    OS << ' ';
+    DL.print(OS);
+  }
+
+  // Print extra comments for DEBUG_VALUE.
   if (isDebugValue() && getOperand(e - 2).isMetadata()) {
-    if (!HaveSemi)
+    if (!HaveSemi) {
       OS << ";";
+      HaveSemi = true;
+    }
     auto *DV = cast<DILocalVariable>(getOperand(e - 2).getMetadata());
     OS << " line no:" <<  DV->getLine();
     if (auto *InlinedAt = debugLoc->getInlinedAt()) {
Index: llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp
===================================================================
--- llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp
+++ llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp
@@ -255,7 +255,11 @@
                       0, nullptr, nullptr, &OpInfo, 0, nullptr};
 
   LLVMContext Ctx;
-  DILocation *DIL = DILocation::get(Ctx, 1, 5, (Metadata *)nullptr, nullptr);
+  DIFile *DIF = DIFile::getDistinct(Ctx, "filename", "");
+  DISubprogram *DIS = DISubprogram::getDistinct(
+      Ctx, nullptr, "", "", DIF, 0, nullptr, false, false, 0, nullptr, 0, 0, 0,
+      DINode::FlagZero, false, nullptr);
+  DILocation *DIL = DILocation::get(Ctx, 1, 5, DIS);
   DebugLoc DL(DIL);
   MachineInstr *MI = MF->CreateMachineInstr(MCID, DL);
   MI->addOperand(*MF, MachineOperand::CreateReg(0, /*isDef*/ true));
@@ -265,6 +269,8 @@
   MI->print(OS);
   ASSERT_TRUE(
       StringRef(OS.str()).startswith("$noreg = UNKNOWN debug-location "));
+  ASSERT_TRUE(
+      StringRef(OS.str()).endswith("filename:1:5"));
 }
 
 } // end namespace


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45992.143708.patch
Type: text/x-patch
Size: 1910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180424/861b8428/attachment.bin>


More information about the llvm-commits mailing list