[llvm] 39385d4 - [CodeGen][Debuginfo][NFC] Refactor DIE values SizeOf method to not depend on AsmPrinter.
Alexey Lapshin via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 12 02:16:34 PST 2022
Author: Alexey Lapshin
Date: 2022-01-12T13:15:26+03:00
New Revision: 39385d4cd1c6e70f9b7c9cadb35e57efbdf2ecbc
URL: https://github.com/llvm/llvm-project/commit/39385d4cd1c6e70f9b7c9cadb35e57efbdf2ecbc
DIFF: https://github.com/llvm/llvm-project/commit/39385d4cd1c6e70f9b7c9cadb35e57efbdf2ecbc.diff
LOG: [CodeGen][Debuginfo][NFC] Refactor DIE values SizeOf method to not depend on AsmPrinter.
SizeOf() method of DIE values(unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const)
depends on AsmPrinter. AsmPrinter is too specific class here. This patch removes dependency
on AsmPrinter and use dwarf::FormParams structure instead. It allows calculate DIE values
size without using AsmPrinter. That refactoring is useful for D96035([dsymutil][DWARFlinker]
implement separate multi-thread processing for compile units.)
Differential Revision: https://reviews.llvm.org/D116997
Added:
Modified:
llvm/include/llvm/BinaryFormat/Dwarf.h
llvm/include/llvm/CodeGen/AsmPrinter.h
llvm/include/llvm/CodeGen/DIE.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/AsmPrinter/DIE.cpp
llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/unittests/CodeGen/DIETest.cpp
llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/Dwarf.h b/llvm/include/llvm/BinaryFormat/Dwarf.h
index a725aff39ac60..7ce3a97f9906f 100644
--- a/llvm/include/llvm/BinaryFormat/Dwarf.h
+++ b/llvm/include/llvm/BinaryFormat/Dwarf.h
@@ -649,6 +649,9 @@ struct FormParams {
uint16_t Version;
uint8_t AddrSize;
DwarfFormat Format;
+ /// True if DWARF v2 output generally uses relocations for references
+ /// to other .debug_* sections.
+ bool DwarfUsesRelocationsAcrossSections = false;
/// The definition of the size of form DW_FORM_ref_addr depends on the
/// version. In DWARF v2 it's the size of an address; after that, it's the
diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h
index 8608c908c1088..d911bfd435aea 100644
--- a/llvm/include/llvm/CodeGen/AsmPrinter.h
+++ b/llvm/include/llvm/CodeGen/AsmPrinter.h
@@ -17,6 +17,7 @@
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/AsmPrinterHandler.h"
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -231,6 +232,9 @@ class AsmPrinter : public MachineFunctionPass {
/// Returns 4 for DWARF32 and 12 for DWARF64.
unsigned int getUnitLengthFieldByteSize() const;
+ /// Returns information about the byte size of DW_FORM values.
+ dwarf::FormParams getDwarfFormParams() const;
+
bool isPositionIndependent() const;
/// Return true if assembly output should contain comments.
diff --git a/llvm/include/llvm/CodeGen/DIE.h b/llvm/include/llvm/CodeGen/DIE.h
index 51320aea0327d..32df448b91a11 100644
--- a/llvm/include/llvm/CodeGen/DIE.h
+++ b/llvm/include/llvm/CodeGen/DIE.h
@@ -191,7 +191,7 @@ class DIEInteger {
void setValue(uint64_t Val) { Integer = Val; }
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
@@ -208,7 +208,7 @@ class DIEExpr {
const MCExpr *getValue() const { return Expr; }
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
@@ -225,7 +225,7 @@ class DIELabel {
const MCSymbol *getValue() const { return Label; }
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
@@ -243,8 +243,8 @@ class DIEBaseTypeRef {
/// EmitValue - Emit base type reference.
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const;
- /// SizeOf - Determine size of the base type reference in bytes.
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ /// sizeOf - Determine size of the base type reference in bytes.
+ unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const;
void print(raw_ostream &O) const;
uint64_t getIndex() const { return Index; }
@@ -261,7 +261,7 @@ class DIEDelta {
DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo) : LabelHi(Hi), LabelLo(Lo) {}
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
@@ -280,7 +280,7 @@ class DIEString {
StringRef getString() const { return S.getString(); }
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
@@ -302,7 +302,7 @@ class DIEInlineString {
StringRef getString() const { return S; }
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const;
void print(raw_ostream &O) const;
};
@@ -321,7 +321,7 @@ class DIEEntry {
DIE &getEntry() const { return *Entry; }
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
@@ -340,7 +340,7 @@ class DIELocList {
size_t getValue() const { return Index; }
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
@@ -356,7 +356,7 @@ class DIEAddrOffset {
: Addr(Idx), Offset(Hi, Lo) {}
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
@@ -506,7 +506,7 @@ class DIEValue {
void emitValue(const AsmPrinter *AP) const;
/// Return the size of a value in bytes.
- unsigned SizeOf(const AsmPrinter *AP) const;
+ unsigned sizeOf(const dwarf::FormParams &FormParams) const;
void print(raw_ostream &O) const;
void dump() const;
@@ -825,12 +825,12 @@ class DIE : IntrusiveBackListNode, public DIEValueList {
/// properly refer to other DIE objects since all DIEs have calculated their
/// offsets.
///
- /// \param AP AsmPrinter to use when calculating sizes.
+ /// \param FormParams Used when calculating sizes.
/// \param AbbrevSet the abbreviation used to unique DIE abbreviations.
/// \param CUOffset the compile/type unit relative offset in bytes.
/// \returns the offset for the DIE that follows this DIE within the
/// current compile/type unit.
- unsigned computeOffsetsAndAbbrevs(const AsmPrinter *AP,
+ unsigned computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams,
DIEAbbrevSet &AbbrevSet, unsigned CUOffset);
/// Climb up the parent chain to get the compile unit or type unit DIE that
@@ -933,9 +933,8 @@ class DIELoc : public DIEValueList {
public:
DIELoc() = default;
- /// ComputeSize - Calculate the size of the location expression.
- ///
- unsigned ComputeSize(const AsmPrinter *AP) const;
+ /// Calculate the size of the location expression.
+ unsigned computeSize(const dwarf::FormParams &FormParams) const;
// TODO: move setSize() and Size to DIEValueList.
void setSize(unsigned size) { Size = size; }
@@ -956,7 +955,7 @@ class DIELoc : public DIEValueList {
}
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
@@ -970,9 +969,8 @@ class DIEBlock : public DIEValueList {
public:
DIEBlock() = default;
- /// ComputeSize - Calculate the size of the location expression.
- ///
- unsigned ComputeSize(const AsmPrinter *AP) const;
+ /// Calculate the size of the location expression.
+ unsigned computeSize(const dwarf::FormParams &FormParams) const;
// TODO: move setSize() and Size to DIEValueList.
void setSize(unsigned size) { Size = size; }
@@ -990,7 +988,7 @@ class DIEBlock : public DIEValueList {
}
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const;
- unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
+ unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const;
void print(raw_ostream &O) const;
};
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 61c2fbc59b5a1..f13b8f733e202 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3649,6 +3649,12 @@ unsigned int AsmPrinter::getDwarfOffsetByteSize() const {
OutStreamer->getContext().getDwarfFormat());
}
+dwarf::FormParams AsmPrinter::getDwarfFormParams() const {
+ return {getDwarfVersion(), uint8_t(getPointerSize()),
+ OutStreamer->getContext().getDwarfFormat(),
+ MAI->doesDwarfUseRelocationsAcrossSections()};
+}
+
unsigned int AsmPrinter::getUnitLengthFieldByteSize() const {
return dwarf::getUnitLengthFieldByteSize(
OutStreamer->getContext().getDwarfFormat());
diff --git a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp
index 2834d9c3ebbf9..1a0256f30d41c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp
@@ -274,7 +274,7 @@ LLVM_DUMP_METHOD void DIE::dump() const {
}
#endif
-unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
+unsigned DIE::computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams,
DIEAbbrevSet &AbbrevSet,
unsigned CUOffset) {
// Unique the abbreviation and fill in the abbreviation number so this DIE
@@ -289,7 +289,7 @@ unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
// Add the byte size of all the DIE attribute values.
for (const auto &V : values())
- CUOffset += V.SizeOf(AP);
+ CUOffset += V.sizeOf(FormParams);
// Let the children compute their offsets and abbreviation numbers.
if (hasChildren()) {
@@ -297,7 +297,8 @@ unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
assert(Abbrev.hasChildren() && "Children flag not set");
for (auto &Child : children())
- CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
+ CUOffset =
+ Child.computeOffsetsAndAbbrevs(FormParams, AbbrevSet, CUOffset);
// Each child chain is terminated with a zero byte, adjust the offset.
CUOffset += sizeof(int8_t);
@@ -335,13 +336,13 @@ void DIEValue::emitValue(const AsmPrinter *AP) const {
}
}
-unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
+unsigned DIEValue::sizeOf(const dwarf::FormParams &FormParams) const {
switch (Ty) {
case isNone:
llvm_unreachable("Expected valid DIEValue");
#define HANDLE_DIEVALUE(T) \
case is##T: \
- return getDIE##T().SizeOf(AP, Form);
+ return getDIE##T().sizeOf(FormParams, Form);
#include "llvm/CodeGen/DIEValue.def"
}
llvm_unreachable("Unknown DIE kind");
@@ -407,7 +408,8 @@ void DIEInteger::emitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
case dwarf::DW_FORM_strp_sup:
case dwarf::DW_FORM_addr:
case dwarf::DW_FORM_ref_addr:
- Asm->OutStreamer->emitIntValue(Integer, SizeOf(Asm, Form));
+ Asm->OutStreamer->emitIntValue(Integer,
+ sizeOf(Asm->getDwarfFormParams(), Form));
return;
case dwarf::DW_FORM_GNU_str_index:
case dwarf::DW_FORM_GNU_addr_index:
@@ -425,15 +427,12 @@ void DIEInteger::emitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
}
}
-/// SizeOf - Determine size of integer value in bytes.
+/// sizeOf - Determine size of integer value in bytes.
///
-unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
- assert(AP && "AsmPrinter is required to set FormParams");
- dwarf::FormParams Params = {AP->getDwarfVersion(),
- uint8_t(AP->getPointerSize()),
- AP->OutStreamer->getContext().getDwarfFormat()};
-
- if (Optional<uint8_t> FixedSize = dwarf::getFixedFormByteSize(Form, Params))
+unsigned DIEInteger::sizeOf(const dwarf::FormParams &FormParams,
+ dwarf::Form Form) const {
+ if (Optional<uint8_t> FixedSize =
+ dwarf::getFixedFormByteSize(Form, FormParams))
return *FixedSize;
switch (Form) {
@@ -464,19 +463,20 @@ void DIEInteger::print(raw_ostream &O) const {
/// EmitValue - Emit expression value.
///
void DIEExpr::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
- AP->emitDebugValue(Expr, SizeOf(AP, Form));
+ AP->emitDebugValue(Expr, sizeOf(AP->getDwarfFormParams(), Form));
}
/// SizeOf - Determine size of expression value in bytes.
///
-unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIEExpr::sizeOf(const dwarf::FormParams &FormParams,
+ dwarf::Form Form) const {
switch (Form) {
case dwarf::DW_FORM_data4:
return 4;
case dwarf::DW_FORM_data8:
return 8;
case dwarf::DW_FORM_sec_offset:
- return AP->getDwarfOffsetByteSize();
+ return FormParams.getDwarfOffsetByteSize();
default:
llvm_unreachable("DIE Value form not supported yet");
}
@@ -493,12 +493,14 @@ void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
///
void DIELabel::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
bool IsSectionRelative = Form != dwarf::DW_FORM_addr;
- AP->emitLabelReference(Label, SizeOf(AP, Form), IsSectionRelative);
+ AP->emitLabelReference(Label, sizeOf(AP->getDwarfFormParams(), Form),
+ IsSectionRelative);
}
-/// SizeOf - Determine size of label value in bytes.
+/// sizeOf - Determine size of label value in bytes.
///
-unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIELabel::sizeOf(const dwarf::FormParams &FormParams,
+ dwarf::Form Form) const {
switch (Form) {
case dwarf::DW_FORM_data4:
return 4;
@@ -506,9 +508,9 @@ unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
return 8;
case dwarf::DW_FORM_sec_offset:
case dwarf::DW_FORM_strp:
- return AP->getDwarfOffsetByteSize();
+ return FormParams.getDwarfOffsetByteSize();
case dwarf::DW_FORM_addr:
- return AP->MAI->getCodePointerSize();
+ return FormParams.AddrSize;
default:
llvm_unreachable("DIE Value form not supported yet");
}
@@ -527,7 +529,7 @@ void DIEBaseTypeRef::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
AP->emitULEB128(Offset, nullptr, ULEB128PadSize);
}
-unsigned DIEBaseTypeRef::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIEBaseTypeRef::sizeOf(const dwarf::FormParams &, dwarf::Form) const {
return ULEB128PadSize;
}
@@ -541,19 +543,21 @@ void DIEBaseTypeRef::print(raw_ostream &O) const { O << "BaseTypeRef: " << Index
/// EmitValue - Emit delta value.
///
void DIEDelta::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
- AP->emitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
+ AP->emitLabelDifference(LabelHi, LabelLo,
+ sizeOf(AP->getDwarfFormParams(), Form));
}
/// SizeOf - Determine size of delta value in bytes.
///
-unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIEDelta::sizeOf(const dwarf::FormParams &FormParams,
+ dwarf::Form Form) const {
switch (Form) {
case dwarf::DW_FORM_data4:
return 4;
case dwarf::DW_FORM_data8:
return 8;
case dwarf::DW_FORM_sec_offset:
- return AP->getDwarfOffsetByteSize();
+ return FormParams.getDwarfOffsetByteSize();
default:
llvm_unreachable("DIE Value form not supported yet");
}
@@ -592,9 +596,10 @@ void DIEString::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
}
}
-/// SizeOf - Determine size of delta value in bytes.
+/// sizeOf - Determine size of delta value in bytes.
///
-unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIEString::sizeOf(const dwarf::FormParams &FormParams,
+ dwarf::Form Form) const {
// Index of string in symbol table.
switch (Form) {
case dwarf::DW_FORM_GNU_str_index:
@@ -603,11 +608,11 @@ unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
case dwarf::DW_FORM_strx2:
case dwarf::DW_FORM_strx3:
case dwarf::DW_FORM_strx4:
- return DIEInteger(S.getIndex()).SizeOf(AP, Form);
+ return DIEInteger(S.getIndex()).sizeOf(FormParams, Form);
case dwarf::DW_FORM_strp:
- if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
- return DIELabel(S.getSymbol()).SizeOf(AP, Form);
- return DIEInteger(S.getOffset()).SizeOf(AP, Form);
+ if (FormParams.DwarfUsesRelocationsAcrossSections)
+ return DIELabel(S.getSymbol()).sizeOf(FormParams, Form);
+ return DIEInteger(S.getOffset()).sizeOf(FormParams, Form);
default:
llvm_unreachable("Expected valid string form");
}
@@ -630,7 +635,7 @@ void DIEInlineString::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
llvm_unreachable("Expected valid string form");
}
-unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIEInlineString::sizeOf(const dwarf::FormParams &, dwarf::Form) const {
// Emit string bytes + NULL byte.
return S.size() + 1;
}
@@ -653,7 +658,8 @@ void DIEEntry::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
case dwarf::DW_FORM_ref2:
case dwarf::DW_FORM_ref4:
case dwarf::DW_FORM_ref8:
- AP->OutStreamer->emitIntValue(Entry->getOffset(), SizeOf(AP, Form));
+ AP->OutStreamer->emitIntValue(Entry->getOffset(),
+ sizeOf(AP->getDwarfFormParams(), Form));
return;
case dwarf::DW_FORM_ref_udata:
@@ -665,11 +671,12 @@ void DIEEntry::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
uint64_t Addr = Entry->getDebugSectionOffset();
if (const MCSymbol *SectionSym =
Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
- AP->emitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
+ AP->emitLabelPlusOffset(SectionSym, Addr,
+ sizeOf(AP->getDwarfFormParams(), Form), true);
return;
}
- AP->OutStreamer->emitIntValue(Addr, SizeOf(AP, Form));
+ AP->OutStreamer->emitIntValue(Addr, sizeOf(AP->getDwarfFormParams(), Form));
return;
}
default:
@@ -677,7 +684,8 @@ void DIEEntry::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
}
}
-unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIEEntry::sizeOf(const dwarf::FormParams &FormParams,
+ dwarf::Form Form) const {
switch (Form) {
case dwarf::DW_FORM_ref1:
return 1;
@@ -690,15 +698,7 @@ unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
case dwarf::DW_FORM_ref_udata:
return getULEB128Size(Entry->getOffset());
case dwarf::DW_FORM_ref_addr:
- if (AP->getDwarfVersion() == 2)
- return AP->MAI->getCodePointerSize();
- switch (AP->OutStreamer->getContext().getDwarfFormat()) {
- case dwarf::DWARF32:
- return 4;
- case dwarf::DWARF64:
- return 8;
- }
- llvm_unreachable("Invalid DWARF format");
+ return FormParams.getRefAddrByteSize();
default:
llvm_unreachable("Improper form for DIE reference");
@@ -714,12 +714,10 @@ void DIEEntry::print(raw_ostream &O) const {
// DIELoc Implementation
//===----------------------------------------------------------------------===//
-/// ComputeSize - calculate the size of the location expression.
-///
-unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
+unsigned DIELoc::computeSize(const dwarf::FormParams &FormParams) const {
if (!Size) {
for (const auto &V : values())
- Size += V.SizeOf(AP);
+ Size += V.sizeOf(FormParams);
}
return Size;
@@ -743,9 +741,9 @@ void DIELoc::emitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
V.emitValue(Asm);
}
-/// SizeOf - Determine size of location data in bytes.
+/// sizeOf - Determine size of location data in bytes.
///
-unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIELoc::sizeOf(const dwarf::FormParams &, dwarf::Form Form) const {
switch (Form) {
case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
@@ -766,12 +764,10 @@ void DIELoc::print(raw_ostream &O) const {
// DIEBlock Implementation
//===----------------------------------------------------------------------===//
-/// ComputeSize - calculate the size of the block.
-///
-unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
+unsigned DIEBlock::computeSize(const dwarf::FormParams &FormParams) const {
if (!Size) {
for (const auto &V : values())
- Size += V.SizeOf(AP);
+ Size += V.sizeOf(FormParams);
}
return Size;
@@ -797,9 +793,9 @@ void DIEBlock::emitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
V.emitValue(Asm);
}
-/// SizeOf - Determine size of block data in bytes.
+/// sizeOf - Determine size of block data in bytes.
///
-unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIEBlock::sizeOf(const dwarf::FormParams &, dwarf::Form Form) const {
switch (Form) {
case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
@@ -820,22 +816,23 @@ void DIEBlock::print(raw_ostream &O) const {
// DIELocList Implementation
//===----------------------------------------------------------------------===//
-unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
+unsigned DIELocList::sizeOf(const dwarf::FormParams &FormParams,
+ dwarf::Form Form) const {
switch (Form) {
case dwarf::DW_FORM_loclistx:
return getULEB128Size(Index);
case dwarf::DW_FORM_data4:
- assert(!AP->isDwarf64() &&
+ assert(FormParams.Format != dwarf::DWARF64 &&
"DW_FORM_data4 is not suitable to emit a pointer to a location list "
"in the 64-bit DWARF format");
return 4;
case dwarf::DW_FORM_data8:
- assert(AP->isDwarf64() &&
+ assert(FormParams.Format == dwarf::DWARF64 &&
"DW_FORM_data8 is not suitable to emit a pointer to a location list "
"in the 32-bit DWARF format");
return 8;
case dwarf::DW_FORM_sec_offset:
- return AP->getDwarfOffsetByteSize();
+ return FormParams.getDwarfOffsetByteSize();
default:
llvm_unreachable("DIE Value form not supported yet");
}
@@ -860,9 +857,10 @@ void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }
// DIEAddrOffset Implementation
//===----------------------------------------------------------------------===//
-unsigned DIEAddrOffset::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
- return Addr.SizeOf(AP, dwarf::DW_FORM_addrx) +
- Offset.SizeOf(AP, dwarf::DW_FORM_data4);
+unsigned DIEAddrOffset::sizeOf(const dwarf::FormParams &FormParams,
+ dwarf::Form) const {
+ return Addr.sizeOf(FormParams, dwarf::DW_FORM_addrx) +
+ Offset.sizeOf(FormParams, dwarf::DW_FORM_data4);
}
/// EmitValue - Emit label value.
diff --git a/llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp b/llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp
index b7b26199956a9..e175854f7b93e 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp
@@ -310,10 +310,10 @@ void DIEHash::hashAttribute(const DIEValue &Value, dwarf::Tag Tag) {
addULEB128(Attribute);
addULEB128(dwarf::DW_FORM_block);
if (Value.getType() == DIEValue::isBlock) {
- addULEB128(Value.getDIEBlock().ComputeSize(AP));
+ addULEB128(Value.getDIEBlock().computeSize(AP->getDwarfFormParams()));
hashBlockData(Value.getDIEBlock().values());
} else if (Value.getType() == DIEValue::isLoc) {
- addULEB128(Value.getDIELoc().ComputeSize(AP));
+ addULEB128(Value.getDIELoc().computeSize(AP->getDwarfFormParams()));
hashBlockData(Value.getDIELoc().values());
} else {
// We could add the block length, but that would take
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp
index 838e1c9a10be6..a67d0f032cf68 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.cpp
@@ -92,7 +92,8 @@ unsigned DwarfFile::computeSizeAndOffsetsForUnit(DwarfUnit *TheU) {
// Compute the size and offset of a DIE. The offset is relative to start of the
// CU. It returns the offset after laying out the DIE.
unsigned DwarfFile::computeSizeAndOffset(DIE &Die, unsigned Offset) {
- return Die.computeOffsetsAndAbbrevs(Asm, Abbrevs, Offset);
+ return Die.computeOffsetsAndAbbrevs(Asm->getDwarfFormParams(), Abbrevs,
+ Offset);
}
void DwarfFile::emitAbbrevs(MCSection *Section) { Abbrevs.Emit(Asm, Section); }
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 0d656707615cb..6b2eb8f2bf1d9 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -77,7 +77,7 @@ void DIEDwarfExpression::enableTemporaryBuffer() {
void DIEDwarfExpression::disableTemporaryBuffer() { IsBuffering = false; }
unsigned DIEDwarfExpression::getTemporaryBufferSize() {
- return TmpDIE.ComputeSize(&AP);
+ return TmpDIE.computeSize(AP.getDwarfFormParams());
}
void DIEDwarfExpression::commitTemporaryBuffer() { OutDIE.takeValues(TmpDIE); }
@@ -394,14 +394,14 @@ DIE &DwarfUnit::createAndAddDIE(dwarf::Tag Tag, DIE &Parent, const DINode *N) {
}
void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc) {
- Loc->ComputeSize(Asm);
+ Loc->computeSize(Asm->getDwarfFormParams());
DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
addAttribute(Die, Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);
}
void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form,
DIEBlock *Block) {
- Block->ComputeSize(Asm);
+ Block->computeSize(Asm->getDwarfFormParams());
DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
addAttribute(Die, Attribute, Form, Block);
}
diff --git a/llvm/unittests/CodeGen/DIETest.cpp b/llvm/unittests/CodeGen/DIETest.cpp
index 73754fe6df3ee..87dbb63e8f16d 100644
--- a/llvm/unittests/CodeGen/DIETest.cpp
+++ b/llvm/unittests/CodeGen/DIETest.cpp
@@ -8,6 +8,7 @@
#include "llvm/CodeGen/DIE.h"
#include "TestAsmPrinter.h"
+#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/Testing/Support/Error.h"
@@ -54,7 +55,7 @@ struct DIEExprFixture : public DIEFixtureBase {
TEST_P(DIEExprFixture, SizeOf) {
DIEExpr Tst(Val);
- EXPECT_EQ(Size, Tst.SizeOf(TestPrinter->getAP(), Form));
+ EXPECT_EQ(Size, Tst.sizeOf(TestPrinter->getAP()->getDwarfFormParams(), Form));
}
TEST_P(DIEExprFixture, EmitValue) {
@@ -87,7 +88,7 @@ struct DIELabelFixture : public DIEFixtureBase {
TEST_P(DIELabelFixture, SizeOf) {
DIELabel Tst(Val);
- EXPECT_EQ(Size, Tst.SizeOf(TestPrinter->getAP(), Form));
+ EXPECT_EQ(Size, Tst.sizeOf(TestPrinter->getAP()->getDwarfFormParams(), Form));
}
TEST_P(DIELabelFixture, EmitValue) {
@@ -133,7 +134,7 @@ struct DIEDeltaFixture : public DIEFixtureBase {
TEST_P(DIEDeltaFixture, SizeOf) {
DIEDelta Tst(Hi, Lo);
- EXPECT_EQ(Size, Tst.SizeOf(TestPrinter->getAP(), Form));
+ EXPECT_EQ(Size, Tst.sizeOf(TestPrinter->getAP()->getDwarfFormParams(), Form));
}
TEST_P(DIEDeltaFixture, EmitValue) {
@@ -158,7 +159,7 @@ struct DIELocListFixture : public DIEFixtureBase {
TEST_P(DIELocListFixture, SizeOf) {
DIELocList Tst(999);
- EXPECT_EQ(Size, Tst.SizeOf(TestPrinter->getAP(), Form));
+ EXPECT_EQ(Size, Tst.sizeOf(TestPrinter->getAP()->getDwarfFormParams(), Form));
}
INSTANTIATE_TEST_SUITE_P(
diff --git a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
index e294239cd7857..78eeba4f50a5d 100644
--- a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
@@ -47,8 +47,8 @@ namespace {} // end anonymous namespace
//===----------------------------------------------------------------------===//
unsigned dwarfgen::DIE::computeSizeAndOffsets(unsigned Offset) {
auto &DG = CU->getGenerator();
- return Die->computeOffsetsAndAbbrevs(DG.getAsmPrinter(), DG.getAbbrevSet(),
- Offset);
+ return Die->computeOffsetsAndAbbrevs(DG.getAsmPrinter()->getDwarfFormParams(),
+ DG.getAbbrevSet(), Offset);
}
void dwarfgen::DIE::addAttribute(uint16_t A, dwarf::Form Form, uint64_t U) {
@@ -112,7 +112,7 @@ void dwarfgen::DIE::addAttribute(uint16_t A, dwarf::Form Form, const void *P,
DIEInteger(
(const_cast<uint8_t *>(static_cast<const uint8_t *>(P)))[I]));
- Block->ComputeSize(DG.getAsmPrinter());
+ Block->computeSize(DG.getAsmPrinter()->getDwarfFormParams());
Die->addValue(DG.getAllocator(), static_cast<dwarf::Attribute>(A), Form,
Block);
}
More information about the llvm-commits
mailing list