[llvm] r322936 - [CodeGen] Unify printing format of debug-location in both MIR and -debug
Francis Visoiu Mistrih via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 19 03:44:42 PST 2018
Author: thegameg
Date: Fri Jan 19 03:44:42 2018
New Revision: 322936
URL: http://llvm.org/viewvc/llvm-project?rev=322936&view=rev
Log:
[CodeGen] Unify printing format of debug-location in both MIR and -debug
Use "debug-location" instead of "; dbg:" in MI::print.
Modified:
llvm/trunk/lib/CodeGen/MIRPrinter.cpp
llvm/trunk/lib/CodeGen/MachineInstr.cpp
llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp
Modified: llvm/trunk/lib/CodeGen/MIRPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MIRPrinter.cpp?rev=322936&r1=322935&r2=322936&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MIRPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/MIRPrinter.cpp Fri Jan 19 03:44:42 2018
@@ -686,11 +686,11 @@ void MIPrinter::print(const MachineInstr
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()) {
Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=322936&r1=322935&r2=322936&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Fri Jan 19 03:44:42 2018
@@ -1425,6 +1425,15 @@ void MachineInstr::print(raw_ostream &OS
}
}
+ 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
}
}
+ 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
}
if (isIndirectDebugValue())
OS << " indirect";
- } else if (SkipDebugLoc) {
- return;
- } else if (debugLoc && MF) {
- if (!HaveSemi)
- OS << ";";
- OS << " dbg:";
- debugLoc.print(OS);
}
OS << '\n';
Modified: llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp?rev=322936&r1=322935&r2=322936&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp Fri Jan 19 03:44:42 2018
@@ -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, Is
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
More information about the llvm-commits
mailing list