Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Target/BPF/BTFDebug.cpp
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void BTFTypeInt::emitType(MCStreamer &OS) { | void BTFTypeInt::emitType(MCStreamer &OS) { | ||||
BTFTypeBase::emitType(OS); | BTFTypeBase::emitType(OS); | ||||
OS.AddComment("0x" + Twine::utohexstr(IntVal)); | OS.AddComment("0x" + Twine::utohexstr(IntVal)); | ||||
OS.emitInt32(IntVal); | OS.emitInt32(IntVal); | ||||
} | } | ||||
BTFTypeEnum::BTFTypeEnum(const DICompositeType *ETy, uint32_t VLen) : ETy(ETy) { | BTFTypeEnum::BTFTypeEnum(const DICompositeType *ETy, uint32_t VLen, | ||||
bool IsSigned) : ETy(ETy) { | |||||
Kind = BTF::BTF_KIND_ENUM; | Kind = BTF::BTF_KIND_ENUM; | ||||
BTFType.Info = Kind << 24 | VLen; | BTFType.Info = IsSigned << 31 | Kind << 24 | VLen; | ||||
BTFType.Size = roundupToBytes(ETy->getSizeInBits()); | BTFType.Size = roundupToBytes(ETy->getSizeInBits()); | ||||
} | } | ||||
void BTFTypeEnum::completeType(BTFDebug &BDebug) { | void BTFTypeEnum::completeType(BTFDebug &BDebug) { | ||||
if (IsCompleted) | if (IsCompleted) | ||||
return; | return; | ||||
IsCompleted = true; | IsCompleted = true; | ||||
Show All 19 Lines | |||||
void BTFTypeEnum::emitType(MCStreamer &OS) { | void BTFTypeEnum::emitType(MCStreamer &OS) { | ||||
BTFTypeBase::emitType(OS); | BTFTypeBase::emitType(OS); | ||||
for (const auto &Enum : EnumValues) { | for (const auto &Enum : EnumValues) { | ||||
OS.emitInt32(Enum.NameOff); | OS.emitInt32(Enum.NameOff); | ||||
OS.emitInt32(Enum.Val); | OS.emitInt32(Enum.Val); | ||||
} | } | ||||
} | } | ||||
BTFTypeEnum64::BTFTypeEnum64(const DICompositeType *ETy, uint32_t VLen, | |||||
bool IsSigned) : ETy(ETy) { | |||||
Kind = BTF::BTF_KIND_ENUM64; | |||||
BTFType.Info = IsSigned << 31 | Kind << 24 | VLen; | |||||
BTFType.Size = roundupToBytes(ETy->getSizeInBits()); | |||||
} | |||||
void BTFTypeEnum64::completeType(BTFDebug &BDebug) { | |||||
if (IsCompleted) | |||||
return; | |||||
IsCompleted = true; | |||||
BTFType.NameOff = BDebug.addString(ETy->getName()); | |||||
DINodeArray Elements = ETy->getElements(); | |||||
for (const auto Element : Elements) { | |||||
const auto *Enum = cast<DIEnumerator>(Element); | |||||
struct BTF::BTFEnum64 BTFEnum; | |||||
BTFEnum.NameOff = BDebug.addString(Enum->getName()); | |||||
uint64_t Value; | |||||
if (Enum->isUnsigned()) | |||||
Value = static_cast<uint64_t>(Enum->getValue().getZExtValue()); | |||||
else | |||||
Value = static_cast<uint64_t>(Enum->getValue().getSExtValue()); | |||||
BTFEnum.Val_Lo32 = Value; | |||||
BTFEnum.Val_Hi32 = Value >> 32; | |||||
EnumValues.push_back(BTFEnum); | |||||
} | |||||
} | |||||
void BTFTypeEnum64::emitType(MCStreamer &OS) { | |||||
BTFTypeBase::emitType(OS); | |||||
for (const auto &Enum : EnumValues) { | |||||
OS.emitInt32(Enum.NameOff); | |||||
OS.AddComment("0x" + Twine::utohexstr(Enum.Val_Lo32)); | |||||
OS.emitInt32(Enum.Val_Lo32); | |||||
OS.AddComment("0x" + Twine::utohexstr(Enum.Val_Hi32)); | |||||
OS.emitInt32(Enum.Val_Hi32); | |||||
} | |||||
} | |||||
BTFTypeArray::BTFTypeArray(uint32_t ElemTypeId, uint32_t NumElems) { | BTFTypeArray::BTFTypeArray(uint32_t ElemTypeId, uint32_t NumElems) { | ||||
Kind = BTF::BTF_KIND_ARRAY; | Kind = BTF::BTF_KIND_ARRAY; | ||||
BTFType.NameOff = 0; | BTFType.NameOff = 0; | ||||
BTFType.Info = Kind << 24; | BTFType.Info = Kind << 24; | ||||
BTFType.Size = 0; | BTFType.Size = 0; | ||||
ArrayInfo.ElemType = ElemTypeId; | ArrayInfo.ElemType = ElemTypeId; | ||||
ArrayInfo.Nelems = NumElems; | ArrayInfo.Nelems = NumElems; | ||||
▲ Show 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void BTFDebug::visitEnumType(const DICompositeType *CTy, uint32_t &TypeId) { | void BTFDebug::visitEnumType(const DICompositeType *CTy, uint32_t &TypeId) { | ||||
DINodeArray Elements = CTy->getElements(); | DINodeArray Elements = CTy->getElements(); | ||||
uint32_t VLen = Elements.size(); | uint32_t VLen = Elements.size(); | ||||
if (VLen > BTF::MAX_VLEN) | if (VLen > BTF::MAX_VLEN) | ||||
return; | return; | ||||
auto TypeEntry = std::make_unique<BTFTypeEnum>(CTy, VLen); | bool IsSigned = false; | ||||
unsigned NumBits = 32; | |||||
// No BaseType implies forward declaration in which case a | |||||
// BTFTypeEnum with Vlen = 0 is emitted. | |||||
if (CTy->getBaseType() != nullptr) { | |||||
const auto *BTy = cast<DIBasicType>(CTy->getBaseType()); | |||||
IsSigned = BTy->getEncoding() == dwarf::DW_ATE_signed || | |||||
BTy->getEncoding() == dwarf::DW_ATE_signed_char; | |||||
NumBits = BTy->getSizeInBits(); | |||||
} | |||||
if (NumBits <= 32) { | |||||
auto TypeEntry = std::make_unique<BTFTypeEnum>(CTy, VLen, IsSigned); | |||||
TypeId = addType(std::move(TypeEntry), CTy); | TypeId = addType(std::move(TypeEntry), CTy); | ||||
} else { | |||||
assert(NumBits == 64); | |||||
auto TypeEntry = std::make_unique<BTFTypeEnum64>(CTy, VLen, IsSigned); | |||||
TypeId = addType(std::move(TypeEntry), CTy); | |||||
} | |||||
// No need to visit base type as BTF does not encode it. | // No need to visit base type as BTF does not encode it. | ||||
} | } | ||||
/// Handle structure/union forward declarations. | /// Handle structure/union forward declarations. | ||||
void BTFDebug::visitFwdDeclType(const DICompositeType *CTy, bool IsUnion, | void BTFDebug::visitFwdDeclType(const DICompositeType *CTy, bool IsUnion, | ||||
uint32_t &TypeId) { | uint32_t &TypeId) { | ||||
auto TypeEntry = std::make_unique<BTFTypeFwd>(CTy->getName(), IsUnion); | auto TypeEntry = std::make_unique<BTFTypeFwd>(CTy->getName(), IsUnion); | ||||
TypeId = addType(std::move(TypeEntry), CTy); | TypeId = addType(std::move(TypeEntry), CTy); | ||||
▲ Show 20 Lines • Show All 864 Lines • Show Last 20 Lines |