[CodeGen] Print user-friendly debug locations as MI comments
If available, print the file, line and column of the DebugLoc attached to the MachineInstr: MOV16mr $rbp, 1, $noreg, -112, $noreg, killed renamable $ax, debug-location !56 :: (store 2 into %ir.._value12); stepping.swift:10:17 renamable $edx = MOVZX32rm16 $rbp, 1, $noreg, -112, $noreg, debug-location !62 :: (dereferenceable load 2 from %ir.._value13); stepping.swift:10:17 Differential Revision: https://reviews.llvm.org/D45992 llvm-svn: 330709
This commit is contained in:
parent
fdfeefd6c2
commit
8ed0f741ae
|
@ -1469,10 +1469,23 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool HaveSemi = false;
|
bool HaveSemi = false;
|
||||||
|
|
||||||
// Print debug location information.
|
// 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 (isDebugValue() && getOperand(e - 2).isMetadata()) {
|
||||||
if (!HaveSemi)
|
if (!HaveSemi) {
|
||||||
OS << ";";
|
OS << ";";
|
||||||
|
HaveSemi = true;
|
||||||
|
}
|
||||||
auto *DV = cast<DILocalVariable>(getOperand(e - 2).getMetadata());
|
auto *DV = cast<DILocalVariable>(getOperand(e - 2).getMetadata());
|
||||||
OS << " line no:" << DV->getLine();
|
OS << " line no:" << DV->getLine();
|
||||||
if (auto *InlinedAt = debugLoc->getInlinedAt()) {
|
if (auto *InlinedAt = debugLoc->getInlinedAt()) {
|
||||||
|
|
|
@ -255,7 +255,11 @@ TEST(MachineInstrPrintingTest, DebugLocPrinting) {
|
||||||
0, nullptr, nullptr, &OpInfo, 0, nullptr};
|
0, nullptr, nullptr, &OpInfo, 0, nullptr};
|
||||||
|
|
||||||
LLVMContext Ctx;
|
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);
|
DebugLoc DL(DIL);
|
||||||
MachineInstr *MI = MF->CreateMachineInstr(MCID, DL);
|
MachineInstr *MI = MF->CreateMachineInstr(MCID, DL);
|
||||||
MI->addOperand(*MF, MachineOperand::CreateReg(0, /*isDef*/ true));
|
MI->addOperand(*MF, MachineOperand::CreateReg(0, /*isDef*/ true));
|
||||||
|
@ -265,6 +269,8 @@ TEST(MachineInstrPrintingTest, DebugLocPrinting) {
|
||||||
MI->print(OS);
|
MI->print(OS);
|
||||||
ASSERT_TRUE(
|
ASSERT_TRUE(
|
||||||
StringRef(OS.str()).startswith("$noreg = UNKNOWN debug-location "));
|
StringRef(OS.str()).startswith("$noreg = UNKNOWN debug-location "));
|
||||||
|
ASSERT_TRUE(
|
||||||
|
StringRef(OS.str()).endswith("filename:1:5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace
|
} // end namespace
|
||||||
|
|
Loading…
Reference in New Issue