[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
Tue Oct 14 13:58:30 PDT 2025


https://github.com/rlavaee updated https://github.com/llvm/llvm-project/pull/163252

>From 0903d669c62d9c168c5a3ac85bbbe59a2d943622 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 1/8] 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 82dd5feb31dba..3c0e26bad7a5b 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;
 };
 
 class BasicBlockSectionsProfileReader {
@@ -81,10 +103,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 {
@@ -132,7 +158,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.
@@ -192,9 +218,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 219bbc9d5cdd4..3544033ead5f5 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"
@@ -1531,38 +1532,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 fbcd614b85d18..71a12e79fdd85 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;
@@ -487,12 +472,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 c22ac4dc0c47c916f3138bdfec2022e6a742644f 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 2/8] 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 3544033ead5f5..f84f15b84f2ba 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1533,8 +1533,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;
@@ -1571,9 +1571,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()));
           }
         }
       }
@@ -1584,9 +1585,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 d10f3404ebed5887a9f1f80ed861bb0fb31e42bc 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 3/8] 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 f84f15b84f2ba..1a770013ec199 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1532,15 +1532,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;
@@ -1553,65 +1566,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 16814a40874fc25563307ec1ae9a5bfcbd043fd7 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 4/8] 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 1a770013ec199..9adc65ee0c1b1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1539,20 +1539,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");
@@ -1566,31 +1564,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 b02b87aea00564c7e32f4115004c62cd56addea9 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 5/8] 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 3362e028bac8aac63c3e0bab3de6f04d996c91f1 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 6/8] 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 3c0e26bad7a5b..4967365f1bfe5 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;
 };
 
 class BasicBlockSectionsProfileReader {
@@ -103,9 +103,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;
@@ -218,6 +218,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 9adc65ee0c1b1..06f57019da40a 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -165,6 +165,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 "
@@ -474,6 +478,7 @@ void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<GCModuleInfo>();
   AU.addRequired<LazyMachineBlockFrequencyInfoPass>();
   AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
+  AU.addUsedIfAvailable<BasicBlockSectionsProfileReaderWrapperPass>();
 }
 
 bool AsmPrinter::doInitialization(Module &M) {
@@ -1532,16 +1537,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 71a12e79fdd85..49de0a351b5f5 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -472,6 +472,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 d1fc65ba2b54c0f6418412ae1420b73fea85811b 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 7/8] 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 06f57019da40a..b54a89468afb6 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -165,9 +165,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",
@@ -1537,12 +1539,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 49de0a351b5f5..0fb8f3a1503cd 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -472,8 +472,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 497d39e30d3efffd05e631cb5a8ab7717af8ef7e 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 8/8] 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



More information about the llvm-commits mailing list