Skip to content

Commit fab690d

Browse files
authored
[NFC][SHT_LLVM_BB_ADDR_MAP] Define and use constructor and accessors for BBAddrMap fields. (llvm#72689)
The fields are still kept as public for now since our tooling accesses them. Will change them to private visibility in a later patch.
1 parent be32e39 commit fab690d

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

llvm/include/llvm/Object/ELFTypes.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,6 @@ template <class ELFT> struct Elf_Mips_ABIFlags {
794794

795795
// Struct representing the BBAddrMap for one function.
796796
struct BBAddrMap {
797-
uint64_t Addr; // Function address
798797
// Struct representing the BBAddrMap information for one basic block.
799798
struct BBEntry {
800799
struct Metadata {
@@ -856,13 +855,24 @@ struct BBAddrMap {
856855
bool canFallThrough() const { return MD.CanFallThrough; }
857856
bool hasIndirectBranch() const { return MD.HasIndirectBranch; }
858857
};
859-
std::vector<BBEntry> BBEntries; // Basic block entries for this function.
858+
859+
BBAddrMap(uint64_t Addr, std::vector<BBEntry> BBEntries)
860+
: Addr(Addr), BBEntries(std::move(BBEntries)) {}
861+
862+
// Returns the address of the corresponding function.
863+
uint64_t getFunctionAddress() const { return Addr; }
864+
865+
// Returns the basic block entries for this function.
866+
const std::vector<BBEntry> &getBBEntries() const { return BBEntries; }
860867

861868
// Equality operator for unit testing.
862869
bool operator==(const BBAddrMap &Other) const {
863870
return Addr == Other.Addr && std::equal(BBEntries.begin(), BBEntries.end(),
864871
Other.BBEntries.begin());
865872
}
873+
874+
uint64_t Addr; // Function address
875+
std::vector<BBEntry> BBEntries; // Basic block entries for this function.
866876
};
867877

868878
} // end namespace object.

llvm/lib/Object/ELF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec,
745745
}
746746
BBEntries.push_back({ID, Offset, Size, *MetadataOrErr});
747747
}
748-
FunctionEntries.push_back({Address, std::move(BBEntries)});
748+
FunctionEntries.emplace_back(Address, std::move(BBEntries));
749749
}
750750
// Either Cur is in the error state, or we have an error in ULEBSizeErr or
751751
// MetadataDecodeErr (but not both), but we join all errors here to be safe.

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,8 +1275,8 @@ collectBBAddrMapLabels(const std::unordered_map<uint64_t, BBAddrMap> &AddrToBBAd
12751275
auto Iter = AddrToBBAddrMap.find(StartAddress);
12761276
if (Iter == AddrToBBAddrMap.end())
12771277
return;
1278-
for (const BBAddrMap::BBEntry &BBEntry : Iter->second.BBEntries) {
1279-
uint64_t BBAddress = BBEntry.Offset + Iter->second.Addr;
1278+
for (const BBAddrMap::BBEntry &BBEntry : Iter->second.getBBEntries()) {
1279+
uint64_t BBAddress = BBEntry.Offset + Iter->second.getFunctionAddress();
12801280
if (BBAddress >= EndAddress)
12811281
continue;
12821282
Labels[BBAddress].push_back(("BB" + Twine(BBEntry.ID)).str());

llvm/unittests/Object/ELFObjectFileTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,10 @@ TEST(ELFObjectFileTest, ReadBBAddrMap) {
661661
Metadata: 0x18
662662
)");
663663

664-
BBAddrMap E1 = {0x11111, {{1, 0x0, 0x1, {false, true, false, false, false}}}};
665-
BBAddrMap E2 = {0x22222, {{2, 0x0, 0x2, {false, false, true, false, false}}}};
666-
BBAddrMap E3 = {0x33333, {{0, 0x0, 0x3, {false, true, true, false, false}}}};
667-
BBAddrMap E4 = {0x44444, {{0, 0x0, 0x4, {false, false, false, true, true}}}};
664+
BBAddrMap E1(0x11111, {{1, 0x0, 0x1, {false, true, false, false, false}}});
665+
BBAddrMap E2(0x22222, {{2, 0x0, 0x2, {false, false, true, false, false}}});
666+
BBAddrMap E3(0x33333, {{0, 0x0, 0x3, {false, true, true, false, false}}});
667+
BBAddrMap E4(0x44444, {{0, 0x0, 0x4, {false, false, false, true, true}}});
668668

669669
std::vector<BBAddrMap> Section0BBAddrMaps = {E4};
670670
std::vector<BBAddrMap> Section1BBAddrMaps = {E3};

0 commit comments

Comments
 (0)