[llvm] [SHT_LLVM_BB_ADDR] Implement ELF and YAML support for Propeller CFG data in PGO analysis map. (PR #164914)
Rahman Lavaee via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 29 13:45:47 PDT 2025
https://github.com/rlavaee updated https://github.com/llvm/llvm-project/pull/164914
>From 4607f03b48963dfd9dcdc6a706a649cee99301f1 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Wed, 22 Oct 2025 20:16:14 +0000
Subject: [PATCH 01/16] Add Propeller cfg fields to ELFTypes.h
---
llvm/include/llvm/Object/ELFTypes.h | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index e9a417d3d4fb3..101ead91df4bd 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -834,6 +834,7 @@ struct BBAddrMap {
bool OmitBBEntries : 1;
bool CallsiteEndOffsets : 1;
bool BBHash : 1;
+ bool PropellerCfg : 1;
bool hasPGOAnalysis() const { return FuncEntryCount || BBFreq || BrProb; }
@@ -847,7 +848,8 @@ struct BBAddrMap {
(static_cast<uint8_t>(MultiBBRange) << 3) |
(static_cast<uint8_t>(OmitBBEntries) << 4) |
(static_cast<uint8_t>(CallsiteEndOffsets) << 5) |
- (static_cast<uint8_t>(BBHash) << 6);
+ (static_cast<uint8_t>(BBHash) << 6) |
+ (static_cast<uint8_t>(PropellerCfg) << 7);
}
// Decodes from minimum bit width representation and validates no
@@ -857,7 +859,7 @@ struct BBAddrMap {
static_cast<bool>(Val & (1 << 0)), static_cast<bool>(Val & (1 << 1)),
static_cast<bool>(Val & (1 << 2)), static_cast<bool>(Val & (1 << 3)),
static_cast<bool>(Val & (1 << 4)), static_cast<bool>(Val & (1 << 5)),
- static_cast<bool>(Val & (1 << 6))};
+ static_cast<bool>(Val & (1 << 6)), static_cast<bool>(Val & (1 << 7))};
if (Feat.encode() != Val)
return createStringError(
std::error_code(), "invalid encoding for BBAddrMap::Features: 0x%x",
@@ -867,10 +869,12 @@ struct BBAddrMap {
bool operator==(const Features &Other) const {
return std::tie(FuncEntryCount, BBFreq, BrProb, MultiBBRange,
- OmitBBEntries, CallsiteEndOffsets, BBHash) ==
+ OmitBBEntries, CallsiteEndOffsets, BBHash,
+ PropellerCfg) ==
std::tie(Other.FuncEntryCount, Other.BBFreq, Other.BrProb,
Other.MultiBBRange, Other.OmitBBEntries,
- Other.CallsiteEndOffsets, Other.BBHash);
+ Other.CallsiteEndOffsets, Other.BBHash,
+ Other.PropellerCfg);
}
};
@@ -1013,20 +1017,25 @@ struct PGOAnalysisMap {
uint32_t ID;
/// Branch Probability of the edge to this successor taken from MBPI.
BranchProbability Prob;
+ /// Edge frequency from Propeller.
+ uint32_t PropellerFreq;
bool operator==(const SuccessorEntry &Other) const {
- return std::tie(ID, Prob) == std::tie(Other.ID, Other.Prob);
+ return std::tie(ID, Prob, PropellerFreq) ==
+ std::tie(Other.ID, Other.Prob, Other.PropellerFreq);
}
};
/// Block frequency taken from MBFI
BlockFrequency BlockFreq;
+ /// Block frequency taken from Propeller.
+ uint32_t PropellerBlockFreq;
/// List of successors of the current block
llvm::SmallVector<SuccessorEntry, 2> Successors;
bool operator==(const PGOBBEntry &Other) const {
- return std::tie(BlockFreq, Successors) ==
- std::tie(Other.BlockFreq, Other.Successors);
+ return std::tie(BlockFreq, PropellerBlockFreq, Successors) ==
+ std::tie(Other.BlockFreq, PropellerBlockFreq, Other.Successors);
}
};
>From a0f61cb6fa9211fe109348d65c96bcfed7151ac8 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Wed, 22 Oct 2025 20:36:31 +0000
Subject: [PATCH 02/16] Add some changes in ELFYAML
---
llvm/include/llvm/ObjectYAML/ELFYAML.h | 2 ++
llvm/lib/ObjectYAML/ELFYAML.cpp | 2 ++
2 files changed, 4 insertions(+)
diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h
index a7c7c7c436dc2..1b7a4018369c3 100644
--- a/llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -203,8 +203,10 @@ struct PGOAnalysisMapEntry {
struct SuccessorEntry {
uint32_t ID;
llvm::yaml::Hex32 BrProb;
+ std::optional<uint32_t> PropellerBrFreq;
};
std::optional<uint64_t> BBFreq;
+ std::optional<uint32_t> PropellerBBFreq;
std::optional<std::vector<SuccessorEntry>> Successors;
};
std::optional<uint64_t> FuncEntryCount;
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index f8a84b075b779..f0226a2444060 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1920,6 +1920,7 @@ void MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry>::mapping(
IO &IO, ELFYAML::PGOAnalysisMapEntry::PGOBBEntry &E) {
assert(IO.getContext() && "The IO context is not initialized");
IO.mapOptional("BBFreq", E.BBFreq);
+ IO.mapOptional("PropellerBBFreq", E.PropellerBBFreq);
IO.mapOptional("Successors", E.Successors);
}
@@ -1929,6 +1930,7 @@ void MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry>::
assert(IO.getContext() && "The IO context is not initialized");
IO.mapRequired("ID", E.ID);
IO.mapRequired("BrProb", E.BrProb);
+ IO.mapOptional("PropellerBrFreq", E.PropellerBrFreq);
}
void MappingTraits<ELFYAML::GnuHashHeader>::mapping(IO &IO,
>From f367d593638b867642489c58c972cf50c280b52e Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Wed, 22 Oct 2025 21:32:12 +0000
Subject: [PATCH 03/16] More changes in YAML.
---
llvm/lib/Object/ELF.cpp | 15 +++++++++++++--
llvm/lib/ObjectYAML/ELFEmitter.cpp | 6 +++++-
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 6da97f9b3755d..1c4178c39b2b8 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -946,6 +946,10 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
uint64_t BBF = FeatEnable.BBFreq
? readULEB128As<uint64_t>(Data, Cur, ULEBSizeErr)
: 0;
+ uint32_t PropellerBBFreq =
+ FeatEnable.PropellerCfg
+ ? readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr)
+ : 0;
// Branch probability
llvm::SmallVector<PGOAnalysisMap::PGOBBEntry::SuccessorEntry, 2>
@@ -955,13 +959,20 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
for (uint64_t I = 0; I < SuccCount; ++I) {
uint32_t BBID = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
uint32_t BrProb = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
+ uint32_t PropellerFreq =
+ FeatEnable.PropellerCfg
+ ? readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr)
+ : 0;
+
if (PGOAnalyses)
- Successors.push_back({BBID, BranchProbability::getRaw(BrProb)});
+ Successors.push_back(
+ {BBID, BranchProbability::getRaw(BrProb), PropellerFreq});
}
}
if (PGOAnalyses)
- PGOBBEntries.push_back({BlockFrequency(BBF), std::move(Successors)});
+ PGOBBEntries.push_back(
+ {BlockFrequency(BBF), PropellerBBFreq, std::move(Successors)});
}
if (PGOAnalyses)
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 8b75fbe8291f0..d62a7349b9acf 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1556,11 +1556,15 @@ void ELFState<ELFT>::writeSectionContent(
for (const auto &PGOBBE : PGOBBEntries) {
if (PGOBBE.BBFreq)
SHeader.sh_size += CBA.writeULEB128(*PGOBBE.BBFreq);
+ if (FeatureOrErr->PropellerCfg || PGOBBE.PropellerBBFreq.has_value())
+ SHeader.sh_size += CBA.writeULEB128(PGOBBE.PropellerBBFreq.value_or(0));
if (PGOBBE.Successors) {
SHeader.sh_size += CBA.writeULEB128(PGOBBE.Successors->size());
- for (const auto &[ID, BrProb] : *PGOBBE.Successors) {
+ for (const auto &[ID, BrProb, PropellerBrFreq] : *PGOBBE.Successors) {
SHeader.sh_size += CBA.writeULEB128(ID);
SHeader.sh_size += CBA.writeULEB128(BrProb);
+ if (FeatureOrErr->PropellerCfg || PropellerBrFreq.has_value())
+ SHeader.sh_size += CBA.writeULEB128(PropellerBrFreq.value_or(0));
}
}
}
>From 3068d1389e33fa2dfd6220906e07de86ec976deb Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Thu, 23 Oct 2025 07:11:08 +0000
Subject: [PATCH 04/16] Add yaml2obj test.
---
.../ELF/bb-addr-map-pgo-analysis-map.yaml | 25 +++++++++++--------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
index a4cb572e6d993..7f3c742b1d125 100644
--- a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
@@ -6,8 +6,9 @@
# Case 4: Specify Entries.
# CHECK: Name: .llvm_bb_addr_map (1)
# CHECK: SectionData (
-# CHECK-NEXT: 0000: 02072000 00000000 0000010B 010203E8
-# CHECK-NEXT: 0010: 07E80702 0CEEDDBB F70E0D91 A2C48801
+# CHECK-NEXT: 0000: 02872000 00000000 0000010B 010203E8
+# CHECK-NEXT: 0010: 07E80764 020CEEDD BBF70E28 0D91A2C4
+# CHECK-NEXT: 0020: 880100
# CHECK-NEXT: )
# Case 7: Not including a field which is enabled in feature doesn't emit value
@@ -31,7 +32,7 @@ Sections:
Type: SHT_LLVM_BB_ADDR_MAP
Entries:
- Version: 2
- Feature: 0x7
+ Feature: 0x87
BBRanges:
- BaseAddress: 0x0000000000000020
BBEntries:
@@ -42,12 +43,14 @@ Sections:
PGOAnalyses:
- FuncEntryCount: 1000
PGOBBEntries:
- - BBFreq: 1000
+ - BBFreq: 1000
+ PropellerBBFreq: 100
Successors:
- - ID: 12
- BrProb: 0xeeeeeeee
- - ID: 13
- BrProb: 0x11111111
+ - ID: 12
+ BrProb: 0xeeeeeeee
+ PropellerBrFreq: 40
+ - ID: 13
+ BrProb: 0x11111111
## 2) According to feature we have FuncEntryCount but none is provided in yaml
- Name: '.llvm_bb_addr_map (2)'
@@ -65,8 +68,8 @@ Sections:
Metadata: 0x00000003
## Check that yaml2obj generates a warning when we use unsupported feature.
-# RUN: yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=INVALID-FEATURE
-# INVALID-FEATURE: warning: invalid encoding for BBAddrMap::Features: 0xf0
+# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=INVALID-FEATURE
+# INVALID-FEATURE: error: out of range hex8 number
--- !ELF
FileHeader:
@@ -79,4 +82,4 @@ Sections:
Entries:
- Version: 2
## Specify unsupported feature
- Feature: 0xF0
+ Feature: 0x100
>From 2c84241d49743f0ad1908713d01471630a9459ef Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Thu, 23 Oct 2025 07:44:59 +0000
Subject: [PATCH 05/16] Add obj2yaml support and test.
---
.../ELF/bb-addr-map-pgo-analysis-map.yaml | 49 +++++++++++--------
llvm/tools/obj2yaml/elf2yaml.cpp | 7 ++-
2 files changed, 35 insertions(+), 21 deletions(-)
diff --git a/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml b/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml
index 299bf463cf4bc..3d7cc15f1f26f 100644
--- a/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml
@@ -15,7 +15,7 @@
# VALID-NEXT: Type: SHT_LLVM_BB_ADDR_MAP
# VALID-NEXT: Entries:
# VALID-NEXT: - Version: 2
-# VALID-NEXT: Feature: 0x7
+# VALID-NEXT: Feature: 0x87
## The 'BaseAddress' field is omitted when it's zero.
# VALID-NEXT: BBRanges:
# VALID-NEXT: - BBEntries:
@@ -43,17 +43,23 @@
# VALID-NEXT: PGOAnalyses:
# VALID-NEXT: - FuncEntryCount: 100
# VALID-NEXT: PGOBBEntries:
-# VALID-NEXT: - BBFreq: 100
+# VALID-NEXT: - BBFreq: 100
+# VALID-NEXT: PropellerBBFreq: 10
# VALID-NEXT: Successors:
-# VALID-NEXT: - ID: 2
-# VALID-NEXT: BrProb: 0x80000000
-# VALID-NEXT: - ID: 4
-# VALID-NEXT: BrProb: 0x80000000
-# VALID-NEXT: - BBFreq: 50
+# VALID-NEXT: - ID: 2
+# VALID-NEXT: BrProb: 0x80000000
+# VALID-NEXT: PropellerBrFreq: 7
+# VALID-NEXT: - ID: 4
+# VALID-NEXT: BrProb: 0x80000000
+# VALID-NEXT: PropellerBrFreq: 0
+# VALID-NEXT: - BBFreq: 50
+# VALID-NEXT: PropellerBBFreq: 0
# VALID-NEXT: Successors:
-# VALID-NEXT: - ID: 4
-# VALID-NEXT: BrProb: 0xFFFFFFFF
-# VALID-NEXT: - BBFreq: 100
+# VALID-NEXT: - ID: 4
+# VALID-NEXT: BrProb: 0xFFFFFFFF
+# VALID-NEXT: PropellerBrFreq: 0
+# VALID-NEXT: - BBFreq: 100
+# VALID-NEXT: PropellerBBFreq: 3
# VALID-NEXT: Successors: []
# VALID-NEXT: PGOBBEntries:
# VALID-NEXT: - BBFreq: 20
@@ -69,7 +75,7 @@ Sections:
ShSize: [[SIZE=<none>]]
Entries:
- Version: 2
- Feature: 0x7
+ Feature: 0x87
BBRanges:
- BaseAddress: 0x0
BBEntries:
@@ -97,17 +103,20 @@ Sections:
PGOAnalyses:
- FuncEntryCount: 100
PGOBBEntries:
- - BBFreq: 100
+ - BBFreq: 100
+ PropellerBBFreq: 10
Successors:
- - ID: 2
- BrProb: 0x80000000
- - ID: 4
- BrProb: 0x80000000
- - BBFreq: 50
+ - ID: 2
+ BrProb: 0x80000000
+ PropellerBrFreq: 7
+ - ID: 4
+ BrProb: 0x80000000
+ - BBFreq: 50
Successors:
- - ID: 4
- BrProb: 0xFFFFFFFF
- - BBFreq: 100
+ - ID: 4
+ BrProb: 0xFFFFFFFF
+ - BBFreq: 100
+ PropellerBBFreq: 3
Successors: []
- PGOBBEntries:
- BBFreq: 20
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 68e18f6c79202..9e32a294554b5 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -972,6 +972,8 @@ ELFDumper<ELFT>::dumpBBAddrMapSection(const Elf_Shdr *Shdr) {
auto &PGOBBEntry = PGOBBEntries.emplace_back();
if (FeatureOrErr->BBFreq) {
PGOBBEntry.BBFreq = Data.getULEB128(Cur);
+ if (FeatureOrErr->PropellerCfg)
+ PGOBBEntry.PropellerBBFreq = Data.getULEB128(Cur);
if (!Cur)
break;
}
@@ -982,7 +984,10 @@ ELFDumper<ELFT>::dumpBBAddrMapSection(const Elf_Shdr *Shdr) {
for (uint64_t SuccIdx = 0; Cur && SuccIdx < SuccCount; ++SuccIdx) {
uint32_t ID = Data.getULEB128(Cur);
uint32_t BrProb = Data.getULEB128(Cur);
- SuccEntries.push_back({ID, BrProb});
+ std::optional<uint32_t> PropellerBrFreq;
+ if (FeatureOrErr->PropellerCfg)
+ PropellerBrFreq = Data.getULEB128(Cur);
+ SuccEntries.push_back({ID, BrProb, PropellerBrFreq});
}
}
}
>From 2ef8082395dc434d626eb990b19801c1e6e9c3e9 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Thu, 23 Oct 2025 23:47:11 +0000
Subject: [PATCH 06/16] Fix conflict.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 1 +
llvm/lib/Object/ELF.cpp | 7 ++++++-
llvm/lib/ObjectYAML/ELFEmitter.cpp | 2 +-
.../ELF/bb-addr-map-pgo-analysis-map.test | 17 +++++++++++------
llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml | 4 ++--
llvm/tools/llvm-readobj/ELFDumper.cpp | 4 ++++
6 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 8aa488f0efd8f..8f000dbba327a 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1444,6 +1444,7 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
// Use static_cast to avoid breakage of tests on windows.
static_cast<bool>(BBAddrMapSkipEmitBBEntries), HasCalls,
static_cast<bool>(EmitBBHash)};
+ false};
}
void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 1c4178c39b2b8..3ce096defc4fc 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -838,7 +838,7 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
Version = Data.getU8(Cur);
if (!Cur)
break;
- if (Version < 2 || Version > 4)
+ if (Version < 2 || Version > 5)
return createError("unsupported SHT_LLVM_BB_ADDR_MAP version: " +
Twine(static_cast<int>(Version)));
Feature = Data.getU8(Cur); // Feature byte
@@ -858,6 +858,11 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
"basic block hash feature is enabled: version = " +
Twine(static_cast<int>(Version)) +
" feature = " + Twine(static_cast<int>(Feature)));
+ if (FeatEnable.PropellerCfg && Version < 5)
+ return createError("version should be >= 5 for SHT_LLVM_BB_ADDR_MAP when "
+ "basic block hash feature is enabled: version = " +
+ Twine(static_cast<int>(Version)) +
+ " feature = " + Twine(static_cast<int>(Feature)));
uint32_t NumBlocksInBBRange = 0;
uint32_t NumBBRanges = 1;
typename ELFFile<ELFT>::uintX_t RangeBaseAddress = 0;
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index d62a7349b9acf..19bbaa9de2871 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1465,7 +1465,7 @@ void ELFState<ELFT>::writeSectionContent(
for (const auto &[Idx, E] : llvm::enumerate(*Section.Entries)) {
// Write version and feature values.
if (Section.Type == llvm::ELF::SHT_LLVM_BB_ADDR_MAP) {
- if (E.Version > 4)
+ if (E.Version > 5)
WithColor::warning() << "unsupported SHT_LLVM_BB_ADDR_MAP version: "
<< static_cast<int>(E.Version)
<< "; encoding using the most recent version";
diff --git a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test
index 5faafd4d83b2f..ca72a1e01a03c 100644
--- a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test
+++ b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test
@@ -15,7 +15,7 @@
## Check that a malformed section can be handled.
# RUN: yaml2obj %s -DBITS=32 -DSIZE=24 -o %t2.o
-# RUN: llvm-readobj %t2.o --bb-addr-map 2>&1 | FileCheck --match-full-lines %s -DOFFSET=0x00000018 -DFILE=%t2.o --check-prefix=TRUNCATED
+# RUN: llvm-readobj %t2.o --bb-addr-map 2>&1 | FileCheck --match-full-lines %s -DOFFSET=0x00000014 -DFILE=%t2.o --check-prefix=TRUNCATED
## Check that missing features can be handled.
# RUN: yaml2obj %s -DBITS=32 -DFEATURE=0x2 -o %t3.o
@@ -59,17 +59,20 @@
# CHECK-NEXT: {
# RAW-NEXT: Frequency: 100
# PRETTY-NEXT: Frequency: 1.0
+# CHECK-NEXT: Propeller Frequency: 10
# CHECK-NEXT: Successors [
# CHECK-NEXT: {
# CHECK-NEXT: ID: 2
# RAW-NEXT: Probability: 0x80000000
# PRETTY-NEXT: Probability: 0x80000000 / 0x80000000 = 100.00%
+# CHECK-NEXT: Propeller Probability: 7
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: }
# CHECK-NEXT: {
# RAW-NEXT: Frequency: 100
# PRETTY-NEXT: Frequency: 1.0
+# CHECK-NEXT: Propeller Frequency: 0
# CHECK-NEXT: Successors [
# CHECK-NEXT: ]
# CHECK-NEXT: }
@@ -172,8 +175,8 @@ Sections:
ShSize: [[SIZE=<none>]]
Link: .text
Entries:
- - Version: 2
- Feature: 0x7
+ - Version: 5
+ Feature: 0x87
BBRanges:
- BaseAddress: [[ADDR=0x11111]]
BBEntries:
@@ -197,10 +200,12 @@ Sections:
PGOAnalyses:
- FuncEntryCount: 100
PGOBBEntries:
- - BBFreq: 100
+ - BBFreq: 100
+ PropellerBBFreq: 10
Successors:
- - ID: 2
- BrProb: 0x80000000
+ - ID: 2
+ BrProb: 0x80000000
+ PropellerBrFreq: 7
- BBFreq: 100
Successors: []
- FuncEntryCount: 8888
diff --git a/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml b/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml
index 339e419b39458..05d77d67e4468 100644
--- a/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/bb-addr-map.yaml
@@ -220,7 +220,7 @@ Sections:
## Check that yaml2obj generates a warning when we use unsupported versions.
# RUN: yaml2obj --docnum=3 %s 2>&1 | FileCheck %s --check-prefix=INVALID-VERSION
-# INVALID-VERSION: warning: unsupported SHT_LLVM_BB_ADDR_MAP version: 5; encoding using the most recent version
+# INVALID-VERSION: warning: unsupported SHT_LLVM_BB_ADDR_MAP version: 6; encoding using the most recent version
--- !ELF
FileHeader:
@@ -232,4 +232,4 @@ Sections:
Type: SHT_LLVM_BB_ADDR_MAP
Entries:
## Specify unsupported version
- - Version: 5
+ - Version: 6
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 9c9b2dd79e686..4067125069d9e 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -8188,6 +8188,8 @@ void LLVMELFDumper<ELFT>::printBBAddrMaps(bool PrettyPGOAnalysis) {
} else {
W.printNumber("Frequency", PBBE.BlockFreq.getFrequency());
}
+ if (PAM.FeatEnable.PropellerCfg)
+ W.printNumber("Propeller Frequency", PBBE.PropellerBlockFreq);
}
if (PAM.FeatEnable.BrProb) {
@@ -8200,6 +8202,8 @@ void LLVMELFDumper<ELFT>::printBBAddrMaps(bool PrettyPGOAnalysis) {
} else {
W.printHex("Probability", Succ.Prob.getNumerator());
}
+ if (PAM.FeatEnable.PropellerCfg)
+ W.printNumber("Propeller Probability", Succ.PropellerFreq);
}
}
}
>From 71604d331499a71e51d589b0edad3c543150e4ea Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Thu, 23 Oct 2025 23:55:26 +0000
Subject: [PATCH 07/16] clang-format.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 8f000dbba327a..a6abe898bec48 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1444,7 +1444,8 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
// Use static_cast to avoid breakage of tests on windows.
static_cast<bool>(BBAddrMapSkipEmitBBEntries), HasCalls,
static_cast<bool>(EmitBBHash)};
- false};
+ false
+};
}
void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
>From a2347afa387ddaddd032e281e9f94df59560e8c0 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Fri, 24 Oct 2025 18:28:43 +0000
Subject: [PATCH 08/16] Add unit test.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 5 +-
llvm/unittests/Object/ELFObjectFileTest.cpp | 72 +++++++++++----------
llvm/unittests/Object/ELFTypesTest.cpp | 43 +++++-------
3 files changed, 56 insertions(+), 64 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index a6abe898bec48..7286cdbf358d9 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1443,9 +1443,8 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
MF.hasBBSections() && NumMBBSectionRanges > 1,
// Use static_cast to avoid breakage of tests on windows.
static_cast<bool>(BBAddrMapSkipEmitBBEntries), HasCalls,
- static_cast<bool>(EmitBBHash)};
- false
-};
+ static_cast<bool>(EmitBBHash),
+ false};
}
void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
diff --git a/llvm/unittests/Object/ELFObjectFileTest.cpp b/llvm/unittests/Object/ELFObjectFileTest.cpp
index d6a3ca53b2154..55a2942da5e1a 100644
--- a/llvm/unittests/Object/ELFObjectFileTest.cpp
+++ b/llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -531,7 +531,7 @@ TEST(ELFObjectFileTest, InvalidDecodeBBAddrMap) {
// Check that we can detect unsupported versions.
SmallString<128> UnsupportedVersionYamlString(CommonYamlString);
UnsupportedVersionYamlString += R"(
- - Version: 5
+ - Version: 6
BBRanges:
- BaseAddress: 0x11111
BBEntries:
@@ -543,7 +543,7 @@ TEST(ELFObjectFileTest, InvalidDecodeBBAddrMap) {
{
SCOPED_TRACE("unsupported version");
DoCheck(UnsupportedVersionYamlString,
- "unsupported SHT_LLVM_BB_ADDR_MAP version: 5");
+ "unsupported SHT_LLVM_BB_ADDR_MAP version: 6");
}
SmallString<128> ZeroBBRangesYamlString(CommonYamlString);
@@ -1181,8 +1181,8 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
Type: SHT_LLVM_BB_ADDR_MAP
# Link: 0 (by default, can be overriden)
Entries:
- - Version: 2
- Feature: 0x7
+ - Version: 5
+ Feature: 0x87
BBRanges:
- BaseAddress: 0x44444
BBEntries:
@@ -1205,7 +1205,8 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
PGOAnalyses:
- FuncEntryCount: 1000
PGOBBEntries:
- - BBFreq: 1000
+ - BBFreq: 1000
+ PropellerBBFreq: 50
Successors:
- ID: 1
BrProb: 0x22222222
@@ -1243,8 +1244,8 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
Type: SHT_LLVM_BB_ADDR_MAP
# Link: 0 (by default, can be overriden)
Entries:
- - Version: 2
- Feature: 0xc
+ - Version: 5
+ Feature: 0x8c
BBRanges:
- BaseAddress: 0x66666
BBEntries:
@@ -1265,8 +1266,9 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
PGOAnalyses:
- PGOBBEntries:
- Successors:
- - ID: 1
- BrProb: 0x22222222
+ - ID: 1
+ BrProb: 0x22222222
+ PropellerBrFreq: 7
- ID: 2
BrProb: 0xcccccccc
- Successors:
@@ -1278,24 +1280,24 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
BBAddrMap E1 = {
{{0x11111, {{1, 0x0, 0x1, {false, true, false, false, false}, {}, 0}}}}};
PGOAnalysisMap P1 = {
- 892, {}, {true, false, false, false, false, false, false}};
+ 892, {}, {true, false, false, false, false, false, false, false}};
BBAddrMap E2 = {
{{0x22222, {{2, 0x0, 0x2, {false, false, true, false, false}, {}, 0}}}}};
PGOAnalysisMap P2 = {{},
- {{BlockFrequency(343), {}}},
- {false, true, false, false, false, false, false}};
+ {{BlockFrequency(343), 0, {}}},
+ {false, true, false, false, false, false, false, false}};
BBAddrMap E3 = {
{{0x33333,
{{0, 0x0, 0x3, {false, true, true, false, false}, {}, 0},
{1, 0x3, 0x3, {false, false, true, false, false}, {}, 0},
{2, 0x6, 0x3, {false, false, false, false, false}, {}, 0}}}}};
PGOAnalysisMap P3 = {{},
- {{{},
- {{1, BranchProbability::getRaw(0x1111'1111)},
- {2, BranchProbability::getRaw(0xeeee'eeee)}}},
- {{}, {{2, BranchProbability::getRaw(0xffff'ffff)}}},
- {{}, {}}},
- {false, false, true, false, false, false, false}};
+ {{{}, 0,
+ {{1, BranchProbability::getRaw(0x1111'1111), 0},
+ {2, BranchProbability::getRaw(0xeeee'eeee), 0}}},
+ {{}, 0, {{2, BranchProbability::getRaw(0xffff'ffff), 0}}},
+ {{}, 0, {}}},
+ {false, false, true, false, false, false, false, false}};
BBAddrMap E4 = {
{{0x44444,
{{0, 0x0, 0x4, {false, false, false, true, true}, {}, 0},
@@ -1304,20 +1306,20 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
{3, 0xc, 0x4, {false, false, false, false, false}, {}, 0}}}}};
PGOAnalysisMap P4 = {
1000,
- {{BlockFrequency(1000),
- {{1, BranchProbability::getRaw(0x2222'2222)},
- {2, BranchProbability::getRaw(0x3333'3333)},
- {3, BranchProbability::getRaw(0xaaaa'aaaa)}}},
- {BlockFrequency(133),
- {{2, BranchProbability::getRaw(0x1111'1111)},
- {3, BranchProbability::getRaw(0xeeee'eeee)}}},
- {BlockFrequency(18), {{3, BranchProbability::getRaw(0xffff'ffff)}}},
- {BlockFrequency(1000), {}}},
- {true, true, true, false, false, false, false}};
+ {{BlockFrequency(1000), 50,
+ {{1, BranchProbability::getRaw(0x2222'2222), 0},
+ {2, BranchProbability::getRaw(0x3333'3333), 0},
+ {3, BranchProbability::getRaw(0xaaaa'aaaa), 0}}},
+ {BlockFrequency(133), 0,
+ {{2, BranchProbability::getRaw(0x1111'1111), 0},
+ {3, BranchProbability::getRaw(0xeeee'eeee), 0}}},
+ {BlockFrequency(18), 0, {{3, BranchProbability::getRaw(0xffff'ffff), 0}}},
+ {BlockFrequency(1000), 0, {}}},
+ {true, true, true, false, false, false, false, true}};
BBAddrMap E5 = {
{{0x55555, {{2, 0x0, 0x2, {false, false, true, false, false}, {}, 0}}}}};
PGOAnalysisMap P5 = {
- {}, {}, {false, false, false, false, false, false, false}};
+ {}, {}, {false, false, false, false, false, false, false, false}};
BBAddrMap E6 = {
{{0x66666,
{{0, 0x0, 0x6, {false, true, true, false, false}, {}, 0},
@@ -1325,12 +1327,12 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
{0x666661,
{{2, 0x0, 0x6, {false, false, false, false, false}, {}, 0}}}}};
PGOAnalysisMap P6 = {{},
- {{{},
- {{1, BranchProbability::getRaw(0x2222'2222)},
- {2, BranchProbability::getRaw(0xcccc'cccc)}}},
- {{}, {{2, BranchProbability::getRaw(0x8888'8888)}}},
- {{}, {}}},
- {false, false, true, true, false, false, false}};
+ {{{}, 0,
+ {{1, BranchProbability::getRaw(0x2222'2222), 7},
+ {2, BranchProbability::getRaw(0xcccc'cccc), 0}}},
+ {{}, 0, {{2, BranchProbability::getRaw(0x8888'8888), 0}}},
+ {{}, 0, {}}},
+ {false, false, true, true, false, false, false, true}};
std::vector<BBAddrMap> Section0BBAddrMaps = {E4, E5, E6};
std::vector<BBAddrMap> Section1BBAddrMaps = {E3};
diff --git a/llvm/unittests/Object/ELFTypesTest.cpp b/llvm/unittests/Object/ELFTypesTest.cpp
index 1765e15003963..9d0a410c5f883 100644
--- a/llvm/unittests/Object/ELFTypesTest.cpp
+++ b/llvm/unittests/Object/ELFTypesTest.cpp
@@ -101,22 +101,24 @@ static_assert(
"PGOAnalysisMap should use the same type for basic block ID as BBAddrMap");
TEST(ELFTypesTest, BBAddrMapFeaturesEncodingTest) {
- const std::array<BBAddrMap::Features, 12> Decoded = {
- {{false, false, false, false, false, false, false},
- {true, false, false, false, false, false, false},
- {false, true, false, false, false, false, false},
- {false, false, true, false, false, false, false},
- {false, false, false, true, false, false, false},
- {true, true, false, false, false, false, false},
- {false, true, true, false, false, false, false},
- {false, true, true, true, false, false, false},
- {true, true, true, true, false, false, false},
- {false, false, false, false, true, false, false},
- {false, false, false, false, false, true, false},
- {false, false, false, false, false, false, true}}};
- const std::array<uint8_t, 12> Encoded = {
+ const std::array<BBAddrMap::Features, 14> Decoded = {
+ {{false, false, false, false, false, false, false, false},
+ {true, false, false, false, false, false, false, false},
+ {false, true, false, false, false, false, false, false},
+ {false, false, true, false, false, false, false, false},
+ {false, false, false, true, false, false, false, false},
+ {true, true, false, false, false, false, false, false},
+ {false, true, true, false, false, false, false, false},
+ {false, true, true, true, false, false, false, false},
+ {true, true, true, true, false, false, false, false},
+ {false, false, false, false, true, false, false, false},
+ {false, false, false, false, false, true, false, false},
+ {false, false, false, false, false, false, true, false},
+ {false, false, false, false, false, false, false, true},
+ {false, false, false, false, false, false, true, true}}};
+ const std::array<uint8_t, 14> Encoded = {
{0b0000, 0b0001, 0b0010, 0b0100, 0b1000, 0b0011, 0b0110, 0b1110, 0b1111,
- 0b1'0000, 0b10'0000, 0b100'0000}};
+ 0b1'0000, 0b10'0000, 0b100'0000, 0b1000'0000, 0b1100'0000}};
for (const auto &[Feat, EncodedVal] : llvm::zip(Decoded, Encoded))
EXPECT_EQ(Feat.encode(), EncodedVal);
for (const auto &[Feat, EncodedVal] : llvm::zip(Decoded, Encoded)) {
@@ -126,14 +128,3 @@ TEST(ELFTypesTest, BBAddrMapFeaturesEncodingTest) {
EXPECT_EQ(*FeatEnableOrError, Feat);
}
}
-
-TEST(ELFTypesTest, BBAddrMapFeaturesInvalidEncodingTest) {
- const std::array<std::string, 2> Errors = {
- "invalid encoding for BBAddrMap::Features: 0x80",
- "invalid encoding for BBAddrMap::Features: 0xf0"};
- const std::array<uint8_t, 2> Values = {{0b1000'0000, 0b1111'0000}};
- for (const auto &[Val, Error] : llvm::zip(Values, Errors)) {
- EXPECT_THAT_ERROR(BBAddrMap::Features::decode(Val).takeError(),
- FailedWithMessage(Error));
- }
-}
>From 989b55eeb0586b9b0d1cecc04af2fcabec40949b Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Fri, 24 Oct 2025 18:28:53 +0000
Subject: [PATCH 09/16] clang-format.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 3 +-
llvm/unittests/Object/ELFObjectFileTest.cpp | 59 ++++++++++++---------
2 files changed, 34 insertions(+), 28 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 7286cdbf358d9..f65d88a669f13 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1443,8 +1443,7 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
MF.hasBBSections() && NumMBBSectionRanges > 1,
// Use static_cast to avoid breakage of tests on windows.
static_cast<bool>(BBAddrMapSkipEmitBBEntries), HasCalls,
- static_cast<bool>(EmitBBHash),
- false};
+ static_cast<bool>(EmitBBHash), false};
}
void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
diff --git a/llvm/unittests/Object/ELFObjectFileTest.cpp b/llvm/unittests/Object/ELFObjectFileTest.cpp
index 55a2942da5e1a..60378eb1ac8fd 100644
--- a/llvm/unittests/Object/ELFObjectFileTest.cpp
+++ b/llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -1291,31 +1291,36 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
{{0, 0x0, 0x3, {false, true, true, false, false}, {}, 0},
{1, 0x3, 0x3, {false, false, true, false, false}, {}, 0},
{2, 0x6, 0x3, {false, false, false, false, false}, {}, 0}}}}};
- PGOAnalysisMap P3 = {{},
- {{{}, 0,
- {{1, BranchProbability::getRaw(0x1111'1111), 0},
- {2, BranchProbability::getRaw(0xeeee'eeee), 0}}},
- {{}, 0, {{2, BranchProbability::getRaw(0xffff'ffff), 0}}},
- {{}, 0, {}}},
- {false, false, true, false, false, false, false, false}};
+ PGOAnalysisMap P3 = {
+ {},
+ {{{},
+ 0,
+ {{1, BranchProbability::getRaw(0x1111'1111), 0},
+ {2, BranchProbability::getRaw(0xeeee'eeee), 0}}},
+ {{}, 0, {{2, BranchProbability::getRaw(0xffff'ffff), 0}}},
+ {{}, 0, {}}},
+ {false, false, true, false, false, false, false, false}};
BBAddrMap E4 = {
{{0x44444,
{{0, 0x0, 0x4, {false, false, false, true, true}, {}, 0},
{1, 0x4, 0x4, {false, false, false, false, false}, {}, 0},
{2, 0x8, 0x4, {false, false, false, false, false}, {}, 0},
{3, 0xc, 0x4, {false, false, false, false, false}, {}, 0}}}}};
- PGOAnalysisMap P4 = {
- 1000,
- {{BlockFrequency(1000), 50,
- {{1, BranchProbability::getRaw(0x2222'2222), 0},
- {2, BranchProbability::getRaw(0x3333'3333), 0},
- {3, BranchProbability::getRaw(0xaaaa'aaaa), 0}}},
- {BlockFrequency(133), 0,
- {{2, BranchProbability::getRaw(0x1111'1111), 0},
- {3, BranchProbability::getRaw(0xeeee'eeee), 0}}},
- {BlockFrequency(18), 0, {{3, BranchProbability::getRaw(0xffff'ffff), 0}}},
- {BlockFrequency(1000), 0, {}}},
- {true, true, true, false, false, false, false, true}};
+ PGOAnalysisMap P4 = {1000,
+ {{BlockFrequency(1000),
+ 50,
+ {{1, BranchProbability::getRaw(0x2222'2222), 0},
+ {2, BranchProbability::getRaw(0x3333'3333), 0},
+ {3, BranchProbability::getRaw(0xaaaa'aaaa), 0}}},
+ {BlockFrequency(133),
+ 0,
+ {{2, BranchProbability::getRaw(0x1111'1111), 0},
+ {3, BranchProbability::getRaw(0xeeee'eeee), 0}}},
+ {BlockFrequency(18),
+ 0,
+ {{3, BranchProbability::getRaw(0xffff'ffff), 0}}},
+ {BlockFrequency(1000), 0, {}}},
+ {true, true, true, false, false, false, false, true}};
BBAddrMap E5 = {
{{0x55555, {{2, 0x0, 0x2, {false, false, true, false, false}, {}, 0}}}}};
PGOAnalysisMap P5 = {
@@ -1326,13 +1331,15 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
{1, 0x6, 0x6, {false, false, true, false, false}, {}, 0}}},
{0x666661,
{{2, 0x0, 0x6, {false, false, false, false, false}, {}, 0}}}}};
- PGOAnalysisMap P6 = {{},
- {{{}, 0,
- {{1, BranchProbability::getRaw(0x2222'2222), 7},
- {2, BranchProbability::getRaw(0xcccc'cccc), 0}}},
- {{}, 0, {{2, BranchProbability::getRaw(0x8888'8888), 0}}},
- {{}, 0, {}}},
- {false, false, true, true, false, false, false, true}};
+ PGOAnalysisMap P6 = {
+ {},
+ {{{},
+ 0,
+ {{1, BranchProbability::getRaw(0x2222'2222), 7},
+ {2, BranchProbability::getRaw(0xcccc'cccc), 0}}},
+ {{}, 0, {{2, BranchProbability::getRaw(0x8888'8888), 0}}},
+ {{}, 0, {}}},
+ {false, false, true, true, false, false, false, true}};
std::vector<BBAddrMap> Section0BBAddrMaps = {E4, E5, E6};
std::vector<BBAddrMap> Section1BBAddrMaps = {E3};
>From 4f9aee7ef4dfb543718b07120d15eb7edef0e3a6 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 27 Oct 2025 20:03:31 +0000
Subject: [PATCH 10/16] Improve comment for Propeller data.
---
llvm/include/llvm/Object/ELFTypes.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index 101ead91df4bd..31bf0ebcbeb3b 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -1017,7 +1017,7 @@ struct PGOAnalysisMap {
uint32_t ID;
/// Branch Probability of the edge to this successor taken from MBPI.
BranchProbability Prob;
- /// Edge frequency from Propeller.
+ /// Raw edge count from Propeller.
uint32_t PropellerFreq;
bool operator==(const SuccessorEntry &Other) const {
@@ -1028,8 +1028,8 @@ struct PGOAnalysisMap {
/// Block frequency taken from MBFI
BlockFrequency BlockFreq;
- /// Block frequency taken from Propeller.
- uint32_t PropellerBlockFreq;
+ /// Raw block count taken from Propeller.
+ uint32_t PropellerBlockFreq = 0;
/// List of successors of the current block
llvm::SmallVector<SuccessorEntry, 2> Successors;
>From ceb304f6f77cc59b55e4de2a129f92e74d66b720 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Tue, 28 Oct 2025 19:03:47 +0000
Subject: [PATCH 11/16] Rename Propeller to PostLink.
---
llvm/include/llvm/Object/ELFTypes.h | 24 +++++++++----------
llvm/include/llvm/ObjectYAML/ELFYAML.h | 4 ++--
llvm/lib/Object/ELF.cpp | 14 +++++------
llvm/lib/ObjectYAML/ELFEmitter.cpp | 10 ++++----
llvm/lib/ObjectYAML/ELFYAML.cpp | 4 ++--
.../ELF/bb-addr-map-pgo-analysis-map.test | 10 ++++----
.../ELF/bb-addr-map-pgo-analysis-map.yaml | 18 +++++++-------
.../ELF/bb-addr-map-pgo-analysis-map.yaml | 4 ++--
llvm/tools/llvm-readobj/ELFDumper.cpp | 8 +++----
llvm/tools/obj2yaml/elf2yaml.cpp | 12 +++++-----
llvm/unittests/Object/ELFObjectFileTest.cpp | 4 ++--
11 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index 31bf0ebcbeb3b..a06d57598bea3 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -834,7 +834,7 @@ struct BBAddrMap {
bool OmitBBEntries : 1;
bool CallsiteEndOffsets : 1;
bool BBHash : 1;
- bool PropellerCfg : 1;
+ bool PostLinkCfg : 1;
bool hasPGOAnalysis() const { return FuncEntryCount || BBFreq || BrProb; }
@@ -849,7 +849,7 @@ struct BBAddrMap {
(static_cast<uint8_t>(OmitBBEntries) << 4) |
(static_cast<uint8_t>(CallsiteEndOffsets) << 5) |
(static_cast<uint8_t>(BBHash) << 6) |
- (static_cast<uint8_t>(PropellerCfg) << 7);
+ (static_cast<uint8_t>(PostLinkCfg) << 7);
}
// Decodes from minimum bit width representation and validates no
@@ -870,11 +870,11 @@ struct BBAddrMap {
bool operator==(const Features &Other) const {
return std::tie(FuncEntryCount, BBFreq, BrProb, MultiBBRange,
OmitBBEntries, CallsiteEndOffsets, BBHash,
- PropellerCfg) ==
+ PostLinkCfg) ==
std::tie(Other.FuncEntryCount, Other.BBFreq, Other.BrProb,
Other.MultiBBRange, Other.OmitBBEntries,
Other.CallsiteEndOffsets, Other.BBHash,
- Other.PropellerCfg);
+ Other.PostLinkCfg);
}
};
@@ -1017,25 +1017,25 @@ struct PGOAnalysisMap {
uint32_t ID;
/// Branch Probability of the edge to this successor taken from MBPI.
BranchProbability Prob;
- /// Raw edge count from Propeller.
- uint32_t PropellerFreq;
+ /// Raw edge count from the post link profile.
+ uint64_t PostLinkFreq;
bool operator==(const SuccessorEntry &Other) const {
- return std::tie(ID, Prob, PropellerFreq) ==
- std::tie(Other.ID, Other.Prob, Other.PropellerFreq);
+ return std::tie(ID, Prob, PostLinkFreq) ==
+ std::tie(Other.ID, Other.Prob, Other.PostLinkFreq);
}
};
/// Block frequency taken from MBFI
BlockFrequency BlockFreq;
- /// Raw block count taken from Propeller.
- uint32_t PropellerBlockFreq = 0;
+ /// Raw block count taken from the post linke profile
+ uint64_t PostLinkBlockFreq = 0;
/// List of successors of the current block
llvm::SmallVector<SuccessorEntry, 2> Successors;
bool operator==(const PGOBBEntry &Other) const {
- return std::tie(BlockFreq, PropellerBlockFreq, Successors) ==
- std::tie(Other.BlockFreq, PropellerBlockFreq, Other.Successors);
+ return std::tie(BlockFreq, PostLinkBlockFreq, Successors) ==
+ std::tie(Other.BlockFreq, PostLinkBlockFreq, Other.Successors);
}
};
diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h
index 1b7a4018369c3..0859a9c22c039 100644
--- a/llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -203,10 +203,10 @@ struct PGOAnalysisMapEntry {
struct SuccessorEntry {
uint32_t ID;
llvm::yaml::Hex32 BrProb;
- std::optional<uint32_t> PropellerBrFreq;
+ std::optional<uint32_t> PostLinkBrFreq;
};
std::optional<uint64_t> BBFreq;
- std::optional<uint32_t> PropellerBBFreq;
+ std::optional<uint32_t> PostLinkBBFreq;
std::optional<std::vector<SuccessorEntry>> Successors;
};
std::optional<uint64_t> FuncEntryCount;
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 3ce096defc4fc..8c406ca224351 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -858,7 +858,7 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
"basic block hash feature is enabled: version = " +
Twine(static_cast<int>(Version)) +
" feature = " + Twine(static_cast<int>(Feature)));
- if (FeatEnable.PropellerCfg && Version < 5)
+ if (FeatEnable.PostLinkCfg && Version < 5)
return createError("version should be >= 5 for SHT_LLVM_BB_ADDR_MAP when "
"basic block hash feature is enabled: version = " +
Twine(static_cast<int>(Version)) +
@@ -951,8 +951,8 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
uint64_t BBF = FeatEnable.BBFreq
? readULEB128As<uint64_t>(Data, Cur, ULEBSizeErr)
: 0;
- uint32_t PropellerBBFreq =
- FeatEnable.PropellerCfg
+ uint32_t PostLinkBBFreq =
+ FeatEnable.PostLinkCfg
? readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr)
: 0;
@@ -964,20 +964,20 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
for (uint64_t I = 0; I < SuccCount; ++I) {
uint32_t BBID = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
uint32_t BrProb = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
- uint32_t PropellerFreq =
- FeatEnable.PropellerCfg
+ uint32_t PostLinkFreq =
+ FeatEnable.PostLinkCfg
? readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr)
: 0;
if (PGOAnalyses)
Successors.push_back(
- {BBID, BranchProbability::getRaw(BrProb), PropellerFreq});
+ {BBID, BranchProbability::getRaw(BrProb), PostLinkFreq});
}
}
if (PGOAnalyses)
PGOBBEntries.push_back(
- {BlockFrequency(BBF), PropellerBBFreq, std::move(Successors)});
+ {BlockFrequency(BBF), PostLinkBBFreq, std::move(Successors)});
}
if (PGOAnalyses)
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index 19bbaa9de2871..b7962faecaca1 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1556,15 +1556,15 @@ void ELFState<ELFT>::writeSectionContent(
for (const auto &PGOBBE : PGOBBEntries) {
if (PGOBBE.BBFreq)
SHeader.sh_size += CBA.writeULEB128(*PGOBBE.BBFreq);
- if (FeatureOrErr->PropellerCfg || PGOBBE.PropellerBBFreq.has_value())
- SHeader.sh_size += CBA.writeULEB128(PGOBBE.PropellerBBFreq.value_or(0));
+ if (FeatureOrErr->PostLinkCfg || PGOBBE.PostLinkBBFreq.has_value())
+ SHeader.sh_size += CBA.writeULEB128(PGOBBE.PostLinkBBFreq.value_or(0));
if (PGOBBE.Successors) {
SHeader.sh_size += CBA.writeULEB128(PGOBBE.Successors->size());
- for (const auto &[ID, BrProb, PropellerBrFreq] : *PGOBBE.Successors) {
+ for (const auto &[ID, BrProb, PostLinkBrFreq] : *PGOBBE.Successors) {
SHeader.sh_size += CBA.writeULEB128(ID);
SHeader.sh_size += CBA.writeULEB128(BrProb);
- if (FeatureOrErr->PropellerCfg || PropellerBrFreq.has_value())
- SHeader.sh_size += CBA.writeULEB128(PropellerBrFreq.value_or(0));
+ if (FeatureOrErr->PostLinkCfg || PostLinkBrFreq.has_value())
+ SHeader.sh_size += CBA.writeULEB128(PostLinkBrFreq.value_or(0));
}
}
}
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index f0226a2444060..d648b63d5dc49 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1920,7 +1920,7 @@ void MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry>::mapping(
IO &IO, ELFYAML::PGOAnalysisMapEntry::PGOBBEntry &E) {
assert(IO.getContext() && "The IO context is not initialized");
IO.mapOptional("BBFreq", E.BBFreq);
- IO.mapOptional("PropellerBBFreq", E.PropellerBBFreq);
+ IO.mapOptional("PostLinkBBFreq", E.PostLinkBBFreq);
IO.mapOptional("Successors", E.Successors);
}
@@ -1930,7 +1930,7 @@ void MappingTraits<ELFYAML::PGOAnalysisMapEntry::PGOBBEntry::SuccessorEntry>::
assert(IO.getContext() && "The IO context is not initialized");
IO.mapRequired("ID", E.ID);
IO.mapRequired("BrProb", E.BrProb);
- IO.mapOptional("PropellerBrFreq", E.PropellerBrFreq);
+ IO.mapOptional("PostLinkBrFreq", E.PostLinkBrFreq);
}
void MappingTraits<ELFYAML::GnuHashHeader>::mapping(IO &IO,
diff --git a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test
index ca72a1e01a03c..933495ecd877c 100644
--- a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test
+++ b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test
@@ -59,20 +59,20 @@
# CHECK-NEXT: {
# RAW-NEXT: Frequency: 100
# PRETTY-NEXT: Frequency: 1.0
-# CHECK-NEXT: Propeller Frequency: 10
+# CHECK-NEXT: PostLink Frequency: 10
# CHECK-NEXT: Successors [
# CHECK-NEXT: {
# CHECK-NEXT: ID: 2
# RAW-NEXT: Probability: 0x80000000
# PRETTY-NEXT: Probability: 0x80000000 / 0x80000000 = 100.00%
-# CHECK-NEXT: Propeller Probability: 7
+# CHECK-NEXT: PostLink Probability: 7
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: }
# CHECK-NEXT: {
# RAW-NEXT: Frequency: 100
# PRETTY-NEXT: Frequency: 1.0
-# CHECK-NEXT: Propeller Frequency: 0
+# CHECK-NEXT: PostLink Frequency: 0
# CHECK-NEXT: Successors [
# CHECK-NEXT: ]
# CHECK-NEXT: }
@@ -201,11 +201,11 @@ Sections:
- FuncEntryCount: 100
PGOBBEntries:
- BBFreq: 100
- PropellerBBFreq: 10
+ PostLinkBBFreq: 10
Successors:
- ID: 2
BrProb: 0x80000000
- PropellerBrFreq: 7
+ PostLinkBrFreq: 7
- BBFreq: 100
Successors: []
- FuncEntryCount: 8888
diff --git a/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml b/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml
index 3d7cc15f1f26f..645507af080cb 100644
--- a/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml
+++ b/llvm/test/tools/obj2yaml/ELF/bb-addr-map-pgo-analysis-map.yaml
@@ -44,22 +44,22 @@
# VALID-NEXT: - FuncEntryCount: 100
# VALID-NEXT: PGOBBEntries:
# VALID-NEXT: - BBFreq: 100
-# VALID-NEXT: PropellerBBFreq: 10
+# VALID-NEXT: PostLinkBBFreq: 10
# VALID-NEXT: Successors:
# VALID-NEXT: - ID: 2
# VALID-NEXT: BrProb: 0x80000000
-# VALID-NEXT: PropellerBrFreq: 7
+# VALID-NEXT: PostLinkBrFreq: 7
# VALID-NEXT: - ID: 4
# VALID-NEXT: BrProb: 0x80000000
-# VALID-NEXT: PropellerBrFreq: 0
+# VALID-NEXT: PostLinkBrFreq: 0
# VALID-NEXT: - BBFreq: 50
-# VALID-NEXT: PropellerBBFreq: 0
+# VALID-NEXT: PostLinkBBFreq: 0
# VALID-NEXT: Successors:
# VALID-NEXT: - ID: 4
# VALID-NEXT: BrProb: 0xFFFFFFFF
-# VALID-NEXT: PropellerBrFreq: 0
+# VALID-NEXT: PostLinkBrFreq: 0
# VALID-NEXT: - BBFreq: 100
-# VALID-NEXT: PropellerBBFreq: 3
+# VALID-NEXT: PostLinkBBFreq: 3
# VALID-NEXT: Successors: []
# VALID-NEXT: PGOBBEntries:
# VALID-NEXT: - BBFreq: 20
@@ -104,11 +104,11 @@ Sections:
- FuncEntryCount: 100
PGOBBEntries:
- BBFreq: 100
- PropellerBBFreq: 10
+ PostLinkBBFreq: 10
Successors:
- ID: 2
BrProb: 0x80000000
- PropellerBrFreq: 7
+ PostLinkBrFreq: 7
- ID: 4
BrProb: 0x80000000
- BBFreq: 50
@@ -116,7 +116,7 @@ Sections:
- ID: 4
BrProb: 0xFFFFFFFF
- BBFreq: 100
- PropellerBBFreq: 3
+ PostLinkBBFreq: 3
Successors: []
- PGOBBEntries:
- BBFreq: 20
diff --git a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
index 7f3c742b1d125..b3a2c1de04ddc 100644
--- a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
@@ -44,11 +44,11 @@ Sections:
- FuncEntryCount: 1000
PGOBBEntries:
- BBFreq: 1000
- PropellerBBFreq: 100
+ PostLinkBBFreq: 100
Successors:
- ID: 12
BrProb: 0xeeeeeeee
- PropellerBrFreq: 40
+ PostLinkBrFreq: 40
- ID: 13
BrProb: 0x11111111
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 32b3b4e469260..6f09da5a4099f 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -8188,8 +8188,8 @@ void LLVMELFDumper<ELFT>::printBBAddrMaps(bool PrettyPGOAnalysis) {
} else {
W.printNumber("Frequency", PBBE.BlockFreq.getFrequency());
}
- if (PAM.FeatEnable.PropellerCfg)
- W.printNumber("Propeller Frequency", PBBE.PropellerBlockFreq);
+ if (PAM.FeatEnable.PostLinkCfg)
+ W.printNumber("PostLink Frequency", PBBE.PostLinkBlockFreq);
}
if (PAM.FeatEnable.BrProb) {
@@ -8202,8 +8202,8 @@ void LLVMELFDumper<ELFT>::printBBAddrMaps(bool PrettyPGOAnalysis) {
} else {
W.printHex("Probability", Succ.Prob.getNumerator());
}
- if (PAM.FeatEnable.PropellerCfg)
- W.printNumber("Propeller Probability", Succ.PropellerFreq);
+ if (PAM.FeatEnable.PostLinkCfg)
+ W.printNumber("PostLink Probability", Succ.PostLinkFreq);
}
}
}
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 9e32a294554b5..3e95313d3805e 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -972,8 +972,8 @@ ELFDumper<ELFT>::dumpBBAddrMapSection(const Elf_Shdr *Shdr) {
auto &PGOBBEntry = PGOBBEntries.emplace_back();
if (FeatureOrErr->BBFreq) {
PGOBBEntry.BBFreq = Data.getULEB128(Cur);
- if (FeatureOrErr->PropellerCfg)
- PGOBBEntry.PropellerBBFreq = Data.getULEB128(Cur);
+ if (FeatureOrErr->PostLinkCfg)
+ PGOBBEntry.PostLinkBBFreq = Data.getULEB128(Cur);
if (!Cur)
break;
}
@@ -984,10 +984,10 @@ ELFDumper<ELFT>::dumpBBAddrMapSection(const Elf_Shdr *Shdr) {
for (uint64_t SuccIdx = 0; Cur && SuccIdx < SuccCount; ++SuccIdx) {
uint32_t ID = Data.getULEB128(Cur);
uint32_t BrProb = Data.getULEB128(Cur);
- std::optional<uint32_t> PropellerBrFreq;
- if (FeatureOrErr->PropellerCfg)
- PropellerBrFreq = Data.getULEB128(Cur);
- SuccEntries.push_back({ID, BrProb, PropellerBrFreq});
+ std::optional<uint32_t> PostLinkBrFreq;
+ if (FeatureOrErr->PostLinkCfg)
+ PostLinkBrFreq = Data.getULEB128(Cur);
+ SuccEntries.push_back({ID, BrProb, PostLinkBrFreq});
}
}
}
diff --git a/llvm/unittests/Object/ELFObjectFileTest.cpp b/llvm/unittests/Object/ELFObjectFileTest.cpp
index 60378eb1ac8fd..33a3398fd98ac 100644
--- a/llvm/unittests/Object/ELFObjectFileTest.cpp
+++ b/llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -1206,7 +1206,7 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
- FuncEntryCount: 1000
PGOBBEntries:
- BBFreq: 1000
- PropellerBBFreq: 50
+ PostLinkBBFreq: 50
Successors:
- ID: 1
BrProb: 0x22222222
@@ -1268,7 +1268,7 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
- Successors:
- ID: 1
BrProb: 0x22222222
- PropellerBrFreq: 7
+ PostLinkBrFreq: 7
- ID: 2
BrProb: 0xcccccccc
- Successors:
>From 9b92076f28206c75cdc6aeb5ec407c7d84d3fed9 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Tue, 28 Oct 2025 19:04:01 +0000
Subject: [PATCH 12/16] clang-format.
---
llvm/include/llvm/Object/ELFTypes.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index a06d57598bea3..319cf16b07e7e 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -869,8 +869,7 @@ struct BBAddrMap {
bool operator==(const Features &Other) const {
return std::tie(FuncEntryCount, BBFreq, BrProb, MultiBBRange,
- OmitBBEntries, CallsiteEndOffsets, BBHash,
- PostLinkCfg) ==
+ OmitBBEntries, CallsiteEndOffsets, BBHash, PostLinkCfg) ==
std::tie(Other.FuncEntryCount, Other.BBFreq, Other.BrProb,
Other.MultiBBRange, Other.OmitBBEntries,
Other.CallsiteEndOffsets, Other.BBHash,
>From 3832bf95351c8f5e7dea81ffe74bd0dd8d11a4ff Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Tue, 28 Oct 2025 19:25:18 +0000
Subject: [PATCH 13/16] Change comment to mention bolt and propeller as
examples of post link profiles.
---
llvm/include/llvm/Object/ELFTypes.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index 319cf16b07e7e..58b3804a0e6ec 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -1016,7 +1016,8 @@ struct PGOAnalysisMap {
uint32_t ID;
/// Branch Probability of the edge to this successor taken from MBPI.
BranchProbability Prob;
- /// Raw edge count from the post link profile.
+ /// Raw edge count from the post link profile (e.g., from bolt or
+ /// propeller).
uint64_t PostLinkFreq;
bool operator==(const SuccessorEntry &Other) const {
@@ -1027,7 +1028,8 @@ struct PGOAnalysisMap {
/// Block frequency taken from MBFI
BlockFrequency BlockFreq;
- /// Raw block count taken from the post linke profile
+ /// Raw block count taken from the post link profile (e.g., from bolt or
+ /// propeller).
uint64_t PostLinkBlockFreq = 0;
/// List of successors of the current block
llvm::SmallVector<SuccessorEntry, 2> Successors;
>From ffd870cad2cbe58aefc6bc3e3e7cf0ce039b114a Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Wed, 29 Oct 2025 06:07:18 +0000
Subject: [PATCH 14/16] Add primitive type default initializations.
---
llvm/include/llvm/Object/ELFTypes.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index 58b3804a0e6ec..c3e3d1ac96dec 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -1013,12 +1013,12 @@ struct PGOAnalysisMap {
/// probability associated with it.
struct SuccessorEntry {
/// Unique ID of this successor basic block.
- uint32_t ID;
+ uint32_t ID = 0;
/// Branch Probability of the edge to this successor taken from MBPI.
BranchProbability Prob;
/// Raw edge count from the post link profile (e.g., from bolt or
/// propeller).
- uint64_t PostLinkFreq;
+ uint64_t PostLinkFreq = 0;
bool operator==(const SuccessorEntry &Other) const {
return std::tie(ID, Prob, PostLinkFreq) ==
>From c113f78cae7bf376e7fb00148d76689b28c340a6 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Wed, 29 Oct 2025 20:13:05 +0000
Subject: [PATCH 15/16] Bump feature value to a 16byte value.
---
llvm/include/llvm/Object/ELFTypes.h | 4 ++--
llvm/include/llvm/ObjectYAML/ELFYAML.h | 2 +-
llvm/lib/Object/ELF.cpp | 6 +++---
llvm/lib/ObjectYAML/ELFEmitter.cpp | 10 ++++++++--
llvm/lib/ObjectYAML/ELFYAML.cpp | 2 +-
.../ELF/bb-addr-map-pgo-analysis-map.test | 2 +-
.../yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml | 6 +++---
llvm/tools/obj2yaml/elf2yaml.cpp | 4 ++--
llvm/unittests/Object/ELFObjectFileTest.cpp | 2 +-
llvm/unittests/Object/ELFTypesTest.cpp | 13 ++++++++++++-
10 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index c3e3d1ac96dec..949228bebca01 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -841,7 +841,7 @@ struct BBAddrMap {
bool hasPGOAnalysisBBData() const { return BBFreq || BrProb; }
// Encodes to minimum bit width representation.
- uint8_t encode() const {
+ uint16_t encode() const {
return (static_cast<uint8_t>(FuncEntryCount) << 0) |
(static_cast<uint8_t>(BBFreq) << 1) |
(static_cast<uint8_t>(BrProb) << 2) |
@@ -854,7 +854,7 @@ struct BBAddrMap {
// Decodes from minimum bit width representation and validates no
// unnecessary bits are used.
- static Expected<Features> decode(uint8_t Val) {
+ static Expected<Features> decode(uint16_t Val) {
Features Feat{
static_cast<bool>(Val & (1 << 0)), static_cast<bool>(Val & (1 << 1)),
static_cast<bool>(Val & (1 << 2)), static_cast<bool>(Val & (1 << 3)),
diff --git a/llvm/include/llvm/ObjectYAML/ELFYAML.h b/llvm/include/llvm/ObjectYAML/ELFYAML.h
index 0859a9c22c039..a8236ca37b5ed 100644
--- a/llvm/include/llvm/ObjectYAML/ELFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/ELFYAML.h
@@ -166,7 +166,7 @@ struct BBAddrMapEntry {
std::optional<llvm::yaml::Hex64> Hash;
};
uint8_t Version;
- llvm::yaml::Hex8 Feature;
+ llvm::yaml::Hex16 Feature;
struct BBRangeEntry {
llvm::yaml::Hex64 BaseAddress;
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 8c406ca224351..354c51d66419c 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -831,7 +831,7 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
};
uint8_t Version = 0;
- uint8_t Feature = 0;
+ uint16_t Feature = 0;
BBAddrMap::Features FeatEnable{};
while (!ULEBSizeErr && !MetadataDecodeErr && Cur &&
Cur.tell() < Content.size()) {
@@ -841,7 +841,7 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
if (Version < 2 || Version > 5)
return createError("unsupported SHT_LLVM_BB_ADDR_MAP version: " +
Twine(static_cast<int>(Version)));
- Feature = Data.getU8(Cur); // Feature byte
+ Feature = Version < 5 ? Data.getU8(Cur) : Data.getU16(Cur);
if (!Cur)
break;
auto FeatEnableOrErr = BBAddrMap::Features::decode(Feature);
@@ -860,7 +860,7 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
" feature = " + Twine(static_cast<int>(Feature)));
if (FeatEnable.PostLinkCfg && Version < 5)
return createError("version should be >= 5 for SHT_LLVM_BB_ADDR_MAP when "
- "basic block hash feature is enabled: version = " +
+ "post link cfg feature is enabled: version = " +
Twine(static_cast<int>(Version)) +
" feature = " + Twine(static_cast<int>(Feature)));
uint32_t NumBlocksInBBRange = 0;
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index b7962faecaca1..8530785d07c93 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -1470,8 +1470,14 @@ void ELFState<ELFT>::writeSectionContent(
<< static_cast<int>(E.Version)
<< "; encoding using the most recent version";
CBA.write(E.Version);
- CBA.write(E.Feature);
- SHeader.sh_size += 2;
+ SHeader.sh_size += 1;
+ if (E.Version < 5) {
+ CBA.write(static_cast<uint8_t>(E.Feature));
+ SHeader.sh_size += 1;
+ } else {
+ CBA.write<uint16_t>(E.Feature, ELFT::Endianness);
+ SHeader.sh_size += 2;
+ }
}
auto FeatureOrErr = llvm::object::BBAddrMap::Features::decode(E.Feature);
bool MultiBBRangeFeatureEnabled = false;
diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp
index d648b63d5dc49..e5e5fc20728e8 100644
--- a/llvm/lib/ObjectYAML/ELFYAML.cpp
+++ b/llvm/lib/ObjectYAML/ELFYAML.cpp
@@ -1886,7 +1886,7 @@ void MappingTraits<ELFYAML::BBAddrMapEntry>::mapping(
IO &IO, ELFYAML::BBAddrMapEntry &E) {
assert(IO.getContext() && "The IO context is not initialized");
IO.mapRequired("Version", E.Version);
- IO.mapOptional("Feature", E.Feature, Hex8(0));
+ IO.mapOptional("Feature", E.Feature, Hex16(0));
IO.mapOptional("NumBBRanges", E.NumBBRanges);
IO.mapOptional("BBRanges", E.BBRanges);
}
diff --git a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test
index 933495ecd877c..8e9d2271b8721 100644
--- a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test
+++ b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-pgo-analysis-map.test
@@ -15,7 +15,7 @@
## Check that a malformed section can be handled.
# RUN: yaml2obj %s -DBITS=32 -DSIZE=24 -o %t2.o
-# RUN: llvm-readobj %t2.o --bb-addr-map 2>&1 | FileCheck --match-full-lines %s -DOFFSET=0x00000014 -DFILE=%t2.o --check-prefix=TRUNCATED
+# RUN: llvm-readobj %t2.o --bb-addr-map 2>&1 | FileCheck --match-full-lines %s -DOFFSET=0x00000015 -DFILE=%t2.o --check-prefix=TRUNCATED
## Check that missing features can be handled.
# RUN: yaml2obj %s -DBITS=32 -DFEATURE=0x2 -o %t3.o
diff --git a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
index b3a2c1de04ddc..ac9c8d402b0a6 100644
--- a/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
+++ b/llvm/test/tools/yaml2obj/ELF/bb-addr-map-pgo-analysis-map.yaml
@@ -27,7 +27,7 @@ Sections:
## Test the following cases:
## 1) We can produce an .llvm_bb_addr_map section from a description with
-## Entries and PGO Analysis data.
+## Entries and PGO Analysis and Post Link data.
- Name: '.llvm_bb_addr_map (1)'
Type: SHT_LLVM_BB_ADDR_MAP
Entries:
@@ -68,8 +68,8 @@ Sections:
Metadata: 0x00000003
## Check that yaml2obj generates a warning when we use unsupported feature.
-# RUN: not yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=INVALID-FEATURE
-# INVALID-FEATURE: error: out of range hex8 number
+# RUN: yaml2obj --docnum=2 %s 2>&1 | FileCheck %s --check-prefix=INVALID-FEATURE
+# INVALID-FEATURE: warning: invalid encoding for BBAddrMap::Features: 0x100
--- !ELF
FileHeader:
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 3e95313d3805e..4364d15a8b455 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -895,7 +895,7 @@ ELFDumper<ELFT>::dumpBBAddrMapSection(const Elf_Shdr *Shdr) {
std::vector<ELFYAML::PGOAnalysisMapEntry> PGOAnalyses;
DataExtractor::Cursor Cur(0);
uint8_t Version = 0;
- uint8_t Feature = 0;
+ uint16_t Feature = 0;
uint64_t Address = 0;
while (Cur && Cur.tell() < Content.size()) {
if (Shdr->sh_type == ELF::SHT_LLVM_BB_ADDR_MAP) {
@@ -905,7 +905,7 @@ ELFDumper<ELFT>::dumpBBAddrMapSection(const Elf_Shdr *Shdr) {
errc::invalid_argument,
"invalid SHT_LLVM_BB_ADDR_MAP section version: " +
Twine(static_cast<int>(Version)));
- Feature = Data.getU8(Cur);
+ Feature = Version < 5 ? Data.getU8(Cur) : Data.getU16(Cur);
}
uint64_t NumBBRanges = 1;
uint64_t NumBlocks = 0;
diff --git a/llvm/unittests/Object/ELFObjectFileTest.cpp b/llvm/unittests/Object/ELFObjectFileTest.cpp
index 33a3398fd98ac..1e2955ae40a66 100644
--- a/llvm/unittests/Object/ELFObjectFileTest.cpp
+++ b/llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -1474,7 +1474,7 @@ TEST(ELFObjectFileTest, ReadPGOAnalysisMap) {
DoCheckFails(
TruncatedYamlString, /*TextSectionIndex=*/std::nullopt,
"unable to read SHT_LLVM_BB_ADDR_MAP section with index 6: "
- "unexpected end of data at offset 0xa while reading [0x3, 0xb)");
+ "unexpected end of data at offset 0xa while reading [0x4, 0xc)");
// Check that we can read the other section's bb-address-maps which are
// valid.
DoCheckSucceeds(TruncatedYamlString, /*TextSectionIndex=*/2,
diff --git a/llvm/unittests/Object/ELFTypesTest.cpp b/llvm/unittests/Object/ELFTypesTest.cpp
index 9d0a410c5f883..9e99b4a6d7bf3 100644
--- a/llvm/unittests/Object/ELFTypesTest.cpp
+++ b/llvm/unittests/Object/ELFTypesTest.cpp
@@ -116,7 +116,7 @@ TEST(ELFTypesTest, BBAddrMapFeaturesEncodingTest) {
{false, false, false, false, false, false, true, false},
{false, false, false, false, false, false, false, true},
{false, false, false, false, false, false, true, true}}};
- const std::array<uint8_t, 14> Encoded = {
+ const std::array<uint16_t, 14> Encoded = {
{0b0000, 0b0001, 0b0010, 0b0100, 0b1000, 0b0011, 0b0110, 0b1110, 0b1111,
0b1'0000, 0b10'0000, 0b100'0000, 0b1000'0000, 0b1100'0000}};
for (const auto &[Feat, EncodedVal] : llvm::zip(Decoded, Encoded))
@@ -128,3 +128,14 @@ TEST(ELFTypesTest, BBAddrMapFeaturesEncodingTest) {
EXPECT_EQ(*FeatEnableOrError, Feat);
}
}
+
+TEST(ELFTypesTest, BBAddrMapFeaturesInvalidEncodingTest) {
+ const std::array<std::string, 2> Errors = {
+ "invalid encoding for BBAddrMap::Features: 0x100",
+ "invalid encoding for BBAddrMap::Features: 0x1000"};
+ const std::array<uint16_t, 2> Values = {{0b1'0000'0000, 0b1'0000'0000'0000}};
+ for (const auto &[Val, Error] : llvm::zip(Values, Errors)) {
+ EXPECT_THAT_ERROR(BBAddrMap::Features::decode(Val).takeError(),
+ FailedWithMessage(Error));
+ }
+}
>From 028c3cb9b1ddbd9ec2e14901e9a520345b6d35c1 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Wed, 29 Oct 2025 20:45:20 +0000
Subject: [PATCH 16/16] Add a test for unsupported features.
---
.../ELF/bb-addr-map-feature-warning.test | 40 +++++++++++++++++++
1 file changed, 40 insertions(+)
create mode 100644 llvm/test/tools/llvm-readobj/ELF/bb-addr-map-feature-warning.test
diff --git a/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-feature-warning.test b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-feature-warning.test
new file mode 100644
index 0000000000000..2d01f422da8bd
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/bb-addr-map-feature-warning.test
@@ -0,0 +1,40 @@
+## This test checks that we output a warning when the specified version is too old to support the given features.
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readobj --bb-addr-map %t 2>&1 | FileCheck -DFILE=%t %s
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+
+
+# CHECK: BBAddrMap [
+# CHECK-NEXT: warning: '[[FILE]]': unable to dump SHT_LLVM_BB_ADDR_MAP section with index 1: version should be >= 3 for SHT_LLVM_BB_ADDR_MAP when callsite offsets feature is enabled: version = 2 feature = 32
+Sections:
+ - Name: '.llvm_bb_addr_map (1)'
+ Type: SHT_LLVM_BB_ADDR_MAP
+ Entries:
+ - Version: 2
+ Feature: 0x20
+
+
+
+# CHECK: BBAddrMap [
+# CHECK-NEXT: warning: '[[FILE]]': unable to dump SHT_LLVM_BB_ADDR_MAP section with index 2: version should be >= 4 for SHT_LLVM_BB_ADDR_MAP when basic block hash feature is enabled: version = 3 feature = 64
+
+ - Name: '.llvm_bb_addr_map (2)'
+ Type: SHT_LLVM_BB_ADDR_MAP
+ Entries:
+ - Version: 3
+ Feature: 0x40
+
+# CHECK: BBAddrMap [
+# CHECK-NEXT: warning: '[[FILE]]': unable to dump SHT_LLVM_BB_ADDR_MAP section with index 3: version should be >= 5 for SHT_LLVM_BB_ADDR_MAP when post link cfg feature is enabled: version = 4 feature = 128
+
+ - Name: '.llvm_bb_addr_map (3)'
+ Type: SHT_LLVM_BB_ADDR_MAP
+ Entries:
+ - Version: 4
+ Feature: 0x80
More information about the llvm-commits
mailing list