[PATCH] D127561: [BOLT][NFC] Move printDebugInfo out of BC::printInstruction
Amir Ayupov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 10 23:39:58 PDT 2022
Amir created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.
Simplify `BinaryContext::printInstruction`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127561
Files:
bolt/include/bolt/Core/BinaryContext.h
bolt/lib/Core/BinaryContext.cpp
Index: bolt/lib/Core/BinaryContext.cpp
===================================================================
--- bolt/lib/Core/BinaryContext.cpp
+++ bolt/lib/Core/BinaryContext.cpp
@@ -1421,7 +1421,7 @@
return Iter->second;
}
-DWARFContext *BinaryContext::getDWOContext() {
+DWARFContext *BinaryContext::getDWOContext() const {
if (DWOCUs.empty())
return nullptr;
return &DWOCUs.begin()->second->getContext();
@@ -1683,6 +1683,36 @@
return getMarkerType(Symbol) != MarkerSymType::NONE;
}
+void printDebugInfo(raw_ostream &OS, const MCInst &Instruction,
+ const BinaryFunction *Function,
+ DWARFContext* DwCtx) {
+ DebugLineTableRowRef RowRef =
+ DebugLineTableRowRef::fromSMLoc(Instruction.getLoc());
+ if (RowRef == DebugLineTableRowRef::NULL_ROW)
+ return;
+
+ const DWARFDebugLine::LineTable *LineTable;
+ if (Function && Function->getDWARFUnit() &&
+ Function->getDWARFUnit()->getOffset() == RowRef.DwCompileUnitIndex) {
+ LineTable = Function->getDWARFLineTable();
+ } else {
+ LineTable = DwCtx->getLineTableForUnit(
+ DwCtx->getCompileUnitForOffset(RowRef.DwCompileUnitIndex));
+ }
+ assert(LineTable && "line table expected for instruction with debug info");
+
+ const DWARFDebugLine::Row &Row = LineTable->Rows[RowRef.RowIndex - 1];
+ StringRef FileName = "";
+ if (Optional<const char *> FName =
+ dwarf::toString(LineTable->Prologue.FileNames[Row.File - 1].Name))
+ FileName = *FName;
+ OS << " # debug line " << FileName << ":" << Row.Line;
+ if (Row.Column)
+ OS << ":" << Row.Column;
+ if (Row.Discriminator)
+ OS << " discriminator:" << Row.Discriminator;
+}
+
void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
uint64_t Offset,
const BinaryFunction *Function,
@@ -1742,33 +1772,8 @@
MIB->printAnnotations(Instruction, OS);
- if (opts::PrintDebugInfo) {
- DebugLineTableRowRef RowRef =
- DebugLineTableRowRef::fromSMLoc(Instruction.getLoc());
- if (RowRef != DebugLineTableRowRef::NULL_ROW) {
- const DWARFDebugLine::LineTable *LineTable;
- if (Function && Function->getDWARFUnit() &&
- Function->getDWARFUnit()->getOffset() == RowRef.DwCompileUnitIndex) {
- LineTable = Function->getDWARFLineTable();
- } else {
- LineTable = DwCtx->getLineTableForUnit(
- DwCtx->getCompileUnitForOffset(RowRef.DwCompileUnitIndex));
- }
- assert(LineTable &&
- "line table expected for instruction with debug info");
-
- const DWARFDebugLine::Row &Row = LineTable->Rows[RowRef.RowIndex - 1];
- StringRef FileName = "";
- if (Optional<const char *> FName =
- dwarf::toString(LineTable->Prologue.FileNames[Row.File - 1].Name))
- FileName = *FName;
- OS << " # debug line " << FileName << ":" << Row.Line;
- if (Row.Column)
- OS << ":" << Row.Column;
- if (Row.Discriminator)
- OS << " discriminator:" << Row.Discriminator;
- }
- }
+ if (opts::PrintDebugInfo)
+ printDebugInfo(OS, Instruction, Function, getDWOContext());
if ((opts::PrintRelocations || PrintRelocations) && Function) {
const uint64_t Size = computeCodeSize(&Instruction, &Instruction + 1);
Index: bolt/include/bolt/Core/BinaryContext.h
===================================================================
--- bolt/include/bolt/Core/BinaryContext.h
+++ bolt/include/bolt/Core/BinaryContext.h
@@ -239,7 +239,7 @@
Optional<DWARFUnit *> getDWOCU(uint64_t DWOId);
/// Returns DWOContext if it exists.
- DWARFContext *getDWOContext();
+ DWARFContext *getDWOContext() const;
/// Get Number of DWOCUs in a map.
uint32_t getNumDWOCUs() { return DWOCUs.size(); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127561.436112.patch
Type: text/x-patch
Size: 3830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220611/83308eb4/attachment.bin>
More information about the llvm-commits
mailing list