Skip to content

Commit 8ebe0a2

Browse files
committed
Use enum for handling Callgraph Flags
1 parent dfd37f2 commit 8ebe0a2

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5329,6 +5329,17 @@ getCallGraphSection(const object::ELFObjectFile<ELFT> &ObjF) {
53295329
return CallGraphSection;
53305330
}
53315331

5332+
namespace callgraph {
5333+
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
5334+
enum Flags : uint8_t {
5335+
None = 0,
5336+
IsIndirectTarget = 1u << 0,
5337+
HasDirectCallees = 1u << 1,
5338+
HasIndirectCallees = 1u << 2,
5339+
LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue*/ HasIndirectCallees)
5340+
};
5341+
} // namespace callgraph
5342+
53325343
template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
53335344
const Elf_Shdr *CGSection = findSectionByName(".llvm.callgraph");
53345345
if (!CGSection)
@@ -5357,26 +5368,27 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
53575368
while (Offset < CGSection->sh_size) {
53585369
Error CGSectionErr = Error::success();
53595370
uint8_t FormatVersionNumber = Data.getU8(&Offset, &CGSectionErr);
5360-
if (CGSectionErr)
5371+
if (CGSectionErr) {
53615372
reportError(std::move(CGSectionErr),
53625373
"While reading call graph info FormatVersionNumber");
5363-
5374+
}
53645375
if (FormatVersionNumber != 0) {
53655376
reportError(createError("Unknown format version value [" +
53665377
std::to_string(FormatVersionNumber) +
53675378
"] in .llvm.callgraph section."),
53685379
"Unknown value");
53695380
}
53705381

5371-
uint8_t Flags = Data.getU8(&Offset, &CGSectionErr);
5382+
uint8_t FlagsVal = Data.getU8(&Offset, &CGSectionErr);
53725383
if (CGSectionErr)
53735384
reportError(std::move(CGSectionErr),
53745385
"While reading call graph info's Flags");
5375-
if (Flags > 7) {
5386+
callgraph::Flags CGFlags = static_cast<callgraph::Flags>(FlagsVal);
5387+
if (FlagsVal > 7) {
53765388
reportError(
53775389
createError(
53785390
"Unknown Flags. Expected a value in the range [0-7] but found [" +
5379-
std::to_string(Flags) + "]"),
5391+
std::to_string(FlagsVal) + "]"),
53805392
"While reading call graph info's Flags");
53815393
}
53825394
uint64_t FuncAddrOffset = Offset;
@@ -5391,19 +5403,19 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
53915403
FunctionCallgraphInfo CGInfo;
53925404
CGInfo.FunctionAddress = IsETREL ? FuncAddrOffset : FuncAddr;
53935405
CGInfo.FormatVersionNumber = FormatVersionNumber;
5394-
bool IsIndirectTarget = Flags & 1; // LSB is set to 1 if indirect target.
5406+
bool IsIndirectTarget =
5407+
(CGFlags & callgraph::IsIndirectTarget) != callgraph::None;
53955408
CGInfo.IsIndirectTarget = IsIndirectTarget;
53965409
uint64_t TypeId = Data.getU64(&Offset, &CGSectionErr);
53975410
if (CGSectionErr)
53985411
PrintMalformedError(CGSectionErr, Twine::utohexstr(FuncAddr),
53995412
"indirect type id");
54005413
CGInfo.FunctionTypeId = TypeId;
5401-
54025414
if (IsIndirectTarget && TypeId == 0)
54035415
UnknownCount++;
54045416

54055417
bool HasDirectCallees =
5406-
Flags & (1u << 1); // LSB 1 is set to 1 if direct callees present.
5418+
(CGFlags & callgraph::HasDirectCallees) != callgraph::None;
54075419
if (HasDirectCallees) {
54085420
// Read number of direct call sites for this function.
54095421
uint64_t NumDirectCallees = Data.getULEB128(&Offset, &CGSectionErr);
@@ -5423,8 +5435,7 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
54235435
}
54245436

54255437
bool HasIndirectTypeIds =
5426-
Flags &
5427-
(1u << 2); // LSB 2 is set to 1 if indirect target type Ids present.
5438+
(CGFlags & callgraph::HasIndirectCallees) != callgraph::None;
54285439
if (HasIndirectTypeIds) {
54295440
uint64_t NumIndirectTargetTypeIDs =
54305441
Data.getULEB128(&Offset, &CGSectionErr);
@@ -5447,10 +5458,6 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
54475458
if (UnknownCount)
54485459
reportUniqueWarning(".llvm.callgraph section has unknown type id for " +
54495460
std::to_string(UnknownCount) + " indirect targets.");
5450-
5451-
// // Sort function info by function PC.
5452-
// llvm::sort(FuncCGInfos,
5453-
// [](const auto &A, const auto &B) { return A.first < B.first; });
54545461
return true;
54555462
}
54565463

0 commit comments

Comments
 (0)