Skip to content

Commit f67f8ea

Browse files
eddyz87mtardy
authored andcommitted
[BPF] Reorganize BTFDebug::visitMapDefType for better readability
Kernel BPF selftests passing. No change in BTF generated for kernel selftests, modulo some reorderings. Signed-off-by: Mahe Tardy <[email protected]>
1 parent 3819d8f commit f67f8ea

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

llvm/lib/Target/BPF/BTFDebug.cpp

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -957,38 +957,26 @@ void BTFDebug::visitMapDefType(const DIType *Ty, uint32_t &TypeId) {
957957
return;
958958
}
959959

960-
// MapDef type may be a struct type or a derived type
961-
const DIType *OrigTy = Ty;
962-
while (auto *DTy = dyn_cast<DIDerivedType>(Ty)) {
963-
auto Tag = DTy->getTag();
964-
if (Tag != dwarf::DW_TAG_typedef && Tag != dwarf::DW_TAG_const_type &&
965-
Tag != dwarf::DW_TAG_volatile_type &&
966-
Tag != dwarf::DW_TAG_restrict_type && Tag != dwarf::DW_TAG_pointer_type)
967-
break;
968-
Ty = DTy->getBaseType();
969-
}
970-
971-
const auto *CTy = dyn_cast<DICompositeType>(Ty);
972-
if (!CTy)
973-
return;
974-
975-
auto Tag = CTy->getTag();
976-
if ((Tag != dwarf::DW_TAG_structure_type &&
977-
Tag != dwarf::DW_TAG_array_type) ||
978-
CTy->isForwardDecl())
979-
return;
980-
981-
// Visit potential nested map array
982-
if (CTy->getTag() == dwarf::DW_TAG_array_type) {
983-
// Jump to the element type of the array
984-
visitMapDefType(CTy->getBaseType(), TypeId);
985-
} else {
960+
uint32_t TmpId;
961+
switch (Ty->getTag()) {
962+
case dwarf::DW_TAG_typedef:
963+
case dwarf::DW_TAG_const_type:
964+
case dwarf::DW_TAG_volatile_type:
965+
case dwarf::DW_TAG_restrict_type:
966+
case dwarf::DW_TAG_pointer_type:
967+
visitMapDefType(dyn_cast<DIDerivedType>(Ty)->getBaseType(), TmpId);
968+
break;
969+
case dwarf::DW_TAG_array_type:
970+
// Visit nested map array and jump to the element type
971+
visitMapDefType(dyn_cast<DICompositeType>(Ty)->getBaseType(), TmpId);
972+
break;
973+
case dwarf::DW_TAG_structure_type: {
986974
// Visit all struct members to ensure their types are visited.
975+
const auto *CTy = cast<DICompositeType>(Ty);
987976
const DINodeArray Elements = CTy->getElements();
988977
for (const auto *Element : Elements) {
989978
const auto *MemberType = cast<DIDerivedType>(Element);
990979
const DIType *MemberBaseType = MemberType->getBaseType();
991-
992980
// If the member is a composite type, that may indicate the currently
993981
// visited composite type is a wrapper, and the member represents the
994982
// actual map definition.
@@ -997,15 +985,19 @@ void BTFDebug::visitMapDefType(const DIType *Ty, uint32_t &TypeId) {
997985
// than as a regular composite type.
998986
const auto *MemberCTy = dyn_cast<DICompositeType>(MemberBaseType);
999987
if (MemberCTy) {
1000-
visitMapDefType(MemberBaseType, TypeId);
988+
visitMapDefType(MemberBaseType, TmpId);
1001989
} else {
1002990
visitTypeEntry(MemberBaseType);
1003991
}
1004992
}
993+
break;
994+
}
995+
default:
996+
break;
1005997
}
1006998

1007999
// Visit this type, struct or a const/typedef/volatile/restrict type
1008-
visitTypeEntry(OrigTy, TypeId, false, false);
1000+
visitTypeEntry(Ty, TypeId, false, false);
10091001
}
10101002

10111003
/// Read file contents from the actual file or from the source

0 commit comments

Comments
 (0)