diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:03:47 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2023-07-26 19:04:23 +0000 |
| commit | 7fa27ce4a07f19b07799a767fc29416f3b625afb (patch) | |
| tree | 27825c83636c4de341eb09a74f49f5d38a15d165 /llvm/lib/Target/BPF/BTFDebug.cpp | |
| parent | e3b557809604d036af6e00c60f012c2025b59a5e (diff) | |
Diffstat (limited to 'llvm/lib/Target/BPF/BTFDebug.cpp')
| -rw-r--r-- | llvm/lib/Target/BPF/BTFDebug.cpp | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp index 9a873413db87..485ba88a4654 100644 --- a/llvm/lib/Target/BPF/BTFDebug.cpp +++ b/llvm/lib/Target/BPF/BTFDebug.cpp @@ -30,7 +30,7 @@ using namespace llvm; static const char *BTFKindStr[] = { #define HANDLE_BTF_KIND(ID, NAME) "BTF_KIND_" #NAME, -#include "BTF.def" +#include "llvm/DebugInfo/BTF/BTF.def" }; /// Emit a BTF common type. @@ -782,6 +782,17 @@ void BTFDebug::visitCompositeType(const DICompositeType *CTy, visitEnumType(CTy, TypeId); } +bool BTFDebug::IsForwardDeclCandidate(const DIType *Base) { + if (const auto *CTy = dyn_cast<DICompositeType>(Base)) { + auto CTag = CTy->getTag(); + if ((CTag == dwarf::DW_TAG_structure_type || + CTag == dwarf::DW_TAG_union_type) && + !CTy->getName().empty() && !CTy->isForwardDecl()) + return true; + } + return false; +} + /// Handle pointer, typedef, const, volatile, restrict and member types. void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId, bool CheckPointer, bool SeenPointer) { @@ -796,20 +807,15 @@ void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId, if (CheckPointer && SeenPointer) { const DIType *Base = DTy->getBaseType(); if (Base) { - if (const auto *CTy = dyn_cast<DICompositeType>(Base)) { - auto CTag = CTy->getTag(); - if ((CTag == dwarf::DW_TAG_structure_type || - CTag == dwarf::DW_TAG_union_type) && - !CTy->getName().empty() && !CTy->isForwardDecl()) { - /// Find a candidate, generate a fixup. Later on the struct/union - /// pointee type will be replaced with either a real type or - /// a forward declaration. - auto TypeEntry = std::make_unique<BTFTypeDerived>(DTy, Tag, true); - auto &Fixup = FixupDerivedTypes[CTy]; - Fixup.push_back(std::make_pair(DTy, TypeEntry.get())); - TypeId = addType(std::move(TypeEntry), DTy); - return; - } + if (IsForwardDeclCandidate(Base)) { + /// Find a candidate, generate a fixup. Later on the struct/union + /// pointee type will be replaced with either a real type or + /// a forward declaration. + auto TypeEntry = std::make_unique<BTFTypeDerived>(DTy, Tag, true); + auto &Fixup = FixupDerivedTypes[cast<DICompositeType>(Base)]; + Fixup.push_back(std::make_pair(DTy, TypeEntry.get())); + TypeId = addType(std::move(TypeEntry), DTy); + return; } } } @@ -844,6 +850,13 @@ void BTFDebug::visitDerivedType(const DIDerivedType *DTy, uint32_t &TypeId, visitTypeEntry(DTy->getBaseType(), TempTypeId, CheckPointer, SeenPointer); } +/// Visit a type entry. CheckPointer is true if the type has +/// one of its predecessors as one struct/union member. SeenPointer +/// is true if CheckPointer is true and one of its predecessors +/// is a pointer. The goal of CheckPointer and SeenPointer is to +/// do pruning for struct/union types so some of these types +/// will not be emitted in BTF and rather forward declarations +/// will be generated. void BTFDebug::visitTypeEntry(const DIType *Ty, uint32_t &TypeId, bool CheckPointer, bool SeenPointer) { if (!Ty || DIToIdMap.find(Ty) != DIToIdMap.end()) { @@ -888,6 +901,11 @@ void BTFDebug::visitTypeEntry(const DIType *Ty, uint32_t &TypeId, if (DIToIdMap.find(BaseTy) != DIToIdMap.end()) { DTy = dyn_cast<DIDerivedType>(BaseTy); } else { + if (CheckPointer && DTy->getTag() == dwarf::DW_TAG_pointer_type) { + SeenPointer = true; + if (IsForwardDeclCandidate(BaseTy)) + break; + } uint32_t TmpTypeId; visitTypeEntry(BaseTy, TmpTypeId, CheckPointer, SeenPointer); break; @@ -964,7 +982,7 @@ std::string BTFDebug::populateFileContent(const DISubprogram *SP) { FileName = std::string(File->getFilename()); // No need to populate the contends if it has been populated! - if (FileContent.find(FileName) != FileContent.end()) + if (FileContent.contains(FileName)) return FileName; std::vector<std::string> Content; |
