Author: Chen Zheng Date: 2021-01-14T07:03:38-05:00 New Revision: de6cd53343c4ed37926c18edbad04aeec06f6ec1
URL: https://github.com/llvm/llvm-project/commit/de6cd53343c4ed37926c18edbad04aeec06f6ec1 DIFF: https://github.com/llvm/llvm-project/commit/de6cd53343c4ed37926c18edbad04aeec06f6ec1.diff LOG: [DebugInfo][NFC] add a new DIE type to represent label + offset. Added: Modified: llvm/include/llvm/CodeGen/AsmPrinter.h llvm/include/llvm/CodeGen/DIE.h llvm/include/llvm/CodeGen/DIEValue.def llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp llvm/lib/CodeGen/AsmPrinter/DIE.cpp llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h Removed: ################################################################################ diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h index 76486b0b48ce..a8a31b83d01c 100644 --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -580,7 +580,7 @@ class AsmPrinter : public MachineFunctionPass { /// Emit something like ".long Label+Offset" where the size in bytes of the /// directive is specified by Size and Label specifies the label. This /// implicitly uses .set if it is available. - void emitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, + void emitLabelPlusOffset(const MCSymbol *Label, int64_t Offset, unsigned Size, bool IsSectionRelative = false) const; /// Emit something like ".long Label" where the size in bytes of the directive diff --git a/llvm/include/llvm/CodeGen/DIE.h b/llvm/include/llvm/CodeGen/DIE.h index 3efef6ec0acd..634ac2815926 100644 --- a/llvm/include/llvm/CodeGen/DIE.h +++ b/llvm/include/llvm/CodeGen/DIE.h @@ -266,6 +266,22 @@ class DIEDelta { void print(raw_ostream &O) const; }; +//===--------------------------------------------------------------------===// +/// A simple label plus offset DIE. +/// +class DIELabelPlusOffset { + const MCSymbol *Label; + int64_t Offset; + +public: + DIELabelPlusOffset(const MCSymbol *L, int64_t O) : Label(L), Offset(O) {} + + void emitValue(const AsmPrinter *AP, dwarf::Form Form) const; + unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const; + + void print(raw_ostream &O) const; +}; + //===--------------------------------------------------------------------===// /// A container for string pool string values. /// @@ -370,7 +386,8 @@ class DIEValue { /// should be stored by reference instead of by value. using ValTy = AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel, DIEDelta *, DIEEntry, DIEBlock *, - DIELoc *, DIELocList, DIEBaseTypeRef *>; + DIELoc *, DIELocList, DIEBaseTypeRef *, + DIELabelPlusOffset *>; static_assert(sizeof(ValTy) <= sizeof(uint64_t) || sizeof(ValTy) <= sizeof(void *), diff --git a/llvm/include/llvm/CodeGen/DIEValue.def b/llvm/include/llvm/CodeGen/DIEValue.def index 92afeb3868b4..9091f8d06c3b 100644 --- a/llvm/include/llvm/CodeGen/DIEValue.def +++ b/llvm/include/llvm/CodeGen/DIEValue.def @@ -41,6 +41,7 @@ HANDLE_DIEVALUE_LARGE(Block) HANDLE_DIEVALUE_LARGE(Loc) HANDLE_DIEVALUE_SMALL(LocList) HANDLE_DIEVALUE_LARGE(InlineString) +HANDLE_DIEVALUE_LARGE(LabelPlusOffset) #undef HANDLE_DIEVALUE #undef HANDLE_DIEVALUE_SMALL diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 85754bf29d0c..89a01e4e1a57 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2319,7 +2319,7 @@ void AsmPrinter::emitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, /// EmitLabelPlusOffset - Emit something like ".long Label+Offset" /// where the size in bytes of the directive is specified by Size and Label /// specifies the label. This implicitly uses .set if it is available. -void AsmPrinter::emitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, +void AsmPrinter::emitLabelPlusOffset(const MCSymbol *Label, int64_t Offset, unsigned Size, bool IsSectionRelative) const { if (MAI->needsDwarfSectionOffsetDirective() && IsSectionRelative) { diff --git a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp index 39b0b027c765..2ca586c713ab 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp @@ -564,6 +564,36 @@ void DIEDelta::print(raw_ostream &O) const { O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName(); } +//===----------------------------------------------------------------------===// +// DIELabelPlusOffset Implementation +//===----------------------------------------------------------------------===// + +/// EmitValue - Emit lable plus offset value. +/// +void DIELabelPlusOffset::emitValue(const AsmPrinter *AP, dwarf::Form Form) const { + AP->emitLabelPlusOffset(Label, Offset, SizeOf(AP, Form)); +} + +/// SizeOf - Determine size of delta value in bytes. +/// +unsigned DIELabelPlusOffset::SizeOf(const AsmPrinter *AP, 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(); + default: + llvm_unreachable("DIE Value form not supported yet"); + } +} + +LLVM_DUMP_METHOD +void DIELabelPlusOffset::print(raw_ostream &O) const { + O << "Del: " << Label->getName() << "-" << Offset; +} + //===----------------------------------------------------------------------===// // DIEString Implementation //===----------------------------------------------------------------------===// diff --git a/llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp b/llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp index da9997efc01f..afbb5a4e3010 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DIEHash.cpp @@ -319,6 +319,7 @@ void DIEHash::hashAttribute(const DIEValue &Value, dwarf::Tag Tag) { case DIEValue::isLabel: case DIEValue::isBaseTypeRef: case DIEValue::isDelta: + case DIEValue::isLabelPlusOffset: llvm_unreachable("Add support for additional value types."); } } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 118b5fcc3bf6..74b515acd8bc 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1733,6 +1733,14 @@ DwarfUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute, new (DIEValueAllocator) DIEDelta(Hi, Lo)); } +DIE::value_iterator +DwarfUnit::addLabelPlusOffset(DIE &Die, dwarf::Attribute Attribute, + const MCSymbol *Label, int64_t Offset) { + return Die.addValue( + DIEValueAllocator, Attribute, DD->getDwarfSectionOffsetForm(), + new (DIEValueAllocator) DIELabelPlusOffset(Label, Offset)); +} + DIE::value_iterator DwarfUnit::addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec) { diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h index 5c643760fd56..8082aae58be0 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -277,6 +277,10 @@ class DwarfUnit : public DIEUnit { const MCSymbol *Label, const MCSymbol *Sec); + /// Add a label plus some offset. + DIE::value_iterator addLabelPlusOffset(DIE &Die, dwarf::Attribute Attribute, + const MCSymbol *Label, int64_t Offset); + /// Get context owner's DIE. DIE *createTypeDIE(const DICompositeType *Ty); _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits