diff options
-rw-r--r-- | llvm/lib/CodeGen/MIRPrinter.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineInstr.cpp | 19 | ||||
-rw-r--r-- | llvm/unittests/CodeGen/MachineInstrTest.cpp | 23 |
3 files changed, 37 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index 569d51aa28d..09316175a78 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -686,11 +686,11 @@ void MIPrinter::print(const MachineInstr &MI) { NeedComma = true; } - if (MI.getDebugLoc()) { + if (const DebugLoc &DL = MI.getDebugLoc()) { if (NeedComma) OS << ','; OS << " debug-location "; - MI.getDebugLoc()->printAsOperand(OS, MST); + DL->printAsOperand(OS, MST); } if (!MI.memoperands_empty()) { diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index 1b3fabad897..32785dee0cb 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/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; if (!memoperands_empty()) { if (!HaveSemi) { @@ -1441,6 +1450,9 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, } } + if (SkipDebugLoc) + return; + // Print debug location information. if (isDebugValue() && getOperand(e - 2).isMetadata()) { if (!HaveSemi) @@ -1457,13 +1469,6 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, } if (isIndirectDebugValue()) OS << " indirect"; - } else if (SkipDebugLoc) { - return; - } else if (debugLoc && MF) { - if (!HaveSemi) - OS << ";"; - OS << " dbg:"; - debugLoc.print(OS); } OS << '\n'; diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp index aca640ebcf3..b1aa16e52a7 100644 --- a/llvm/unittests/CodeGen/MachineInstrTest.cpp +++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp @@ -14,6 +14,8 @@ #include "llvm/CodeGen/TargetInstrInfo.h" #include "llvm/CodeGen/TargetLowering.h" #include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/ModuleSlotTracker.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Target/TargetMachine.h" @@ -244,4 +246,25 @@ TEST(MachineInstrExpressionTraitTest, IsEqualAgreesWithGetHashValue) { 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 |