diff options
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp | 280 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h | 16 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfFile.h | 4 |
3 files changed, 147 insertions, 153 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp b/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp index 8b16e389963..44484c2ae05 100644 --- a/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.cpp @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#include "DwarfUnit.h" #include "Dwarf2BTF.h" +#include "DwarfUnit.h" #include "llvm/MC/MCBTFContext.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSectionELF.h" @@ -17,47 +17,47 @@ namespace llvm { Die2BTFEntry::~Die2BTFEntry() {} -unsigned char Die2BTFEntry::getDieKind(const DIE & Die) { +unsigned char Die2BTFEntry::getDieKind(const DIE &Die) { auto Tag = Die.getTag(); switch (Tag) { - case dwarf::DW_TAG_base_type: - if (getBaseTypeEncoding(Die) == BTF_INVALID_ENCODING) - return BTF_KIND_UNKN; - return BTF_KIND_INT; - case dwarf::DW_TAG_const_type: - return BTF_KIND_CONST; - case dwarf::DW_TAG_pointer_type: - return BTF_KIND_PTR; - case dwarf::DW_TAG_restrict_type: - return BTF_KIND_RESTRICT; - case dwarf::DW_TAG_volatile_type: - return BTF_KIND_VOLATILE; - case dwarf::DW_TAG_typedef: - return BTF_KIND_TYPEDEF; - case dwarf::DW_TAG_structure_type: - case dwarf::DW_TAG_class_type: - if (Die.findAttribute(dwarf::DW_AT_declaration).getType() - != DIEValue::isNone) - return BTF_KIND_FWD; - else - return BTF_KIND_STRUCT; - case dwarf::DW_TAG_union_type: - if (Die.findAttribute(dwarf::DW_AT_declaration).getType() - != DIEValue::isNone) - return BTF_KIND_FWD; - else - return BTF_KIND_UNION; - case dwarf::DW_TAG_enumeration_type: - return BTF_KIND_ENUM; - case dwarf::DW_TAG_array_type: - return BTF_KIND_ARRAY; - case dwarf::DW_TAG_subprogram: - return BTF_KIND_FUNC; - case dwarf::DW_TAG_subroutine_type: - return BTF_KIND_FUNC_PROTO; - default: - break; + case dwarf::DW_TAG_base_type: + if (getBaseTypeEncoding(Die) == BTF_INVALID_ENCODING) + return BTF_KIND_UNKN; + return BTF_KIND_INT; + case dwarf::DW_TAG_const_type: + return BTF_KIND_CONST; + case dwarf::DW_TAG_pointer_type: + return BTF_KIND_PTR; + case dwarf::DW_TAG_restrict_type: + return BTF_KIND_RESTRICT; + case dwarf::DW_TAG_volatile_type: + return BTF_KIND_VOLATILE; + case dwarf::DW_TAG_typedef: + return BTF_KIND_TYPEDEF; + case dwarf::DW_TAG_structure_type: + case dwarf::DW_TAG_class_type: + if (Die.findAttribute(dwarf::DW_AT_declaration).getType() != + DIEValue::isNone) + return BTF_KIND_FWD; + else + return BTF_KIND_STRUCT; + case dwarf::DW_TAG_union_type: + if (Die.findAttribute(dwarf::DW_AT_declaration).getType() != + DIEValue::isNone) + return BTF_KIND_FWD; + else + return BTF_KIND_UNION; + case dwarf::DW_TAG_enumeration_type: + return BTF_KIND_ENUM; + case dwarf::DW_TAG_array_type: + return BTF_KIND_ARRAY; + case dwarf::DW_TAG_subprogram: + return BTF_KIND_FUNC; + case dwarf::DW_TAG_subroutine_type: + return BTF_KIND_FUNC_PROTO; + default: + break; } return BTF_KIND_UNKN; @@ -67,27 +67,27 @@ std::unique_ptr<Die2BTFEntry> Die2BTFEntry::dieToBTFTypeEntry(const DIE &Die) { unsigned char Kind = getDieKind(Die); switch (Kind) { - case BTF_KIND_INT: - return make_unique<Die2BTFEntryInt>(Die); - case BTF_KIND_PTR: - case BTF_KIND_TYPEDEF: - case BTF_KIND_VOLATILE: - case BTF_KIND_CONST: - case BTF_KIND_RESTRICT: - case BTF_KIND_FWD: - return make_unique<Die2BTFEntry>(Die); - case BTF_KIND_ARRAY: - return make_unique<Die2BTFEntryArray>(Die); - case BTF_KIND_STRUCT: - case BTF_KIND_UNION: - return make_unique<Die2BTFEntryStruct>(Die); - case BTF_KIND_ENUM: - return make_unique<Die2BTFEntryEnum>(Die); - case BTF_KIND_FUNC: - case BTF_KIND_FUNC_PROTO: - return make_unique<Die2BTFEntryFunc>(Die); - default: - break; + case BTF_KIND_INT: + return make_unique<Die2BTFEntryInt>(Die); + case BTF_KIND_PTR: + case BTF_KIND_TYPEDEF: + case BTF_KIND_VOLATILE: + case BTF_KIND_CONST: + case BTF_KIND_RESTRICT: + case BTF_KIND_FWD: + return make_unique<Die2BTFEntry>(Die); + case BTF_KIND_ARRAY: + return make_unique<Die2BTFEntryArray>(Die); + case BTF_KIND_STRUCT: + case BTF_KIND_UNION: + return make_unique<Die2BTFEntryStruct>(Die); + case BTF_KIND_ENUM: + return make_unique<Die2BTFEntryEnum>(Die); + case BTF_KIND_FUNC: + case BTF_KIND_FUNC_PROTO: + return make_unique<Die2BTFEntryFunc>(Die); + default: + break; } return nullptr; } @@ -96,20 +96,19 @@ bool Die2BTFEntry::shouldSkipDie(const DIE &Die) { auto Tag = Die.getTag(); switch (Tag) { - case dwarf::DW_TAG_const_type: - case dwarf::DW_TAG_pointer_type: - case dwarf::DW_TAG_restrict_type: - case dwarf::DW_TAG_typedef: - case dwarf::DW_TAG_volatile_type: - { - auto TypeV = Die.findAttribute(dwarf::DW_AT_type); - if (TypeV.getType() == DIEValue::isNone) - return false; - auto &TypeDie = TypeV.getDIEEntry().getEntry(); - return Die2BTFEntry::shouldSkipDie(TypeDie); - } - default: - return getDieKind(Die) == BTF_KIND_UNKN; + case dwarf::DW_TAG_const_type: + case dwarf::DW_TAG_pointer_type: + case dwarf::DW_TAG_restrict_type: + case dwarf::DW_TAG_typedef: + case dwarf::DW_TAG_volatile_type: { + auto TypeV = Die.findAttribute(dwarf::DW_AT_type); + if (TypeV.getType() == DIEValue::isNone) + return false; + auto &TypeDie = TypeV.getDIEEntry().getEntry(); + return Die2BTFEntry::shouldSkipDie(TypeDie); + } + default: + return getDieKind(Die) == BTF_KIND_UNKN; } return true; } @@ -120,26 +119,26 @@ unsigned char Die2BTFEntry::getBaseTypeEncoding(const DIE &Die) { return BTF_INVALID_ENCODING; switch (V.getDIEInteger().getValue()) { - case dwarf::DW_ATE_boolean: - return BTF_INT_BOOL; - case dwarf::DW_ATE_signed: - return BTF_INT_SIGNED; - case dwarf::DW_ATE_signed_char: - return BTF_INT_CHAR; - case dwarf::DW_ATE_unsigned: - return 0; - case dwarf::DW_ATE_unsigned_char: - return BTF_INT_CHAR; - case dwarf::DW_ATE_imaginary_float: - case dwarf::DW_ATE_packed_decimal: - case dwarf::DW_ATE_numeric_string: - case dwarf::DW_ATE_edited: - case dwarf::DW_ATE_signed_fixed: - case dwarf::DW_ATE_address: - case dwarf::DW_ATE_complex_float: - case dwarf::DW_ATE_float: - default: - break; + case dwarf::DW_ATE_boolean: + return BTF_INT_BOOL; + case dwarf::DW_ATE_signed: + return BTF_INT_SIGNED; + case dwarf::DW_ATE_signed_char: + return BTF_INT_CHAR; + case dwarf::DW_ATE_unsigned: + return 0; + case dwarf::DW_ATE_unsigned_char: + return BTF_INT_CHAR; + case dwarf::DW_ATE_imaginary_float: + case dwarf::DW_ATE_packed_decimal: + case dwarf::DW_ATE_numeric_string: + case dwarf::DW_ATE_edited: + case dwarf::DW_ATE_signed_fixed: + case dwarf::DW_ATE_address: + case dwarf::DW_ATE_complex_float: + case dwarf::DW_ATE_float: + default: + break; } return BTF_INVALID_ENCODING; } @@ -148,53 +147,53 @@ Die2BTFEntry::Die2BTFEntry(const DIE &Die) : Die(Die) { unsigned char Kind = getDieKind(Die); switch (Kind) { - case BTF_KIND_CONST: - case BTF_KIND_FWD: - case BTF_KIND_PTR: - case BTF_KIND_RESTRICT: - case BTF_KIND_TYPEDEF: - case BTF_KIND_VOLATILE: - break; - default: - assert("Invalid Die passed into BTFTypeEntry()"); - break; + case BTF_KIND_CONST: + case BTF_KIND_FWD: + case BTF_KIND_PTR: + case BTF_KIND_RESTRICT: + case BTF_KIND_TYPEDEF: + case BTF_KIND_VOLATILE: + break; + default: + assert("Invalid Die passed into BTFTypeEntry()"); + break; } BTFType.info = (Kind & 0xf) << 24; } void Die2BTFEntry::completeData(class Dwarf2BTF &Dwarf2BTF) { - auto TypeV = Die.findAttribute(dwarf::DW_AT_type); - if (TypeV.getType() == DIEValue::isNone) { - BTFType.type = 0; - } else { - auto &TypeDie = TypeV.getDIEEntry().getEntry(); - auto Type = Dwarf2BTF.getTypeIndex(TypeDie); - BTFType.type = Type; - } + auto TypeV = Die.findAttribute(dwarf::DW_AT_type); + if (TypeV.getType() == DIEValue::isNone) { + BTFType.type = 0; + } else { + auto &TypeDie = TypeV.getDIEEntry().getEntry(); + auto Type = Dwarf2BTF.getTypeIndex(TypeDie); + BTFType.type = Type; + } - unsigned char Kind = getDieKind(Die); - if (Kind != BTF_KIND_FWD) { - BTFType.name_off = 0; - } else { - auto NameV = Die.findAttribute(dwarf::DW_AT_name); - auto Str = NameV.getDIEString().getString(); - BTFType.name_off = Dwarf2BTF.addBTFString(Str); - } + unsigned char Kind = getDieKind(Die); + if (Kind != BTF_KIND_FWD) { + BTFType.name_off = 0; + } else { + auto NameV = Die.findAttribute(dwarf::DW_AT_name); + auto Str = NameV.getDIEString().getString(); + BTFType.name_off = Dwarf2BTF.addBTFString(Str); + } - auto typeEntry = make_unique<BTFTypeEntry>(Id, BTFType); - Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); + auto typeEntry = make_unique<BTFTypeEntry>(Id, BTFType); + Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); } Die2BTFEntryInt::Die2BTFEntryInt(const DIE &Die) : Die2BTFEntry(Die) { unsigned char Kind = getDieKind(Die); switch (Kind) { - case BTF_KIND_INT: - break; - default: - assert("Invalid Die passed into BTFTypeEntryInt()"); - break; + case BTF_KIND_INT: + break; + default: + assert("Invalid Die passed into BTFTypeEntryInt()"); + break; } // handle BTF_INT_ENCODING in IntVal @@ -212,7 +211,7 @@ Die2BTFEntryInt::Die2BTFEntryInt(const DIE &Die) : Die2BTFEntry(Die) { V = Die.findAttribute(dwarf::DW_AT_byte_size); __u32 Size = V.getDIEInteger().getValue() & 0xffffffff; -// handle BTF_INT_BITS in IntVal + // handle BTF_INT_BITS in IntVal V = Die.findAttribute(dwarf::DW_AT_bit_size); if (V.getType() == DIEValue::isInteger) IntVal |= V.getDIEInteger().getValue() & 0xff; @@ -225,14 +224,14 @@ Die2BTFEntryInt::Die2BTFEntryInt(const DIE &Die) : Die2BTFEntry(Die) { } void Die2BTFEntryInt::completeData(class Dwarf2BTF &Dwarf2BTF) { - auto NameV = Die.findAttribute(dwarf::DW_AT_name); - auto TypeV = Die.findAttribute(dwarf::DW_AT_type); - auto Str = NameV.getDIEString().getString(); + auto NameV = Die.findAttribute(dwarf::DW_AT_name); + auto TypeV = Die.findAttribute(dwarf::DW_AT_type); + auto Str = NameV.getDIEString().getString(); - BTFType.name_off = Dwarf2BTF.addBTFString(Str); + BTFType.name_off = Dwarf2BTF.addBTFString(Str); - auto typeEntry = make_unique<BTFTypeEntryInt>(Id, BTFType, IntVal); - Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); + auto typeEntry = make_unique<BTFTypeEntryInt>(Id, BTFType, IntVal); + Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); } Die2BTFEntryEnum::Die2BTFEntryEnum(const DIE &Die) : Die2BTFEntry(Die) { @@ -275,8 +274,7 @@ void Die2BTFEntryEnum::completeData(class Dwarf2BTF &Dwarf2BTF) { Dwarf2BTF.addBTFTypeEntry(std::move(typeEntry)); } -Die2BTFEntryArray::Die2BTFEntryArray(const DIE &Die) : - Die2BTFEntry(Die) { +Die2BTFEntryArray::Die2BTFEntryArray(const DIE &Die) : Die2BTFEntry(Die) { BTFType.info = (BTF_KIND_ARRAY << 24); BTFType.size = 0; } @@ -289,7 +287,8 @@ void Die2BTFEntryArray::completeData(class Dwarf2BTF &Dwarf2BTF) { Str = NameV.getDIEString().getString(); BTFType.name_off = Dwarf2BTF.addBTFString(Str); - auto &ArrayTypeDie = Die.findAttribute(dwarf::DW_AT_type).getDIEEntry().getEntry(); + auto &ArrayTypeDie = + Die.findAttribute(dwarf::DW_AT_type).getDIEEntry().getEntry(); ArrayInfo.type = Dwarf2BTF.getTypeIndex(ArrayTypeDie); // The number of elements should count all subranges @@ -342,7 +341,6 @@ void Die2BTFEntryStruct::completeData(class Dwarf2BTF &Dwarf2BTF) { } else BTFType.name_off = 0; - for (auto &ChildDie : Die.children()) { if (ChildDie.getTag() != dwarf::DW_TAG_member) continue; @@ -456,7 +454,7 @@ void Die2BTFEntryFunc::completeData(class Dwarf2BTF &Dwarf2BTF) { } Dwarf2BTF::Dwarf2BTF(MCContext &Context, bool IsLittleEndian) - : OuterCtx(Context), IsLE(IsLittleEndian) { + : OuterCtx(Context), IsLE(IsLittleEndian) { BTFContext = make_unique<MCBTFContext>(); } @@ -470,7 +468,7 @@ void Dwarf2BTF::addTypeEntry(const DIE &Die) { auto TypeEntry = Die2BTFEntry::dieToBTFTypeEntry(Die); if (TypeEntry != nullptr) { TypeEntry->setId(TypeEntries.size() + 1); - DieToIdMap[const_cast<DIE*>(&Die)] = TypeEntry->getId(); + DieToIdMap[const_cast<DIE *>(&Die)] = TypeEntry->getId(); TypeEntries.push_back(std::move(TypeEntry)); } } @@ -500,4 +498,4 @@ void Dwarf2BTF::finish() { OuterCtx.setBTFContext(std::move(BTFContext)); } -} +} // namespace llvm diff --git a/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h b/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h index 125441d37b3..a472d68ed7e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h +++ b/llvm/lib/CodeGen/AsmPrinter/Dwarf2BTF.h @@ -26,7 +26,7 @@ class MCBTFContext; class Die2BTFEntry { protected: const DIE &Die; - size_t Id; /* type index in the BTF list, started from 1 */ + size_t Id; /* type index in the BTF list, started from 1 */ struct btf_type BTFType; public: @@ -54,7 +54,7 @@ public: // BTF_KIND_INT class Die2BTFEntryInt : public Die2BTFEntry { - __u32 IntVal; // encoding, offset, bits + __u32 IntVal; // encoding, offset, bits public: Die2BTFEntryInt(const DIE &Die); @@ -99,7 +99,7 @@ public: class Dwarf2BTF { std::vector<std::unique_ptr<Die2BTFEntry>> TypeEntries; - std::map<DIE*, size_t> DieToIdMap; + std::map<DIE *, size_t> DieToIdMap; std::unique_ptr<MCBTFContext> BTFContext; MCContext &OuterCtx; bool IsLE; @@ -110,14 +110,12 @@ public: void addDwarfCU(DwarfUnit *TheU); void finish(); __u32 getTypeIndex(DIE &Die) { - DIE *DiePtr = const_cast<DIE*>(&Die); + DIE *DiePtr = const_cast<DIE *>(&Die); assert((DieToIdMap.find(DiePtr) != DieToIdMap.end()) && "Die not added to in the BTFContext"); return DieToIdMap[DiePtr]; } - size_t addBTFString(std::string S) { - return BTFContext->addString(S); - } + size_t addBTFString(std::string S) { return BTFContext->addString(S); } void addBTFTypeEntry(std::unique_ptr<BTFTypeEntry> Entry); void addBTFFuncInfo(unsigned SecNameOff, BTFFuncInfo FuncInfo) { BTFContext->addFuncInfo(SecNameOff, FuncInfo); @@ -126,10 +124,10 @@ public: private: void addTypeEntry(const DIE &Die); bool alreadyAdded(DIE &Die) { - return DieToIdMap.find(const_cast<DIE*>(&Die)) != DieToIdMap.end(); + return DieToIdMap.find(const_cast<DIE *>(&Die)) != DieToIdMap.end(); } void completeData(); }; -} +} // namespace llvm #endif diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h index 9aafe2613f6..114f98f725d 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfFile.h @@ -137,9 +137,7 @@ public: return ScopeVariables; } - DenseMap<LexicalScope *, LabelList> &getScopeLabels() { - return ScopeLabels; - } + DenseMap<LexicalScope *, LabelList> &getScopeLabels() { return ScopeLabels; } DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { return AbstractSPDies; |