[llvm] Use the Propeller CFG profile in the PGO analysis map if it is available. (PR #163252)
Rahman Lavaee via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 2 17:41:45 PST 2025
https://github.com/rlavaee updated https://github.com/llvm/llvm-project/pull/163252
>From 6f84c9a7be27765a1b7836301f8eb659f6188d1b Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 13 Oct 2025 17:29:55 +0000
Subject: [PATCH 01/14] Emit the PGO analysis map based on the Propeller
profile.
---
.../CodeGen/BasicBlockSectionsProfileReader.h | 49 ++++++++---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 87 ++++++++++++++-----
.../BasicBlockSectionsProfileReader.cpp | 25 +-----
.../X86/basic-block-sections-pgo-features.ll | 64 ++++++++++++++
4 files changed, 167 insertions(+), 58 deletions(-)
create mode 100644 llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
index 7b1a5f5019589..0c12622e5698b 100644
--- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
+++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
@@ -42,18 +42,40 @@ struct BBClusterInfo {
unsigned PositionInCluster;
};
+// This represents the CFG profile data for a function.
+struct CFGProfile {
+ // Node counts for each basic block.
+ DenseMap<UniqueBBID, uint64_t> NodeCounts;
+ // Edge counts for each edge, stored as a nested map.
+ DenseMap<UniqueBBID, DenseMap<UniqueBBID, uint64_t>> EdgeCounts;
+
+ // Returns the profile count for the given basic block or zero if it does not
+ // exist.
+ uint64_t getNodeCount(const UniqueBBID &BBID) const {
+ return NodeCounts.lookup(BBID);
+ }
+
+ // Returns the profile count for the edge from `SrcBBID` to `SinkBBID` or
+ // zero if it does not exist.
+ uint64_t getEdgeCount(const UniqueBBID &SrcBBID,
+ const UniqueBBID &SinkBBID) const {
+ auto It = EdgeCounts.find(SrcBBID);
+ if (It == EdgeCounts.end())
+ return 0;
+ return It->second.lookup(SinkBBID);
+ }
+};
+
// This represents the raw input profile for one function.
-struct FunctionPathAndClusterInfo {
+struct FunctionProfile {
// BB Cluster information specified by `UniqueBBID`s.
SmallVector<BBClusterInfo> ClusterInfo;
// Paths to clone. A path a -> b -> c -> d implies cloning b, c, and d along
// the edge a -> b (a is not cloned). The index of the path in this vector
// determines the `UniqueBBID::CloneID` of the cloned blocks in that path.
SmallVector<SmallVector<unsigned>> ClonePaths;
- // Node counts for each basic block.
- DenseMap<UniqueBBID, uint64_t> NodeCounts;
- // Edge counts for each edge, stored as a nested map.
- DenseMap<UniqueBBID, DenseMap<UniqueBBID, uint64_t>> EdgeCounts;
+ // CFG profile data.
+ CFGProfile CFG;
// Hash for each basic block. The Hashes are stored for every original block
// (not cloned blocks), hence the map key being unsigned instead of
// UniqueBBID.
@@ -85,10 +107,14 @@ class BasicBlockSectionsProfileReader {
SmallVector<SmallVector<unsigned>>
getClonePathsForFunction(StringRef FuncName) const;
- // Returns the profile count for the edge from `SrcBBID` to `SinkBBID` in
- // function `FuncName` or zero if it does not exist.
- uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID,
- const UniqueBBID &SinkBBID) const;
+ // Returns a pointer to the CFGProfile for the given function.
+ // Returns nullptr if no profile data is available for the function.
+ const CFGProfile *getFunctionCFGProfile(StringRef FuncName) const {
+ auto It = ProgramPathAndClusterInfo.find(getAliasName(FuncName));
+ if (It == ProgramPathAndClusterInfo.end())
+ return nullptr;
+ return &It->second.CFG;
+ }
private:
StringRef getAliasName(StringRef FuncName) const {
@@ -136,7 +162,7 @@ class BasicBlockSectionsProfileReader {
// for (all or some of) its basic blocks. The cluster information for every
// basic block includes its cluster ID along with the position of the basic
// block in that cluster.
- StringMap<FunctionPathAndClusterInfo> ProgramPathAndClusterInfo;
+ StringMap<FunctionProfile> ProgramPathAndClusterInfo;
// Some functions have alias names. We use this map to find the main alias
// name which appears in ProgramPathAndClusterInfo as a key.
@@ -196,9 +222,6 @@ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
SmallVector<SmallVector<unsigned>>
getClonePathsForFunction(StringRef FuncName) const;
- uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID,
- const UniqueBBID &DestBBID) const;
-
// Initializes the FunctionNameToDIFilename map for the current module and
// then reads the profile for the matching functions.
bool doInitialization(Module &M) override;
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index f65d88a669f13..5a5a80aa09e97 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -37,6 +37,7 @@
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/CodeGen/BasicBlockSectionsProfileReader.h"
#include "llvm/CodeGen/GCMetadata.h"
#include "llvm/CodeGen/GCMetadataPrinter.h"
#include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h"
@@ -1544,38 +1545,80 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
assert(BBAddrMapVersion >= 2 &&
"PGOAnalysisMap only supports version 2 or later");
+ const BasicBlockSectionsProfileReader *BBSPR = nullptr;
+ if (auto *BBSPRPass =
+ getAnalysisIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>())
+ BBSPR = &BBSPRPass->getBBSPR();
+
+ const CFGProfile *FuncCFGProfile = nullptr;
+ if (BBSPR)
+ FuncCFGProfile = BBSPR->getFunctionCFGProfile(MF.getFunction().getName());
+
if (Features.FuncEntryCount) {
OutStreamer->AddComment("function entry count");
- auto MaybeEntryCount = MF.getFunction().getEntryCount();
- OutStreamer->emitULEB128IntValue(
- MaybeEntryCount ? MaybeEntryCount->getCount() : 0);
+ uint64_t EntryCount = 0;
+ if (FuncCFGProfile) {
+ EntryCount = FuncCFGProfile->getNodeCount(*MF.front().getBBID());
+ } else {
+ auto MaybeEntryCount = MF.getFunction().getEntryCount();
+ EntryCount = MaybeEntryCount ? MaybeEntryCount->getCount() : 0;
+ }
+ OutStreamer->emitULEB128IntValue(EntryCount);
}
- const MachineBlockFrequencyInfo *MBFI =
- Features.BBFreq
- ? &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI()
- : nullptr;
- const MachineBranchProbabilityInfo *MBPI =
- Features.BrProb
- ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI()
- : nullptr;
-
- if (Features.BBFreq || Features.BrProb) {
- for (const MachineBasicBlock &MBB : MF) {
- if (Features.BBFreq) {
- OutStreamer->AddComment("basic block frequency");
+
+ if (FuncCFGProfile) {
+ if (Features.BBFreq) {
+ // Basic Block Frequencies from BBSPR NodeCounts.
+ for (const MachineBasicBlock &MBB : MF) {
+ OutStreamer->AddComment("basic block frequency (from BBSPR)");
OutStreamer->emitULEB128IntValue(
- MBFI->getBlockFreq(&MBB).getFrequency());
+ FuncCFGProfile->getNodeCount(*MBB.getBBID()));
}
- if (Features.BrProb) {
- unsigned SuccCount = MBB.succ_size();
+ }
+ if (Features.BrProb) {
+ // Branch Probabilities from BBSPR EdgeCounts.
+ for (const MachineBasicBlock &MBB : MF) {
OutStreamer->AddComment("basic block successor count");
- OutStreamer->emitULEB128IntValue(SuccCount);
+ OutStreamer->emitULEB128IntValue(MBB.succ_size());
for (const MachineBasicBlock *SuccMBB : MBB.successors()) {
OutStreamer->AddComment("successor BB ID");
OutStreamer->emitULEB128IntValue(SuccMBB->getBBID()->BaseID);
- OutStreamer->AddComment("successor branch probability");
+ // Emit the numerator of the probability.
+ OutStreamer->AddComment("successor branch probability (from BBSPR)");
OutStreamer->emitULEB128IntValue(
- MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator());
+ FuncCFGProfile->getEdgeCount(*MBB.getBBID(), *SuccMBB->getBBID()));
+ }
+ }
+ }
+ } else {
+ // Fallback to MBFI and MBPI if BBSPR data is not available.
+ const MachineBlockFrequencyInfo *MBFI =
+ Features.BBFreq
+ ? &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI()
+ : nullptr;
+ const MachineBranchProbabilityInfo *MBPI =
+ Features.BrProb ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>()
+ .getMBPI()
+ : nullptr;
+
+ if (Features.BBFreq || Features.BrProb) {
+ for (const MachineBasicBlock &MBB : MF) {
+ if (Features.BBFreq) {
+ OutStreamer->AddComment("basic block frequency");
+ OutStreamer->emitULEB128IntValue(
+ MBFI->getBlockFreq(&MBB).getFrequency());
+ }
+ if (Features.BrProb) {
+ unsigned SuccCount = MBB.succ_size();
+ OutStreamer->AddComment("basic block successor count");
+ OutStreamer->emitULEB128IntValue(SuccCount);
+ for (const MachineBasicBlock *SuccMBB : MBB.successors()) {
+ OutStreamer->AddComment("successor BB ID");
+ OutStreamer->emitULEB128IntValue(SuccMBB->getBBID()->BaseID);
+ OutStreamer->AddComment("successor branch probability");
+ OutStreamer->emitULEB128IntValue(
+ MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator());
+ }
}
}
}
diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
index 485b44ae4c4aa..01d7f51dff54c 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -76,21 +76,6 @@ BasicBlockSectionsProfileReader::getClonePathsForFunction(
return ProgramPathAndClusterInfo.lookup(getAliasName(FuncName)).ClonePaths;
}
-uint64_t BasicBlockSectionsProfileReader::getEdgeCount(
- StringRef FuncName, const UniqueBBID &SrcBBID,
- const UniqueBBID &SinkBBID) const {
- auto It = ProgramPathAndClusterInfo.find(getAliasName(FuncName));
- if (It == ProgramPathAndClusterInfo.end())
- return 0;
- auto NodeIt = It->second.EdgeCounts.find(SrcBBID);
- if (NodeIt == It->second.EdgeCounts.end())
- return 0;
- auto EdgeIt = NodeIt->second.find(SinkBBID);
- if (EdgeIt == NodeIt->second.end())
- return 0;
- return EdgeIt->second;
-}
-
// Reads the version 1 basic block sections profile. Profile for each function
// is encoded as follows:
// m <module_name>
@@ -279,10 +264,10 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
Twine("unsigned integer expected: '") + CountStr + "'");
if (i == 0) {
// The first element represents the source and its total count.
- FI->second.NodeCounts[SrcBBID = *BBID] = Count;
+ FI->second.CFG.NodeCounts[SrcBBID = *BBID] = Count;
continue;
}
- FI->second.EdgeCounts[SrcBBID][*BBID] = Count;
+ FI->second.CFG.EdgeCounts[SrcBBID][*BBID] = Count;
}
}
continue;
@@ -506,12 +491,6 @@ BasicBlockSectionsProfileReaderWrapperPass::getClonePathsForFunction(
return BBSPR.getClonePathsForFunction(FuncName);
}
-uint64_t BasicBlockSectionsProfileReaderWrapperPass::getEdgeCount(
- StringRef FuncName, const UniqueBBID &SrcBBID,
- const UniqueBBID &SinkBBID) const {
- return BBSPR.getEdgeCount(FuncName, SrcBBID, SinkBBID);
-}
-
BasicBlockSectionsProfileReader &
BasicBlockSectionsProfileReaderWrapperPass::getBBSPR() {
return BBSPR;
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
new file mode 100644
index 0000000000000..e46dba51c716b
--- /dev/null
+++ b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
@@ -0,0 +1,64 @@
+; Verify PGO analysis map features with basic block sections profile.
+;
+; RUN: echo 'v1' > %t
+; RUN: echo 'f foo' >> %t
+; RUN: echo 'g 0:1000,1:800,2:200 1:800,3:800 2:200,3:200 3:1000' >> %t
+; RUN: echo 'c 0 1 2' >> %t
+;
+; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -basic-block-address-map -pgo-analysis-map=all | FileCheck %s
+
+define void @foo() nounwind !prof !0 {
+entry:
+ br label %bb1
+
+bb1:
+ br i1 undef, label %bb2, label %bb3, !prof !1
+
+bb2:
+ br label %bb3
+
+bb3:
+ ret void
+}
+
+!0 = !{!"function_entry_count", i64 1500}
+!1 = !{!"branch_weights", i32 1200, i32 300}
+
+; CHECK: .section .text.foo,"ax", at progbits
+; CHECK-LABEL: foo:
+; CHECK: .LBB_END0_0:
+; CHECK-LABEL: .LBB0_1:
+; CHECK: .LBB_END0_1:
+; CHECK-LABEL: .LBB0_2:
+; CHECK: .LBB_END0_2:
+; CHECK-LABEL: foo.cold:
+; CHECK: .LBB_END0_3:
+
+; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.foo
+; CHECK-NEXT: .byte 3 # version
+; CHECK-NEXT: .byte 15 # feature
+; CHECK: .quad .Lfunc_begin0 # base address
+; CHECK: .byte 0 # BB id
+; CHECK: .byte 1 # BB id
+; CHECK: .byte 2 # BB id
+; CHECK: .byte 3 # BB id
+
+; PGO Analysis Map
+; CHECK: .ascii "\350\007" # function entry count
+; CHECK-NEXT: .ascii "\350\007" # basic block frequency (from BBSPR)
+; CHECK-NEXT: .ascii "\240\006" # basic block frequency (from BBSPR)
+; CHECK-NEXT: .ascii "\310\001" # basic block frequency (from BBSPR)
+; CHECK-NEXT: .ascii "\350\007" # basic block frequency (from BBSPR)
+; CHECK-NEXT: .byte 1 # basic block successor count
+; CHECK-NEXT: .byte 1 # successor BB ID
+; CHECK-NEXT: .ascii "\240\006" # successor branch probability (from BBSPR)
+; CHECK-NEXT: .byte 2 # basic block successor count
+; CHECK-NEXT: .byte 2 # successor BB ID
+; CHECK-NEXT: .byte 0 # successor branch probability (from BBSPR)
+; CHECK-NEXT: .byte 3 # successor BB ID
+; CHECK-NEXT: .ascii "\240\006" # successor branch probability (from BBSPR)
+; CHECK-NEXT: .byte 1 # basic block successor count
+; CHECK-NEXT: .byte 3 # successor BB ID
+; CHECK-NEXT: .ascii "\310\001" # successor branch probability (from BBSPR)
+; CHECK-NEXT: .byte 0 # basic block successor count
+
>From 35b7100702aa3a4093307fd012756c8dbea3ab39 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 13 Oct 2025 17:30:07 +0000
Subject: [PATCH 02/14] clang-format.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 5a5a80aa09e97..3ac254cf259da 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1546,8 +1546,8 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
"PGOAnalysisMap only supports version 2 or later");
const BasicBlockSectionsProfileReader *BBSPR = nullptr;
- if (auto *BBSPRPass =
- getAnalysisIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>())
+ if (auto *BBSPRPass = getAnalysisIfAvailable<
+ BasicBlockSectionsProfileReaderWrapperPass>())
BBSPR = &BBSPRPass->getBBSPR();
const CFGProfile *FuncCFGProfile = nullptr;
@@ -1584,9 +1584,10 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
OutStreamer->AddComment("successor BB ID");
OutStreamer->emitULEB128IntValue(SuccMBB->getBBID()->BaseID);
// Emit the numerator of the probability.
- OutStreamer->AddComment("successor branch probability (from BBSPR)");
- OutStreamer->emitULEB128IntValue(
- FuncCFGProfile->getEdgeCount(*MBB.getBBID(), *SuccMBB->getBBID()));
+ OutStreamer->AddComment(
+ "successor branch probability (from BBSPR)");
+ OutStreamer->emitULEB128IntValue(FuncCFGProfile->getEdgeCount(
+ *MBB.getBBID(), *SuccMBB->getBBID()));
}
}
}
@@ -1597,9 +1598,10 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
? &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI()
: nullptr;
const MachineBranchProbabilityInfo *MBPI =
- Features.BrProb ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>()
- .getMBPI()
- : nullptr;
+ Features.BrProb
+ ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>()
+ .getMBPI()
+ : nullptr;
if (Features.BBFreq || Features.BrProb) {
for (const MachineBasicBlock &MBB : MF) {
>From aa37e156ec537ab3023452f3fdeeddd5c3dda809 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 13 Oct 2025 18:36:27 +0000
Subject: [PATCH 03/14] Refine and extend the test.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 73 +++++++------------
.../X86/basic-block-sections-pgo-features.ll | 64 +++++++++++-----
2 files changed, 72 insertions(+), 65 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3ac254cf259da..65e4f638892a8 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1545,15 +1545,28 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
assert(BBAddrMapVersion >= 2 &&
"PGOAnalysisMap only supports version 2 or later");
+ // We will emit the BBSPR profile data if availale. Otherwise, we fall back
+ // to MBFI and MBPI.
const BasicBlockSectionsProfileReader *BBSPR = nullptr;
if (auto *BBSPRPass = getAnalysisIfAvailable<
BasicBlockSectionsProfileReaderWrapperPass>())
BBSPR = &BBSPRPass->getBBSPR();
+
const CFGProfile *FuncCFGProfile = nullptr;
if (BBSPR)
FuncCFGProfile = BBSPR->getFunctionCFGProfile(MF.getFunction().getName());
+ const MachineBlockFrequencyInfo *MBFI =
+ Features.BBFreq
+ ? &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI()
+ : nullptr;
+ const MachineBranchProbabilityInfo *MBPI =
+ Features.BrProb
+ ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>()
+ .getMBPI()
+ : nullptr;
+
if (Features.FuncEntryCount) {
OutStreamer->AddComment("function entry count");
uint64_t EntryCount = 0;
@@ -1566,65 +1579,31 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
OutStreamer->emitULEB128IntValue(EntryCount);
}
- if (FuncCFGProfile) {
- if (Features.BBFreq) {
- // Basic Block Frequencies from BBSPR NodeCounts.
+ if (Features.BBFreq || Features.BrProb) {
for (const MachineBasicBlock &MBB : MF) {
- OutStreamer->AddComment("basic block frequency (from BBSPR)");
- OutStreamer->emitULEB128IntValue(
- FuncCFGProfile->getNodeCount(*MBB.getBBID()));
+
+ if (Features.BBFreq) {
+ OutStreamer->AddComment("basic block frequency");
+ uint64_t BlockFrequency = FuncCFGProfile ? FuncCFGProfile->getNodeCount(*MBB.getBBID()) : MBFI->getBlockFreq(&MBB).getFrequency();
+ OutStreamer->emitULEB128IntValue(BlockFrequency);
}
- }
if (Features.BrProb) {
- // Branch Probabilities from BBSPR EdgeCounts.
- for (const MachineBasicBlock &MBB : MF) {
OutStreamer->AddComment("basic block successor count");
OutStreamer->emitULEB128IntValue(MBB.succ_size());
for (const MachineBasicBlock *SuccMBB : MBB.successors()) {
OutStreamer->AddComment("successor BB ID");
OutStreamer->emitULEB128IntValue(SuccMBB->getBBID()->BaseID);
- // Emit the numerator of the probability.
OutStreamer->AddComment(
- "successor branch probability (from BBSPR)");
- OutStreamer->emitULEB128IntValue(FuncCFGProfile->getEdgeCount(
- *MBB.getBBID(), *SuccMBB->getBBID()));
+ "successor branch probability");
+ // For MPBI, we emit the numerator of the probability. For BBSPR, we
+ // emit the raw edge count.
+ uint64_t EdgeFrequency = FuncCFGProfile ? FuncCFGProfile->getEdgeCount(
+ *MBB.getBBID(), *SuccMBB->getBBID()) : MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator();
+ OutStreamer->emitULEB128IntValue(EdgeFrequency);
}
- }
}
- } else {
- // Fallback to MBFI and MBPI if BBSPR data is not available.
- const MachineBlockFrequencyInfo *MBFI =
- Features.BBFreq
- ? &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI()
- : nullptr;
- const MachineBranchProbabilityInfo *MBPI =
- Features.BrProb
- ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>()
- .getMBPI()
- : nullptr;
-
- if (Features.BBFreq || Features.BrProb) {
- for (const MachineBasicBlock &MBB : MF) {
- if (Features.BBFreq) {
- OutStreamer->AddComment("basic block frequency");
- OutStreamer->emitULEB128IntValue(
- MBFI->getBlockFreq(&MBB).getFrequency());
- }
- if (Features.BrProb) {
- unsigned SuccCount = MBB.succ_size();
- OutStreamer->AddComment("basic block successor count");
- OutStreamer->emitULEB128IntValue(SuccCount);
- for (const MachineBasicBlock *SuccMBB : MBB.successors()) {
- OutStreamer->AddComment("successor BB ID");
- OutStreamer->emitULEB128IntValue(SuccMBB->getBBID()->BaseID);
- OutStreamer->AddComment("successor branch probability");
- OutStreamer->emitULEB128IntValue(
- MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator());
- }
- }
- }
}
- }
+ }
}
OutStreamer->popSection();
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
index e46dba51c716b..ff97066659f4d 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
@@ -24,15 +24,7 @@ bb3:
!0 = !{!"function_entry_count", i64 1500}
!1 = !{!"branch_weights", i32 1200, i32 300}
-; CHECK: .section .text.foo,"ax", at progbits
-; CHECK-LABEL: foo:
-; CHECK: .LBB_END0_0:
-; CHECK-LABEL: .LBB0_1:
-; CHECK: .LBB_END0_1:
-; CHECK-LABEL: .LBB0_2:
-; CHECK: .LBB_END0_2:
-; CHECK-LABEL: foo.cold:
-; CHECK: .LBB_END0_3:
+;; Verify that foo gets its PGO map from its Propeller CFG profile.
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.foo
; CHECK-NEXT: .byte 3 # version
@@ -43,22 +35,58 @@ bb3:
; CHECK: .byte 2 # BB id
; CHECK: .byte 3 # BB id
-; PGO Analysis Map
+; PGO Analysis Map for foo
; CHECK: .ascii "\350\007" # function entry count
-; CHECK-NEXT: .ascii "\350\007" # basic block frequency (from BBSPR)
-; CHECK-NEXT: .ascii "\240\006" # basic block frequency (from BBSPR)
-; CHECK-NEXT: .ascii "\310\001" # basic block frequency (from BBSPR)
-; CHECK-NEXT: .ascii "\350\007" # basic block frequency (from BBSPR)
+; CHECK-NEXT: .ascii "\350\007" # basic block frequency
; CHECK-NEXT: .byte 1 # basic block successor count
; CHECK-NEXT: .byte 1 # successor BB ID
-; CHECK-NEXT: .ascii "\240\006" # successor branch probability (from BBSPR)
+; CHECK-NEXT: .ascii "\240\006" # successor branch probability
+; CHECK-NEXT: .ascii "\240\006" # basic block frequency
; CHECK-NEXT: .byte 2 # basic block successor count
; CHECK-NEXT: .byte 2 # successor BB ID
-; CHECK-NEXT: .byte 0 # successor branch probability (from BBSPR)
+; CHECK-NEXT: .byte 0 # successor branch probability
; CHECK-NEXT: .byte 3 # successor BB ID
-; CHECK-NEXT: .ascii "\240\006" # successor branch probability (from BBSPR)
+; CHECK-NEXT: .ascii "\240\006" # successor branch probability
+; CHECK-NEXT: .ascii "\310\001" # basic block frequency
; CHECK-NEXT: .byte 1 # basic block successor count
; CHECK-NEXT: .byte 3 # successor BB ID
-; CHECK-NEXT: .ascii "\310\001" # successor branch probability (from BBSPR)
+; CHECK-NEXT: .ascii "\310\001" # successor branch probability
+; CHECK-NEXT: .ascii "\350\007" # basic block frequency
; CHECK-NEXT: .byte 0 # basic block successor count
+define void @bar() nounwind !prof !2 {
+entry:
+ br i1 undef, label %bb1, label %bb2, !prof !3
+
+bb1:
+ ret void
+
+bb2:
+ ret void
+}
+
+!2 = !{!"function_entry_count", i64 80}
+!3 = !{!"branch_weights", i32 2, i32 78}
+
+;; Verify that we emit the PGO map for bar although it doesn't have Propeller profile.
+
+; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.bar
+; CHECK-NEXT: .byte 3 # version
+; CHECK-NEXT: .byte 7 # feature
+; CHECK: .quad .Lfunc_begin1 # function address
+; CHECK: .byte 0 # BB id
+; CHECK: .byte 1 # BB id
+; CHECK: .byte 2 # BB id
+
+; CHECK: .byte 80 # function entry count
+; CHECK-NEXT: .ascii "\200\200\200\200\200\200\200 " # basic block frequency
+; CHECK-NEXT: .byte 2 # basic block successor count
+; CHECK-NEXT: .byte 1 # successor BB ID
+; CHECK-NEXT: .ascii "\200\200\200\200\004" # successor branch probability
+; CHECK-NEXT: .byte 2 # successor BB ID
+; CHECK-NEXT: .ascii "\200\200\200\200\004" # successor branch probability
+; CHECK-NEXT: .ascii "\200\200\200\200\200\200\200\020" # basic block frequency
+; CHECK-NEXT: .byte 0 # basic block successor count
+; CHECK-NEXT: .ascii "\200\200\200\200\200\200\200\020" # basic block frequency
+; CHECK-NEXT: .byte 0 # basic block successor count
+
>From 233c44a050c963235d60d5b87e930dbe2af41193 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 13 Oct 2025 18:36:43 +0000
Subject: [PATCH 04/14] clang-format.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 42 +++++++++++-----------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 65e4f638892a8..e4d04ed3d3583 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1552,20 +1552,18 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
BasicBlockSectionsProfileReaderWrapperPass>())
BBSPR = &BBSPRPass->getBBSPR();
-
const CFGProfile *FuncCFGProfile = nullptr;
if (BBSPR)
FuncCFGProfile = BBSPR->getFunctionCFGProfile(MF.getFunction().getName());
const MachineBlockFrequencyInfo *MBFI =
- Features.BBFreq
- ? &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI()
- : nullptr;
- const MachineBranchProbabilityInfo *MBPI =
- Features.BrProb
- ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>()
- .getMBPI()
- : nullptr;
+ Features.BBFreq
+ ? &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI()
+ : nullptr;
+ const MachineBranchProbabilityInfo *MBPI =
+ Features.BrProb
+ ? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI()
+ : nullptr;
if (Features.FuncEntryCount) {
OutStreamer->AddComment("function entry count");
@@ -1579,31 +1577,35 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
OutStreamer->emitULEB128IntValue(EntryCount);
}
- if (Features.BBFreq || Features.BrProb) {
- for (const MachineBasicBlock &MBB : MF) {
+ if (Features.BBFreq || Features.BrProb) {
+ for (const MachineBasicBlock &MBB : MF) {
- if (Features.BBFreq) {
+ if (Features.BBFreq) {
OutStreamer->AddComment("basic block frequency");
- uint64_t BlockFrequency = FuncCFGProfile ? FuncCFGProfile->getNodeCount(*MBB.getBBID()) : MBFI->getBlockFreq(&MBB).getFrequency();
+ uint64_t BlockFrequency =
+ FuncCFGProfile ? FuncCFGProfile->getNodeCount(*MBB.getBBID())
+ : MBFI->getBlockFreq(&MBB).getFrequency();
OutStreamer->emitULEB128IntValue(BlockFrequency);
}
- if (Features.BrProb) {
+ if (Features.BrProb) {
OutStreamer->AddComment("basic block successor count");
OutStreamer->emitULEB128IntValue(MBB.succ_size());
for (const MachineBasicBlock *SuccMBB : MBB.successors()) {
OutStreamer->AddComment("successor BB ID");
OutStreamer->emitULEB128IntValue(SuccMBB->getBBID()->BaseID);
- OutStreamer->AddComment(
- "successor branch probability");
+ OutStreamer->AddComment("successor branch probability");
// For MPBI, we emit the numerator of the probability. For BBSPR, we
// emit the raw edge count.
- uint64_t EdgeFrequency = FuncCFGProfile ? FuncCFGProfile->getEdgeCount(
- *MBB.getBBID(), *SuccMBB->getBBID()) : MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator();
+ uint64_t EdgeFrequency =
+ FuncCFGProfile
+ ? FuncCFGProfile->getEdgeCount(*MBB.getBBID(),
+ *SuccMBB->getBBID())
+ : MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator();
OutStreamer->emitULEB128IntValue(EdgeFrequency);
}
- }
- }
}
+ }
+ }
}
OutStreamer->popSection();
>From c9444c7ee626d918d8d7dffbeff90255b4216acc Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 13 Oct 2025 19:38:48 +0000
Subject: [PATCH 05/14] Fix a test comment.
---
llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
index ff97066659f4d..f535b9f6bd9d2 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
@@ -68,7 +68,7 @@ bb2:
!2 = !{!"function_entry_count", i64 80}
!3 = !{!"branch_weights", i32 2, i32 78}
-;; Verify that we emit the PGO map for bar although it doesn't have Propeller profile.
+;; Verify that we emit the PGO map for bar which doesn't have Propeller profile.
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.bar
; CHECK-NEXT: .byte 3 # version
>From 9cea27e4695dae0092794a2715cfecdd43466549 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 13 Oct 2025 22:36:44 +0000
Subject: [PATCH 06/14] Add flag to enable using the Propeller profile in PGO
analysis map.
---
.../CodeGen/BasicBlockSectionsProfileReader.h | 12 ++++++-----
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 20 ++++++++++---------
.../BasicBlockSectionsProfileReader.cpp | 5 +++++
.../X86/basic-block-sections-pgo-features.ll | 2 +-
4 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
index 0c12622e5698b..df4339fda0d5c 100644
--- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
+++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
@@ -43,7 +43,7 @@ struct BBClusterInfo {
};
// This represents the CFG profile data for a function.
-struct CFGProfile {
+struct CfgProfile {
// Node counts for each basic block.
DenseMap<UniqueBBID, uint64_t> NodeCounts;
// Edge counts for each edge, stored as a nested map.
@@ -74,8 +74,8 @@ struct FunctionProfile {
// the edge a -> b (a is not cloned). The index of the path in this vector
// determines the `UniqueBBID::CloneID` of the cloned blocks in that path.
SmallVector<SmallVector<unsigned>> ClonePaths;
- // CFG profile data.
- CFGProfile CFG;
+ // Cfg profile data (block and edge frequencies).
+ CfgProfile CFG;
// Hash for each basic block. The Hashes are stored for every original block
// (not cloned blocks), hence the map key being unsigned instead of
// UniqueBBID.
@@ -107,9 +107,9 @@ class BasicBlockSectionsProfileReader {
SmallVector<SmallVector<unsigned>>
getClonePathsForFunction(StringRef FuncName) const;
- // Returns a pointer to the CFGProfile for the given function.
+ // Returns a pointer to the CfgProfile for the given function.
// Returns nullptr if no profile data is available for the function.
- const CFGProfile *getFunctionCFGProfile(StringRef FuncName) const {
+ const CfgProfile *getFunctionCfgProfile(StringRef FuncName) const {
auto It = ProgramPathAndClusterInfo.find(getAliasName(FuncName));
if (It == ProgramPathAndClusterInfo.end())
return nullptr;
@@ -222,6 +222,8 @@ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
SmallVector<SmallVector<unsigned>>
getClonePathsForFunction(StringRef FuncName) const;
+ const CfgProfile *getFunctionCfgProfile(StringRef FuncName) const;
+
// Initializes the FunctionNameToDIFilename map for the current module and
// then reads the profile for the matching functions.
bool doInitialization(Module &M) override;
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index e4d04ed3d3583..45e3bfc2f0847 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -167,6 +167,10 @@ static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
"Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is "
"extracted from PGO related analysis."));
+static cl::opt<bool> PgoAnalysisMapUsePropellerCfg("pgo-analysis-map-use-propeller-cfg",
+cl::desc("If available, use the Propeller cfg profile in the PGO analysis map."),
+cl::Hidden, cl::init(false));
+
static cl::opt<bool> BBAddrMapSkipEmitBBEntries(
"basic-block-address-map-skip-bb-entries",
cl::desc("Skip emitting basic block entries in the SHT_LLVM_BB_ADDR_MAP "
@@ -480,6 +484,7 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
if (EmitBBHash)
AU.addRequired<MachineBlockHashInfo>();
+ AU.addUsedIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>();
}
bool AsmPrinter::doInitialization(Module &M) {
@@ -1545,16 +1550,13 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
assert(BBAddrMapVersion >= 2 &&
"PGOAnalysisMap only supports version 2 or later");
- // We will emit the BBSPR profile data if availale. Otherwise, we fall back
+ // We will emit the BBSPR profile data if requested and availale. Otherwise, we fall back
// to MBFI and MBPI.
- const BasicBlockSectionsProfileReader *BBSPR = nullptr;
- if (auto *BBSPRPass = getAnalysisIfAvailable<
- BasicBlockSectionsProfileReaderWrapperPass>())
- BBSPR = &BBSPRPass->getBBSPR();
-
- const CFGProfile *FuncCFGProfile = nullptr;
- if (BBSPR)
- FuncCFGProfile = BBSPR->getFunctionCFGProfile(MF.getFunction().getName());
+ const CfgProfile *FuncCFGProfile = nullptr;
+ if (PgoAnalysisMapUsePropellerCfg) {
+ if (auto *BBSPR = getAnalysisIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>())
+ FuncCFGProfile = BBSPR->getFunctionCfgProfile(MF.getFunction().getName());
+ }
const MachineBlockFrequencyInfo *MBFI =
Features.BBFreq
diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
index 01d7f51dff54c..9cffb217b8548 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -491,6 +491,11 @@ BasicBlockSectionsProfileReaderWrapperPass::getClonePathsForFunction(
return BBSPR.getClonePathsForFunction(FuncName);
}
+
+const CfgProfile *BasicBlockSectionsProfileReaderWrapperPass::getFunctionCfgProfile(StringRef FuncName) const {
+ return BBSPR.getFunctionCfgProfile(FuncName);
+}
+
BasicBlockSectionsProfileReader &
BasicBlockSectionsProfileReaderWrapperPass::getBBSPR() {
return BBSPR;
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
index f535b9f6bd9d2..ee3a24177a466 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
@@ -5,7 +5,7 @@
; RUN: echo 'g 0:1000,1:800,2:200 1:800,3:800 2:200,3:200 3:1000' >> %t
; RUN: echo 'c 0 1 2' >> %t
;
-; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -basic-block-address-map -pgo-analysis-map=all | FileCheck %s
+; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -basic-block-address-map -pgo-analysis-map=all -pgo-analysis-map-use-propeller-cfg | FileCheck %s
define void @foo() nounwind !prof !0 {
entry:
>From 58114e7e5117933befbbb9e93bd2220fba888e5a Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 13 Oct 2025 22:36:56 +0000
Subject: [PATCH 07/14] clang-format.
---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 18 +++++++++++-------
.../BasicBlockSectionsProfileReader.cpp | 5 +++--
2 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 45e3bfc2f0847..a68bab5536db6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -167,9 +167,11 @@ static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
"Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is "
"extracted from PGO related analysis."));
-static cl::opt<bool> PgoAnalysisMapUsePropellerCfg("pgo-analysis-map-use-propeller-cfg",
-cl::desc("If available, use the Propeller cfg profile in the PGO analysis map."),
-cl::Hidden, cl::init(false));
+static cl::opt<bool> PgoAnalysisMapUsePropellerCfg(
+ "pgo-analysis-map-use-propeller-cfg",
+ cl::desc(
+ "If available, use the Propeller cfg profile in the PGO analysis map."),
+ cl::Hidden, cl::init(false));
static cl::opt<bool> BBAddrMapSkipEmitBBEntries(
"basic-block-address-map-skip-bb-entries",
@@ -1550,12 +1552,14 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
assert(BBAddrMapVersion >= 2 &&
"PGOAnalysisMap only supports version 2 or later");
- // We will emit the BBSPR profile data if requested and availale. Otherwise, we fall back
- // to MBFI and MBPI.
+ // We will emit the BBSPR profile data if requested and availale. Otherwise,
+ // we fall back to MBFI and MBPI.
const CfgProfile *FuncCFGProfile = nullptr;
if (PgoAnalysisMapUsePropellerCfg) {
- if (auto *BBSPR = getAnalysisIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>())
- FuncCFGProfile = BBSPR->getFunctionCfgProfile(MF.getFunction().getName());
+ if (auto *BBSPR = getAnalysisIfAvailable<
+ BasicBlockSectionsProfileReaderWrapperPass>())
+ FuncCFGProfile =
+ BBSPR->getFunctionCfgProfile(MF.getFunction().getName());
}
const MachineBlockFrequencyInfo *MBFI =
diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
index 9cffb217b8548..0ac079229ced1 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -491,8 +491,9 @@ BasicBlockSectionsProfileReaderWrapperPass::getClonePathsForFunction(
return BBSPR.getClonePathsForFunction(FuncName);
}
-
-const CfgProfile *BasicBlockSectionsProfileReaderWrapperPass::getFunctionCfgProfile(StringRef FuncName) const {
+const CfgProfile *
+BasicBlockSectionsProfileReaderWrapperPass::getFunctionCfgProfile(
+ StringRef FuncName) const {
return BBSPR.getFunctionCfgProfile(FuncName);
}
>From f5e07110658b104facfc4321436de45658d7997b Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 13 Oct 2025 22:52:16 +0000
Subject: [PATCH 08/14] Fix the undefs in test.
---
.../test/CodeGen/X86/basic-block-sections-pgo-features.ll | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
index ee3a24177a466..21ff75a5cd354 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
@@ -7,12 +7,12 @@
;
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -basic-block-address-map -pgo-analysis-map=all -pgo-analysis-map-use-propeller-cfg | FileCheck %s
-define void @foo() nounwind !prof !0 {
+define void @foo(i1 %cond) nounwind !prof !0 {
entry:
br label %bb1
bb1:
- br i1 undef, label %bb2, label %bb3, !prof !1
+ br i1 %cond, label %bb2, label %bb3, !prof !1
bb2:
br label %bb3
@@ -54,9 +54,9 @@ bb3:
; CHECK-NEXT: .ascii "\350\007" # basic block frequency
; CHECK-NEXT: .byte 0 # basic block successor count
-define void @bar() nounwind !prof !2 {
+define void @bar(i1 %cond) nounwind !prof !2 {
entry:
- br i1 undef, label %bb1, label %bb2, !prof !3
+ br i1 %cond, label %bb1, label %bb2, !prof !3
bb1:
ret void
>From 0ea0690a1869af357ac7ae90ca44f052b932cda2 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Tue, 14 Oct 2025 22:00:16 +0000
Subject: [PATCH 09/14] Change CFG to lower-case Cfg.
---
.../llvm/CodeGen/BasicBlockSectionsProfileReader.h | 6 +++---
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 14 +++++++-------
.../CodeGen/BasicBlockSectionsProfileReader.cpp | 10 +++++-----
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
index df4339fda0d5c..ffb6690a17f4d 100644
--- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
+++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
@@ -42,7 +42,7 @@ struct BBClusterInfo {
unsigned PositionInCluster;
};
-// This represents the CFG profile data for a function.
+// This represents the cfg profile data for a function.
struct CfgProfile {
// Node counts for each basic block.
DenseMap<UniqueBBID, uint64_t> NodeCounts;
@@ -75,7 +75,7 @@ struct FunctionProfile {
// determines the `UniqueBBID::CloneID` of the cloned blocks in that path.
SmallVector<SmallVector<unsigned>> ClonePaths;
// Cfg profile data (block and edge frequencies).
- CfgProfile CFG;
+ CfgProfile Cfg;
// Hash for each basic block. The Hashes are stored for every original block
// (not cloned blocks), hence the map key being unsigned instead of
// UniqueBBID.
@@ -113,7 +113,7 @@ class BasicBlockSectionsProfileReader {
auto It = ProgramPathAndClusterInfo.find(getAliasName(FuncName));
if (It == ProgramPathAndClusterInfo.end())
return nullptr;
- return &It->second.CFG;
+ return &It->second.Cfg;
}
private:
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index a68bab5536db6..3f9ee0ac4f6fe 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1554,11 +1554,11 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
// We will emit the BBSPR profile data if requested and availale. Otherwise,
// we fall back to MBFI and MBPI.
- const CfgProfile *FuncCFGProfile = nullptr;
+ const CfgProfile *FuncCfgProfile = nullptr;
if (PgoAnalysisMapUsePropellerCfg) {
if (auto *BBSPR = getAnalysisIfAvailable<
BasicBlockSectionsProfileReaderWrapperPass>())
- FuncCFGProfile =
+ FuncCfgProfile =
BBSPR->getFunctionCfgProfile(MF.getFunction().getName());
}
@@ -1574,8 +1574,8 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
if (Features.FuncEntryCount) {
OutStreamer->AddComment("function entry count");
uint64_t EntryCount = 0;
- if (FuncCFGProfile) {
- EntryCount = FuncCFGProfile->getNodeCount(*MF.front().getBBID());
+ if (FuncCfgProfile) {
+ EntryCount = FuncCfgProfile->getNodeCount(*MF.front().getBBID());
} else {
auto MaybeEntryCount = MF.getFunction().getEntryCount();
EntryCount = MaybeEntryCount ? MaybeEntryCount->getCount() : 0;
@@ -1589,7 +1589,7 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
if (Features.BBFreq) {
OutStreamer->AddComment("basic block frequency");
uint64_t BlockFrequency =
- FuncCFGProfile ? FuncCFGProfile->getNodeCount(*MBB.getBBID())
+ FuncCfgProfile ? FuncCfgProfile->getNodeCount(*MBB.getBBID())
: MBFI->getBlockFreq(&MBB).getFrequency();
OutStreamer->emitULEB128IntValue(BlockFrequency);
}
@@ -1603,8 +1603,8 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
// For MPBI, we emit the numerator of the probability. For BBSPR, we
// emit the raw edge count.
uint64_t EdgeFrequency =
- FuncCFGProfile
- ? FuncCFGProfile->getEdgeCount(*MBB.getBBID(),
+ FuncCfgProfile
+ ? FuncCfgProfile->getEdgeCount(*MBB.getBBID(),
*SuccMBB->getBBID())
: MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator();
OutStreamer->emitULEB128IntValue(EdgeFrequency);
diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
index 0ac079229ced1..bea2a137060bb 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -100,7 +100,7 @@ BasicBlockSectionsProfileReader::getClonePathsForFunction(
// the edge 1->3. Within the given clusters, each cloned block is identified by
// "<original block id>.<clone id>". For instance, 3.1 represents the first
// clone of block 3. Original blocks are specified just with their block ids. A
-// block cloned multiple times appears with distinct clone ids. The CFG for bar
+// block cloned multiple times appears with distinct clone ids. The Cfg for bar
// is shown below before and after cloning with its final clusters labeled.
//
// f main
@@ -240,12 +240,12 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
}
continue;
}
- case 'g': { // CFG profile specifier.
+ case 'g': { // Cfg profile specifier.
// Skip the profile when we the profile iterator (FI) refers to the
// past-the-end element.
if (FI == ProgramPathAndClusterInfo.end())
continue;
- // For each node, its CFG profile is encoded as
+ // For each node, its Cfg profile is encoded as
// <src>:<count>,<sink_1>:<count_1>,<sink_2>:<count_2>,...
for (auto BasicBlockEdgeProfile : Values) {
if (BasicBlockEdgeProfile.empty())
@@ -264,10 +264,10 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
Twine("unsigned integer expected: '") + CountStr + "'");
if (i == 0) {
// The first element represents the source and its total count.
- FI->second.CFG.NodeCounts[SrcBBID = *BBID] = Count;
+ FI->second.Cfg.NodeCounts[SrcBBID = *BBID] = Count;
continue;
}
- FI->second.CFG.EdgeCounts[SrcBBID][*BBID] = Count;
+ FI->second.Cfg.EdgeCounts[SrcBBID][*BBID] = Count;
}
}
continue;
>From 4d00b065d43c3e039b66416d555440f1e9fb6184 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Tue, 21 Oct 2025 05:19:29 +0000
Subject: [PATCH 10/14] Emit the Propeller CFG frequencies.
---
.../CodeGen/BasicBlockSectionsProfileReader.h | 14 ++-
llvm/include/llvm/Object/ELFTypes.h | 6 +-
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 99 ++++++++++---------
.../BasicBlockSectionsProfileReader.cpp | 16 +--
.../X86/basic-block-sections-pgo-features.ll | 52 +++++-----
5 files changed, 98 insertions(+), 89 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
index ffb6690a17f4d..557f9c43988be 100644
--- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
+++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
@@ -42,8 +42,8 @@ struct BBClusterInfo {
unsigned PositionInCluster;
};
-// This represents the cfg profile data for a function.
-struct CfgProfile {
+// This represents the CFG profile data for a function.
+struct CFGProfile {
// Node counts for each basic block.
DenseMap<UniqueBBID, uint64_t> NodeCounts;
// Edge counts for each edge, stored as a nested map.
@@ -51,7 +51,7 @@ struct CfgProfile {
// Returns the profile count for the given basic block or zero if it does not
// exist.
- uint64_t getNodeCount(const UniqueBBID &BBID) const {
+ uint64_t getBlockCount(const UniqueBBID &BBID) const {
return NodeCounts.lookup(BBID);
}
@@ -107,13 +107,13 @@ class BasicBlockSectionsProfileReader {
SmallVector<SmallVector<unsigned>>
getClonePathsForFunction(StringRef FuncName) const;
- // Returns a pointer to the CfgProfile for the given function.
+ // Returns a pointer to the CFGProfile for the given function.
// Returns nullptr if no profile data is available for the function.
- const CfgProfile *getFunctionCfgProfile(StringRef FuncName) const {
+ const CFGProfile *getFunctionCFGProfile(StringRef FuncName) const {
auto It = ProgramPathAndClusterInfo.find(getAliasName(FuncName));
if (It == ProgramPathAndClusterInfo.end())
return nullptr;
- return &It->second.Cfg;
+ return &It->second.CFG;
}
private:
@@ -222,8 +222,6 @@ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
SmallVector<SmallVector<unsigned>>
getClonePathsForFunction(StringRef FuncName) const;
- const CfgProfile *getFunctionCfgProfile(StringRef FuncName) const;
-
// Initializes the FunctionNameToDIFilename map for the current module and
// then reads the profile for the matching functions.
bool doInitialization(Module &M) override;
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index 467ab6fd3c1e9..94980e1a46c3f 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -836,9 +836,11 @@ struct BBAddrMap {
bool BBHash : 1;
bool PostLinkCfg : 1;
- bool hasPGOAnalysis() const { return FuncEntryCount || BBFreq || BrProb; }
+ bool hasPGOAnalysis() const {
+ return FuncEntryCount || BBFreq || BrProb || PropellerCFG;
+ }
- bool hasPGOAnalysisBBData() const { return BBFreq || BrProb; }
+ bool hasPGOAnalysisBBData() const { return BBFreq || BrProb || PropellerCFG; }
// Encodes to minimum bit width representation.
uint16_t encode() const {
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3f9ee0ac4f6fe..1bf2a1c67509c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -20,7 +20,6 @@
#include "WinException.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
-#include "llvm/ADT/BitmaskEnum.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -151,6 +150,7 @@ enum class PGOMapFeaturesEnum {
FuncEntryCount,
BBFreq,
BrProb,
+ PropellerCFG,
All,
};
static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
@@ -162,17 +162,13 @@ static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq",
"Basic Block Frequency"),
clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob", "Branch Probability"),
+ clEnumValN(PGOMapFeaturesEnum::PropellerCFG, "propeller-cfg",
+ "Propeller CFG"),
clEnumValN(PGOMapFeaturesEnum::All, "all", "Enable all options")),
cl::desc(
"Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is "
"extracted from PGO related analysis."));
-static cl::opt<bool> PgoAnalysisMapUsePropellerCfg(
- "pgo-analysis-map-use-propeller-cfg",
- cl::desc(
- "If available, use the Propeller cfg profile in the PGO analysis map."),
- cl::Hidden, cl::init(false));
-
static cl::opt<bool> BBAddrMapSkipEmitBBEntries(
"basic-block-address-map-skip-bb-entries",
cl::desc("Skip emitting basic block entries in the SHT_LLVM_BB_ADDR_MAP "
@@ -1419,7 +1415,7 @@ static uint32_t getBBAddrMapMetadata(const MachineBasicBlock &MBB) {
static llvm::object::BBAddrMap::Features
getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
- bool HasCalls) {
+ bool HasCalls, const CFGProfile *FuncCFGProfile) {
// Ensure that the user has not passed in additional options while also
// specifying all or none.
if ((PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::None) ||
@@ -1441,17 +1437,33 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
bool BrProbEnabled =
AllFeatures ||
(!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BrProb));
+ bool PropellerCFGEnabled =
+ FuncCFGProfile &&
+ (AllFeatures ||
+ (!NoFeatures &&
+ PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::PropellerCFG)));
if ((BBFreqEnabled || BrProbEnabled) && BBAddrMapSkipEmitBBEntries) {
MF.getFunction().getContext().emitError(
- "BB entries info is required for BBFreq and BrProb "
- "features");
+ "BB entries info is required for BBFreq and BrProb features");
}
+<<<<<<< HEAD
return {FuncEntryCountEnabled, BBFreqEnabled, BrProbEnabled,
MF.hasBBSections() && NumMBBSectionRanges > 1,
// Use static_cast to avoid breakage of tests on windows.
static_cast<bool>(BBAddrMapSkipEmitBBEntries), HasCalls,
static_cast<bool>(EmitBBHash), false};
+=======
+
+ return {FuncEntryCountEnabled,
+ BBFreqEnabled,
+ BrProbEnabled,
+ MF.hasBBSections() && NumMBBSectionRanges > 1,
+ static_cast<bool>(BBAddrMapSkipEmitBBEntries),
+ HasCalls,
+ false,
+ PropellerCFGEnabled};
+>>>>>>> 7e89984eb0b3 (Emit the Propeller CFG frequencies.)
}
void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
@@ -1460,6 +1472,14 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
assert(BBAddrMapSection && ".llvm_bb_addr_map section is not initialized.");
bool HasCalls = !CurrentFnCallsiteEndSymbols.empty();
+ const BasicBlockSectionsProfileReader *BBSPR = nullptr;
+ if (auto *BBSPRPass =
+ getAnalysisIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>())
+ BBSPR = &BBSPRPass->getBBSPR();
+ const CFGProfile *FuncCFGProfile = nullptr;
+ if (BBSPR)
+ FuncCFGProfile = BBSPR->getFunctionCFGProfile(MF.getFunction().getName());
+
const MCSymbol *FunctionSymbol = getFunctionBegin();
OutStreamer->pushSection();
@@ -1468,7 +1488,8 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
uint8_t BBAddrMapVersion = OutStreamer->getContext().getBBAddrMapVersion();
OutStreamer->emitInt8(BBAddrMapVersion);
OutStreamer->AddComment("feature");
- auto Features = getBBAddrMapFeature(MF, MBBSectionRanges.size(), HasCalls);
+ auto Features =
+ getBBAddrMapFeature(MF, MBBSectionRanges.size(), HasCalls, FuncCFGProfile);
OutStreamer->emitInt8(Features.encode());
// Emit BB Information for each basic block in the function.
if (Features.MultiBBRange) {
@@ -1552,16 +1573,12 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
assert(BBAddrMapVersion >= 2 &&
"PGOAnalysisMap only supports version 2 or later");
- // We will emit the BBSPR profile data if requested and availale. Otherwise,
- // we fall back to MBFI and MBPI.
- const CfgProfile *FuncCfgProfile = nullptr;
- if (PgoAnalysisMapUsePropellerCfg) {
- if (auto *BBSPR = getAnalysisIfAvailable<
- BasicBlockSectionsProfileReaderWrapperPass>())
- FuncCfgProfile =
- BBSPR->getFunctionCfgProfile(MF.getFunction().getName());
+ if (Features.FuncEntryCount) {
+ OutStreamer->AddComment("function entry count");
+ auto MaybeEntryCount = MF.getFunction().getEntryCount();
+ OutStreamer->emitULEB128IntValue(
+ MaybeEntryCount ? MaybeEntryCount->getCount() : 0);
}
-
const MachineBlockFrequencyInfo *MBFI =
Features.BBFreq
? &getAnalysis<LazyMachineBlockFrequencyInfoPass>().getBFI()
@@ -1571,43 +1588,33 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
? &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI()
: nullptr;
- if (Features.FuncEntryCount) {
- OutStreamer->AddComment("function entry count");
- uint64_t EntryCount = 0;
- if (FuncCfgProfile) {
- EntryCount = FuncCfgProfile->getNodeCount(*MF.front().getBBID());
- } else {
- auto MaybeEntryCount = MF.getFunction().getEntryCount();
- EntryCount = MaybeEntryCount ? MaybeEntryCount->getCount() : 0;
- }
- OutStreamer->emitULEB128IntValue(EntryCount);
- }
-
if (Features.BBFreq || Features.BrProb) {
for (const MachineBasicBlock &MBB : MF) {
-
if (Features.BBFreq) {
OutStreamer->AddComment("basic block frequency");
- uint64_t BlockFrequency =
- FuncCfgProfile ? FuncCfgProfile->getNodeCount(*MBB.getBBID())
- : MBFI->getBlockFreq(&MBB).getFrequency();
- OutStreamer->emitULEB128IntValue(BlockFrequency);
+ OutStreamer->emitULEB128IntValue(
+ MBFI->getBlockFreq(&MBB).getFrequency());
+ if (Features.PropellerCFG) {
+ OutStreamer->AddComment("basic block frequency (propeller)");
+ OutStreamer->emitULEB128IntValue(
+ FuncCFGProfile->getBlockCount(*MBB.getBBID()));
+ }
}
if (Features.BrProb) {
+ unsigned SuccCount = MBB.succ_size();
OutStreamer->AddComment("basic block successor count");
- OutStreamer->emitULEB128IntValue(MBB.succ_size());
+ OutStreamer->emitULEB128IntValue(SuccCount);
for (const MachineBasicBlock *SuccMBB : MBB.successors()) {
OutStreamer->AddComment("successor BB ID");
OutStreamer->emitULEB128IntValue(SuccMBB->getBBID()->BaseID);
OutStreamer->AddComment("successor branch probability");
- // For MPBI, we emit the numerator of the probability. For BBSPR, we
- // emit the raw edge count.
- uint64_t EdgeFrequency =
- FuncCfgProfile
- ? FuncCfgProfile->getEdgeCount(*MBB.getBBID(),
- *SuccMBB->getBBID())
- : MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator();
- OutStreamer->emitULEB128IntValue(EdgeFrequency);
+ OutStreamer->emitULEB128IntValue(
+ MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator());
+ if (Features.PropellerCFG) {
+ OutStreamer->AddComment("successor branch frequency (propeller)");
+ OutStreamer->emitULEB128IntValue(FuncCFGProfile->getEdgeCount(
+ *MBB.getBBID(), *SuccMBB->getBBID()));
+ }
}
}
}
diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
index bea2a137060bb..01d7f51dff54c 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -100,7 +100,7 @@ BasicBlockSectionsProfileReader::getClonePathsForFunction(
// the edge 1->3. Within the given clusters, each cloned block is identified by
// "<original block id>.<clone id>". For instance, 3.1 represents the first
// clone of block 3. Original blocks are specified just with their block ids. A
-// block cloned multiple times appears with distinct clone ids. The Cfg for bar
+// block cloned multiple times appears with distinct clone ids. The CFG for bar
// is shown below before and after cloning with its final clusters labeled.
//
// f main
@@ -240,12 +240,12 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
}
continue;
}
- case 'g': { // Cfg profile specifier.
+ case 'g': { // CFG profile specifier.
// Skip the profile when we the profile iterator (FI) refers to the
// past-the-end element.
if (FI == ProgramPathAndClusterInfo.end())
continue;
- // For each node, its Cfg profile is encoded as
+ // For each node, its CFG profile is encoded as
// <src>:<count>,<sink_1>:<count_1>,<sink_2>:<count_2>,...
for (auto BasicBlockEdgeProfile : Values) {
if (BasicBlockEdgeProfile.empty())
@@ -264,10 +264,10 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
Twine("unsigned integer expected: '") + CountStr + "'");
if (i == 0) {
// The first element represents the source and its total count.
- FI->second.Cfg.NodeCounts[SrcBBID = *BBID] = Count;
+ FI->second.CFG.NodeCounts[SrcBBID = *BBID] = Count;
continue;
}
- FI->second.Cfg.EdgeCounts[SrcBBID][*BBID] = Count;
+ FI->second.CFG.EdgeCounts[SrcBBID][*BBID] = Count;
}
}
continue;
@@ -491,12 +491,6 @@ BasicBlockSectionsProfileReaderWrapperPass::getClonePathsForFunction(
return BBSPR.getClonePathsForFunction(FuncName);
}
-const CfgProfile *
-BasicBlockSectionsProfileReaderWrapperPass::getFunctionCfgProfile(
- StringRef FuncName) const {
- return BBSPR.getFunctionCfgProfile(FuncName);
-}
-
BasicBlockSectionsProfileReader &
BasicBlockSectionsProfileReaderWrapperPass::getBBSPR() {
return BBSPR;
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
index 21ff75a5cd354..ad55e86e62e25 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
@@ -5,7 +5,7 @@
; RUN: echo 'g 0:1000,1:800,2:200 1:800,3:800 2:200,3:200 3:1000' >> %t
; RUN: echo 'c 0 1 2' >> %t
;
-; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -basic-block-address-map -pgo-analysis-map=all -pgo-analysis-map-use-propeller-cfg | FileCheck %s
+; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -basic-block-address-map -pgo-analysis-map=all | FileCheck %s
define void @foo(i1 %cond) nounwind !prof !0 {
entry:
@@ -24,35 +24,42 @@ bb3:
!0 = !{!"function_entry_count", i64 1500}
!1 = !{!"branch_weights", i32 1200, i32 300}
-;; Verify that foo gets its PGO map from its Propeller CFG profile.
+;; Verify that foo's PGO map contains both IRPGO and Propeller CFG profiles.
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.foo
; CHECK-NEXT: .byte 3 # version
-; CHECK-NEXT: .byte 15 # feature
+; CHECK-NEXT: .byte 143 # feature
; CHECK: .quad .Lfunc_begin0 # base address
; CHECK: .byte 0 # BB id
; CHECK: .byte 1 # BB id
; CHECK: .byte 2 # BB id
; CHECK: .byte 3 # BB id
-; PGO Analysis Map for foo
-; CHECK: .ascii "\350\007" # function entry count
-; CHECK-NEXT: .ascii "\350\007" # basic block frequency
-; CHECK-NEXT: .byte 1 # basic block successor count
-; CHECK-NEXT: .byte 1 # successor BB ID
-; CHECK-NEXT: .ascii "\240\006" # successor branch probability
-; CHECK-NEXT: .ascii "\240\006" # basic block frequency
-; CHECK-NEXT: .byte 2 # basic block successor count
-; CHECK-NEXT: .byte 2 # successor BB ID
-; CHECK-NEXT: .byte 0 # successor branch probability
-; CHECK-NEXT: .byte 3 # successor BB ID
-; CHECK-NEXT: .ascii "\240\006" # successor branch probability
-; CHECK-NEXT: .ascii "\310\001" # basic block frequency
-; CHECK-NEXT: .byte 1 # basic block successor count
-; CHECK-NEXT: .byte 3 # successor BB ID
-; CHECK-NEXT: .ascii "\310\001" # successor branch probability
-; CHECK-NEXT: .ascii "\350\007" # basic block frequency
-; CHECK-NEXT: .byte 0 # basic block successor count
+; CHECK: .ascii "\334\013" # function entry count
+; CHECK-NEXT: .ascii "\200\200\200\200\200\200\200 " # basic block frequency
+; CHECK-NEXT: .ascii "\350\007" # basic block frequency (propeller)
+; CHECK-NEXT: .byte 1 # basic block successor count
+; CHECK-NEXT: .byte 1 # successor BB ID
+; CHECK-NEXT: .ascii "\200\200\200\200\b" # successor branch probability
+; CHECK-NEXT: .ascii "\240\006" # successor branch frequency (propeller)
+; CHECK-NEXT: .ascii "\200\200\200\200\200\200\200 " # basic block frequency
+; CHECK-NEXT: .ascii "\240\006" # basic block frequency (propeller)
+; CHECK-NEXT: .byte 2 # basic block successor count
+; CHECK-NEXT: .byte 2 # successor BB ID
+; CHECK-NEXT: .ascii "\200\200\200\200\004" # successor branch probability
+; CHECK-NEXT: .byte 0 # successor branch frequency (propeller)
+; CHECK-NEXT: .byte 3 # successor BB ID
+; CHECK-NEXT: .ascii "\200\200\200\200\004" # successor branch probability
+; CHECK-NEXT: .ascii "\240\006" # successor branch frequency (propeller)
+; CHECK-NEXT: .ascii "\200\200\200\200\200\200\200\020" # basic block frequency
+; CHECK-NEXT: .ascii "\310\001" # basic block frequency (propeller)
+; CHECK-NEXT: .byte 1 # basic block successor count
+; CHECK-NEXT: .byte 3 # successor BB ID
+; CHECK-NEXT: .ascii "\200\200\200\200\b" # successor branch probability
+; CHECK-NEXT: .ascii "\310\001" # successor branch frequency (propeller)
+; CHECK-NEXT: .ascii "\200\200\200\200\200\200\200 " # basic block frequency
+; CHECK-NEXT: .ascii "\350\007" # basic block frequency (propeller)
+; CHECK-NEXT: .byte 0 # basic block successor count
define void @bar(i1 %cond) nounwind !prof !2 {
entry:
@@ -68,7 +75,8 @@ bb2:
!2 = !{!"function_entry_count", i64 80}
!3 = !{!"branch_weights", i32 2, i32 78}
-;; Verify that we emit the PGO map for bar which doesn't have Propeller profile.
+;; Verify that the PGO map for bar only includes IRPGO data since it doesn't
+;; have Propeller profile.
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.bar
; CHECK-NEXT: .byte 3 # version
>From 3fbc277e87dd385d22ac8d8a0568c08c17769c9c Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Tue, 21 Oct 2025 16:56:11 +0000
Subject: [PATCH 11/14] clang-format.
---
llvm/include/llvm/Object/ELFTypes.h | 4 +++-
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 9 ++++-----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index 94980e1a46c3f..59bdfb74ce58f 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -840,7 +840,9 @@ struct BBAddrMap {
return FuncEntryCount || BBFreq || BrProb || PropellerCFG;
}
- bool hasPGOAnalysisBBData() const { return BBFreq || BrProb || PropellerCFG; }
+ bool hasPGOAnalysisBBData() const {
+ return BBFreq || BrProb || PropellerCFG;
+ }
// Encodes to minimum bit width representation.
uint16_t encode() const {
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 1bf2a1c67509c..30777a3d0bc17 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1439,9 +1439,8 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
(!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BrProb));
bool PropellerCFGEnabled =
FuncCFGProfile &&
- (AllFeatures ||
- (!NoFeatures &&
- PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::PropellerCFG)));
+ (AllFeatures || (!NoFeatures && PgoAnalysisMapFeatures.isSet(
+ PGOMapFeaturesEnum::PropellerCFG)));
if ((BBFreqEnabled || BrProbEnabled) && BBAddrMapSkipEmitBBEntries) {
MF.getFunction().getContext().emitError(
@@ -1488,8 +1487,8 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
uint8_t BBAddrMapVersion = OutStreamer->getContext().getBBAddrMapVersion();
OutStreamer->emitInt8(BBAddrMapVersion);
OutStreamer->AddComment("feature");
- auto Features =
- getBBAddrMapFeature(MF, MBBSectionRanges.size(), HasCalls, FuncCFGProfile);
+ auto Features = getBBAddrMapFeature(MF, MBBSectionRanges.size(), HasCalls,
+ FuncCFGProfile);
OutStreamer->emitInt8(Features.encode());
// Emit BB Information for each basic block in the function.
if (Features.MultiBBRange) {
>From 8c93878fd0d90165e2e28e07a73a6152f699b3d3 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 3 Nov 2025 00:39:57 +0000
Subject: [PATCH 12/14] Change option name.
---
.../CodeGen/BasicBlockSectionsProfileReader.h | 8 ++--
llvm/include/llvm/Object/ELFTypes.h | 4 +-
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 40 ++++++-------------
.../BasicBlockSectionsProfileReader.cpp | 4 +-
.../X86/basic-block-sections-pgo-features.ll | 4 +-
5 files changed, 23 insertions(+), 37 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
index 557f9c43988be..3f22ece30a3ed 100644
--- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
+++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
@@ -43,7 +43,7 @@ struct BBClusterInfo {
};
// This represents the CFG profile data for a function.
-struct CFGProfile {
+struct CfgProfile {
// Node counts for each basic block.
DenseMap<UniqueBBID, uint64_t> NodeCounts;
// Edge counts for each edge, stored as a nested map.
@@ -107,13 +107,13 @@ class BasicBlockSectionsProfileReader {
SmallVector<SmallVector<unsigned>>
getClonePathsForFunction(StringRef FuncName) const;
- // Returns a pointer to the CFGProfile for the given function.
+ // Returns a pointer to the CfgProfile for the given function.
// Returns nullptr if no profile data is available for the function.
- const CFGProfile *getFunctionCFGProfile(StringRef FuncName) const {
+ const CfgProfile *getFunctionCfgProfile(StringRef FuncName) const {
auto It = ProgramPathAndClusterInfo.find(getAliasName(FuncName));
if (It == ProgramPathAndClusterInfo.end())
return nullptr;
- return &It->second.CFG;
+ return &It->second.Cfg;
}
private:
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index 59bdfb74ce58f..d1e010d82389a 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -837,11 +837,11 @@ struct BBAddrMap {
bool PostLinkCfg : 1;
bool hasPGOAnalysis() const {
- return FuncEntryCount || BBFreq || BrProb || PropellerCFG;
+ return FuncEntryCount || BBFreq || BrProb;
}
bool hasPGOAnalysisBBData() const {
- return BBFreq || BrProb || PropellerCFG;
+ return BBFreq || BrProb;
}
// Encodes to minimum bit width representation.
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 30777a3d0bc17..aaba8314897eb 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -162,13 +162,14 @@ static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
clEnumValN(PGOMapFeaturesEnum::BBFreq, "bb-freq",
"Basic Block Frequency"),
clEnumValN(PGOMapFeaturesEnum::BrProb, "br-prob", "Branch Probability"),
- clEnumValN(PGOMapFeaturesEnum::PropellerCFG, "propeller-cfg",
- "Propeller CFG"),
clEnumValN(PGOMapFeaturesEnum::All, "all", "Enable all options")),
cl::desc(
"Enable extended information within the SHT_LLVM_BB_ADDR_MAP that is "
"extracted from PGO related analysis."));
+static cl::opt<bool> PgoAnalysisMapEmitBBSectionsCfg(
+ "pgo-analysis-map-emit-bb-sections-cfg", cl::desc("Enable the post-link cfg information from the basic block sections profile in the PGO analysis map"), cl::Hidden, cl::init(false));
+
static cl::opt<bool> BBAddrMapSkipEmitBBEntries(
"basic-block-address-map-skip-bb-entries",
cl::desc("Skip emitting basic block entries in the SHT_LLVM_BB_ADDR_MAP "
@@ -1415,7 +1416,7 @@ static uint32_t getBBAddrMapMetadata(const MachineBasicBlock &MBB) {
static llvm::object::BBAddrMap::Features
getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
- bool HasCalls, const CFGProfile *FuncCFGProfile) {
+ bool HasCalls, const CfgProfile *FuncCfgProfile) {
// Ensure that the user has not passed in additional options while also
// specifying all or none.
if ((PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::None) ||
@@ -1437,32 +1438,17 @@ getBBAddrMapFeature(const MachineFunction &MF, int NumMBBSectionRanges,
bool BrProbEnabled =
AllFeatures ||
(!NoFeatures && PgoAnalysisMapFeatures.isSet(PGOMapFeaturesEnum::BrProb));
- bool PropellerCFGEnabled =
- FuncCFGProfile &&
- (AllFeatures || (!NoFeatures && PgoAnalysisMapFeatures.isSet(
- PGOMapFeaturesEnum::PropellerCFG)));
+ bool PostLinkCfgEnabled = FuncCfgProfile && PgoAnalysisMapEmitBBSectionsCfg;
if ((BBFreqEnabled || BrProbEnabled) && BBAddrMapSkipEmitBBEntries) {
MF.getFunction().getContext().emitError(
"BB entries info is required for BBFreq and BrProb features");
}
-<<<<<<< HEAD
return {FuncEntryCountEnabled, BBFreqEnabled, BrProbEnabled,
MF.hasBBSections() && NumMBBSectionRanges > 1,
// Use static_cast to avoid breakage of tests on windows.
static_cast<bool>(BBAddrMapSkipEmitBBEntries), HasCalls,
- static_cast<bool>(EmitBBHash), false};
-=======
-
- return {FuncEntryCountEnabled,
- BBFreqEnabled,
- BrProbEnabled,
- MF.hasBBSections() && NumMBBSectionRanges > 1,
- static_cast<bool>(BBAddrMapSkipEmitBBEntries),
- HasCalls,
- false,
- PropellerCFGEnabled};
->>>>>>> 7e89984eb0b3 (Emit the Propeller CFG frequencies.)
+ static_cast<bool>(EmitBBHash), PostLinkCfgEnabled};
}
void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
@@ -1475,9 +1461,9 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
if (auto *BBSPRPass =
getAnalysisIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>())
BBSPR = &BBSPRPass->getBBSPR();
- const CFGProfile *FuncCFGProfile = nullptr;
+ const CfgProfile *FuncCfgProfile = nullptr;
if (BBSPR)
- FuncCFGProfile = BBSPR->getFunctionCFGProfile(MF.getFunction().getName());
+ FuncCfgProfile = BBSPR->getFunctionCfgProfile(MF.getFunction().getName());
const MCSymbol *FunctionSymbol = getFunctionBegin();
@@ -1488,7 +1474,7 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
OutStreamer->emitInt8(BBAddrMapVersion);
OutStreamer->AddComment("feature");
auto Features = getBBAddrMapFeature(MF, MBBSectionRanges.size(), HasCalls,
- FuncCFGProfile);
+ FuncCfgProfile);
OutStreamer->emitInt8(Features.encode());
// Emit BB Information for each basic block in the function.
if (Features.MultiBBRange) {
@@ -1593,10 +1579,10 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
OutStreamer->AddComment("basic block frequency");
OutStreamer->emitULEB128IntValue(
MBFI->getBlockFreq(&MBB).getFrequency());
- if (Features.PropellerCFG) {
+ if (Features.PostLinkCfg) {
OutStreamer->AddComment("basic block frequency (propeller)");
OutStreamer->emitULEB128IntValue(
- FuncCFGProfile->getBlockCount(*MBB.getBBID()));
+ FuncCfgProfile->getBlockCount(*MBB.getBBID()));
}
}
if (Features.BrProb) {
@@ -1609,9 +1595,9 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
OutStreamer->AddComment("successor branch probability");
OutStreamer->emitULEB128IntValue(
MBPI->getEdgeProbability(&MBB, SuccMBB).getNumerator());
- if (Features.PropellerCFG) {
+ if (Features.PostLinkCfg) {
OutStreamer->AddComment("successor branch frequency (propeller)");
- OutStreamer->emitULEB128IntValue(FuncCFGProfile->getEdgeCount(
+ OutStreamer->emitULEB128IntValue(FuncCfgProfile->getEdgeCount(
*MBB.getBBID(), *SuccMBB->getBBID()));
}
}
diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
index 01d7f51dff54c..c03c17d4599ae 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -264,10 +264,10 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
Twine("unsigned integer expected: '") + CountStr + "'");
if (i == 0) {
// The first element represents the source and its total count.
- FI->second.CFG.NodeCounts[SrcBBID = *BBID] = Count;
+ FI->second.Cfg.NodeCounts[SrcBBID = *BBID] = Count;
continue;
}
- FI->second.CFG.EdgeCounts[SrcBBID][*BBID] = Count;
+ FI->second.Cfg.EdgeCounts[SrcBBID][*BBID] = Count;
}
}
continue;
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
index ad55e86e62e25..54a4c1f49dcf0 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
@@ -5,7 +5,7 @@
; RUN: echo 'g 0:1000,1:800,2:200 1:800,3:800 2:200,3:200 3:1000' >> %t
; RUN: echo 'c 0 1 2' >> %t
;
-; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -basic-block-address-map -pgo-analysis-map=all | FileCheck %s
+; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -basic-block-address-map -pgo-analysis-map=all -pgo-analysis-map-emit-bb-sections-cfg | FileCheck %s
define void @foo(i1 %cond) nounwind !prof !0 {
entry:
@@ -27,7 +27,7 @@ bb3:
;; Verify that foo's PGO map contains both IRPGO and Propeller CFG profiles.
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.foo
-; CHECK-NEXT: .byte 3 # version
+; CHECK-NEXT: .byte 4 # version
; CHECK-NEXT: .byte 143 # feature
; CHECK: .quad .Lfunc_begin0 # base address
; CHECK: .byte 0 # BB id
>From 48957ac1f380d278a4cb4ae503fd2abe63c8e2b6 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 3 Nov 2025 00:40:16 +0000
Subject: [PATCH 13/14] clang-format.
---
llvm/include/llvm/Object/ELFTypes.h | 8 ++------
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 5 ++++-
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index d1e010d82389a..467ab6fd3c1e9 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -836,13 +836,9 @@ struct BBAddrMap {
bool BBHash : 1;
bool PostLinkCfg : 1;
- bool hasPGOAnalysis() const {
- return FuncEntryCount || BBFreq || BrProb;
- }
+ bool hasPGOAnalysis() const { return FuncEntryCount || BBFreq || BrProb; }
- bool hasPGOAnalysisBBData() const {
- return BBFreq || BrProb;
- }
+ bool hasPGOAnalysisBBData() const { return BBFreq || BrProb; }
// Encodes to minimum bit width representation.
uint16_t encode() const {
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index aaba8314897eb..632a74ad65c0c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -168,7 +168,10 @@ static cl::bits<PGOMapFeaturesEnum> PgoAnalysisMapFeatures(
"extracted from PGO related analysis."));
static cl::opt<bool> PgoAnalysisMapEmitBBSectionsCfg(
- "pgo-analysis-map-emit-bb-sections-cfg", cl::desc("Enable the post-link cfg information from the basic block sections profile in the PGO analysis map"), cl::Hidden, cl::init(false));
+ "pgo-analysis-map-emit-bb-sections-cfg",
+ cl::desc("Enable the post-link cfg information from the basic block "
+ "sections profile in the PGO analysis map"),
+ cl::Hidden, cl::init(false));
static cl::opt<bool> BBAddrMapSkipEmitBBEntries(
"basic-block-address-map-skip-bb-entries",
>From 0b3716a483a1aadf4aeead37bd3bec142862e74a Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Mon, 3 Nov 2025 01:15:19 +0000
Subject: [PATCH 14/14] Bump the version byte in all the tests to 5.
---
llvm/include/llvm/MC/MCContext.h | 2 +-
.../CodeGen/X86/basic-block-address-map-empty-function.ll | 2 +-
.../X86/basic-block-address-map-function-sections.ll | 6 +++---
.../CodeGen/X86/basic-block-address-map-pgo-features.ll | 2 +-
.../basic-block-address-map-with-basic-block-sections.ll | 2 +-
.../X86/basic-block-address-map-with-emit-bb-hash.ll | 2 +-
llvm/test/CodeGen/X86/basic-block-address-map-with-mfs.ll | 2 +-
llvm/test/CodeGen/X86/basic-block-address-map.ll | 2 +-
llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll | 4 ++--
9 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 74abe3403bbed..c5de76bd30b3f 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -175,7 +175,7 @@ class MCContext {
unsigned GetInstance(unsigned LocalLabelVal);
/// SHT_LLVM_BB_ADDR_MAP version to emit.
- uint8_t BBAddrMapVersion = 4;
+ uint8_t BBAddrMapVersion = 5;
/// The file name of the log file from the environment variable
/// AS_SECURE_LOG_FILE. Which must be set before the .secure_log_unique
diff --git a/llvm/test/CodeGen/X86/basic-block-address-map-empty-function.ll b/llvm/test/CodeGen/X86/basic-block-address-map-empty-function.ll
index 423e31868bc5f..7457e3bdb24dc 100644
--- a/llvm/test/CodeGen/X86/basic-block-address-map-empty-function.ll
+++ b/llvm/test/CodeGen/X86/basic-block-address-map-empty-function.ll
@@ -19,7 +19,7 @@ entry:
; CHECK: func:
; CHECK: .Lfunc_begin1:
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text{{$}}
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; BASIC-NEXT: .byte 0 # feature
; PGO-NEXT: .byte 3 # feature
; CHECK-NEXT: .quad .Lfunc_begin1 # function address
diff --git a/llvm/test/CodeGen/X86/basic-block-address-map-function-sections.ll b/llvm/test/CodeGen/X86/basic-block-address-map-function-sections.ll
index e32e5222bf016..bdfe1e4564fc1 100644
--- a/llvm/test/CodeGen/X86/basic-block-address-map-function-sections.ll
+++ b/llvm/test/CodeGen/X86/basic-block-address-map-function-sections.ll
@@ -10,7 +10,7 @@ define dso_local i32 @_Z3barv() {
; CHECK-LABEL: _Z3barv:
; CHECK-NEXT: [[BAR_BEGIN:.Lfunc_begin[0-9]+]]:
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text._Z3barv{{$}}
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; CHECK-NEXT: .byte 0 # feature
; CHECK-NEXT: .quad [[BAR_BEGIN]] # function address
@@ -23,7 +23,7 @@ define dso_local i32 @_Z3foov() {
; CHECK-LABEL: _Z3foov:
; CHECK-NEXT: [[FOO_BEGIN:.Lfunc_begin[0-9]+]]:
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text._Z3foov{{$}}
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; CHECK-NEXT: .byte 32 # feature
; CHECK-NEXT: .quad [[FOO_BEGIN]] # function address
@@ -36,6 +36,6 @@ define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
; CHECK-LABEL: _Z4fooTIiET_v:
; CHECK-NEXT: [[FOOCOMDAT_BEGIN:.Lfunc_begin[0-9]+]]:
; CHECK: .section .llvm_bb_addr_map,"oG", at llvm_bb_addr_map,.text._Z4fooTIiET_v,_Z4fooTIiET_v,comdat{{$}}
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; CHECK-NEXT: .byte 0 # feature
; CHECK-NEXT: .quad [[FOOCOMDAT_BEGIN]] # function address
diff --git a/llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll
index 12b1297ba97ce..ca3c8d18e7dc5 100644
--- a/llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll
+++ b/llvm/test/CodeGen/X86/basic-block-address-map-pgo-features.ll
@@ -69,7 +69,7 @@ declare i32 @__gxx_personality_v0(...)
; CHECK-LABEL: .Lfunc_end0:
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text._Z3bazb{{$}}
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; BASIC-NEXT: .byte 32 # feature
; PGO-ALL-NEXT: .byte 39 # feature
; FEC-ONLY-NEXT:.byte 33 # feature
diff --git a/llvm/test/CodeGen/X86/basic-block-address-map-with-basic-block-sections.ll b/llvm/test/CodeGen/X86/basic-block-address-map-with-basic-block-sections.ll
index aeb6dc95e32f3..297cbd81ed036 100644
--- a/llvm/test/CodeGen/X86/basic-block-address-map-with-basic-block-sections.ll
+++ b/llvm/test/CodeGen/X86/basic-block-address-map-with-basic-block-sections.ll
@@ -47,7 +47,7 @@ declare i32 @__gxx_personality_v0(...)
; CHECK-LABEL: .Lfunc_end0:
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.hot._Z3bazb
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; CHECK-NEXT: .byte 40 # feature
; CHECK-NEXT: .byte 2 # number of basic block ranges
; CHECK-NEXT: .quad .Lfunc_begin0 # base address
diff --git a/llvm/test/CodeGen/X86/basic-block-address-map-with-emit-bb-hash.ll b/llvm/test/CodeGen/X86/basic-block-address-map-with-emit-bb-hash.ll
index a567887753245..f17e9a5849150 100644
--- a/llvm/test/CodeGen/X86/basic-block-address-map-with-emit-bb-hash.ll
+++ b/llvm/test/CodeGen/X86/basic-block-address-map-with-emit-bb-hash.ll
@@ -50,7 +50,7 @@ declare i32 @__gxx_personality_v0(...)
; UNIQ: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text._Z3bazb{{$}}
;; Verify that with -unique-section-names=false, the unique id of the text section gets assigned to the llvm_bb_addr_map section.
; NOUNIQ: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text,unique,1
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; CHECK-NEXT: .byte 96 # feature
; CHECK-NEXT: .quad .Lfunc_begin0 # function address
; CHECK-NEXT: .byte 6 # number of basic blocks
diff --git a/llvm/test/CodeGen/X86/basic-block-address-map-with-mfs.ll b/llvm/test/CodeGen/X86/basic-block-address-map-with-mfs.ll
index d49b313679628..36e21b9b3faa7 100644
--- a/llvm/test/CodeGen/X86/basic-block-address-map-with-mfs.ll
+++ b/llvm/test/CodeGen/X86/basic-block-address-map-with-mfs.ll
@@ -58,7 +58,7 @@ declare i32 @qux()
; CHECK-LABEL: .Lfunc_end0:
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.hot.foo
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; BASIC-NEXT: .byte 40 # feature
; PGO-NEXT: .byte 47 # feature
; CHECK-NEXT: .byte 2 # number of basic block ranges
diff --git a/llvm/test/CodeGen/X86/basic-block-address-map.ll b/llvm/test/CodeGen/X86/basic-block-address-map.ll
index 64cf2c709f3df..523b939765525 100644
--- a/llvm/test/CodeGen/X86/basic-block-address-map.ll
+++ b/llvm/test/CodeGen/X86/basic-block-address-map.ll
@@ -52,7 +52,7 @@ declare i32 @__gxx_personality_v0(...)
; UNIQ: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text._Z3bazb{{$}}
;; Verify that with -unique-section-names=false, the unique id of the text section gets assigned to the llvm_bb_addr_map section.
; NOUNIQ: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text,unique,1
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; CHECK-NEXT: .byte 32 # feature
; CHECK-NEXT: .quad .Lfunc_begin0 # function address
; CHECK-NEXT: .byte 6 # number of basic blocks
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
index 54a4c1f49dcf0..7f7d87369701b 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-pgo-features.ll
@@ -27,7 +27,7 @@ bb3:
;; Verify that foo's PGO map contains both IRPGO and Propeller CFG profiles.
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.foo
-; CHECK-NEXT: .byte 4 # version
+; CHECK-NEXT: .byte 5 # version
; CHECK-NEXT: .byte 143 # feature
; CHECK: .quad .Lfunc_begin0 # base address
; CHECK: .byte 0 # BB id
@@ -79,7 +79,7 @@ bb2:
;; have Propeller profile.
; CHECK: .section .llvm_bb_addr_map,"o", at llvm_bb_addr_map,.text.bar
-; CHECK-NEXT: .byte 3 # version
+; CHECK-NEXT: .byte 5 # version
; CHECK-NEXT: .byte 7 # feature
; CHECK: .quad .Lfunc_begin1 # function address
; CHECK: .byte 0 # BB id
More information about the llvm-commits
mailing list