[llvm] Insert symbols for prefetch targets read from basic blocks section profile. (PR #168439)
Rahman Lavaee via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 12 16:47:59 PST 2025
https://github.com/rlavaee updated https://github.com/llvm/llvm-project/pull/168439
>From 74b2eebeb401d590b0ac734448f00aa91521d441 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Sat, 8 Nov 2025 19:54:21 +0000
Subject: [PATCH 1/3] feat(AsmPrinter): Add support for emitting prefetch
target symbols
---
.../CodeGen/BasicBlockSectionsProfileReader.h | 23 +++-
llvm/include/llvm/CodeGen/MachineBasicBlock.h | 14 +++
llvm/include/llvm/CodeGen/Passes.h | 2 +
llvm/include/llvm/InitializePasses.h | 1 +
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 39 ++++++-
.../BasicBlockSectionsProfileReader.cpp | 64 +++++++++++
llvm/lib/CodeGen/CMakeLists.txt | 1 +
llvm/lib/CodeGen/InsertCodePrefetch.cpp | 101 ++++++++++++++++++
llvm/lib/CodeGen/TargetPassConfig.cpp | 4 +-
.../X86/basic-block-sections-code-prefetch.ll | 65 +++++++++++
10 files changed, 310 insertions(+), 4 deletions(-)
create mode 100644 llvm/lib/CodeGen/InsertCodePrefetch.cpp
create mode 100644 llvm/test/CodeGen/X86/basic-block-sections-code-prefetch.ll
diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
index f0d28d863282e..e4433648a8bc2 100644
--- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
+++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
@@ -42,6 +42,14 @@ struct BBClusterInfo {
unsigned PositionInCluster;
};
+// The prefetch symbol is emitted immediately after the call of the given index,
+// in block `BBID` (First call has an index of 1). Zero callsite index means the
+// start of the block.
+struct CallsiteID {
+ UniqueBBID BBID;
+ unsigned CallsiteIndex;
+};
+
// This represents the raw input profile for one function.
struct FunctionPathAndClusterInfo {
// BB Cluster information specified by `UniqueBBID`s.
@@ -50,9 +58,12 @@ struct FunctionPathAndClusterInfo {
// 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;
+ // Code prefetch targets, specified by the callsite ID. The target is the code
+ // immediately following this callsite.
+ SmallVector<CallsiteID> PrefetchTargets;
// Node counts for each basic block.
DenseMap<UniqueBBID, uint64_t> NodeCounts;
- // Edge counts for each edge, stored as a nested map.
+ // Edge counts for each edge.
DenseMap<UniqueBBID, DenseMap<UniqueBBID, uint64_t>> EdgeCounts;
// Hash for each basic block. The Hashes are stored for every original block
// (not cloned blocks), hence the map key being unsigned instead of
@@ -90,6 +101,11 @@ class BasicBlockSectionsProfileReader {
std::pair<bool, FunctionPathAndClusterInfo>
getFunctionPathAndClusterInfo(StringRef FuncName) const;
+ // Returns the prefetch targets (identified by their containing callsite IDs)
+ // for function `FuncName`.
+ SmallVector<CallsiteID>
+ getPrefetchTargetsForFunction(StringRef FuncName) const;
+
private:
StringRef getAliasName(StringRef FuncName) const {
auto R = FuncAliasMap.find(FuncName);
@@ -199,8 +215,13 @@ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID,
const UniqueBBID &DestBBID) const;
+<<<<<<< HEAD
std::pair<bool, FunctionPathAndClusterInfo>
getFunctionPathAndClusterInfo(StringRef FuncName) const;
+=======
+ SmallVector<CallsiteID>
+ getPrefetchTargetsForFunction(StringRef FuncName) const;
+>>>>>>> 9bd00b1ae0d0 (feat(AsmPrinter): Add support for emitting prefetch target symbols)
// Initializes the FunctionNameToDIFilename map for the current module and
// then reads the profile for the matching functions.
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index a1023d4c32ce4..b166d99f70538 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -229,6 +229,12 @@ class MachineBasicBlock
/// is only computed once and is cached.
mutable MCSymbol *CachedMCSymbol = nullptr;
+ /// Contains the callsite indices in this block that are targets of code
+ /// prefetching. The index `i` specifies the `i`th call, with zero
+ /// representing the beginning of the block and ` representing the first call.
+ /// Must be in ascending order and without duplicates.
+ SmallVector<unsigned> PrefetchTargetCallsiteIndexes;
+
/// Cached MCSymbol for this block (used if IsEHContTarget).
mutable MCSymbol *CachedEHContMCSymbol = nullptr;
@@ -710,6 +716,14 @@ class MachineBasicBlock
std::optional<UniqueBBID> getBBID() const { return BBID; }
+ const SmallVector<unsigned> &getPrefetchTargetCallsiteIndexes() const {
+ return PrefetchTargetCallsiteIndexes;
+ }
+
+ void setPrefetchTargetCallsiteIndexes(const SmallVector<unsigned> &V) {
+ PrefetchTargetCallsiteIndexes = V;
+ }
+
/// Returns the section ID of this basic block.
MBBSectionID getSectionID() const { return SectionID; }
diff --git a/llvm/include/llvm/CodeGen/Passes.h b/llvm/include/llvm/CodeGen/Passes.h
index 2bf83cfa655b6..97523ab2233bb 100644
--- a/llvm/include/llvm/CodeGen/Passes.h
+++ b/llvm/include/llvm/CodeGen/Passes.h
@@ -73,6 +73,8 @@ LLVM_ABI MachineFunctionPass *createBasicBlockPathCloningPass();
/// and inference when using propeller.
LLVM_ABI MachineFunctionPass *createBasicBlockMatchingAndInferencePass();
+LLVM_ABI MachineFunctionPass *createInsertCodePrefetchPass();
+
/// createMachineBlockHashInfoPass - This pass computes basic block hashes.
LLVM_ABI MachineFunctionPass *createMachineBlockHashInfoPass();
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index a5491e68bbe52..1c35914e4f3d7 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -57,6 +57,7 @@ LLVM_ABI void initializeAssumptionCacheTrackerPass(PassRegistry &);
LLVM_ABI void initializeAtomicExpandLegacyPass(PassRegistry &);
LLVM_ABI void initializeBasicBlockMatchingAndInferencePass(PassRegistry &);
LLVM_ABI void initializeBasicBlockPathCloningPass(PassRegistry &);
+LLVM_ABI void initializeInsertCodePrefetchPass(PassRegistry &);
LLVM_ABI void
initializeBasicBlockSectionsProfileReaderWrapperPassPass(PassRegistry &);
LLVM_ABI void initializeBasicBlockSectionsPass(PassRegistry &);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3aa245b7f3f1e..e48495cfaab64 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1985,7 +1985,33 @@ void AsmPrinter::emitFunctionBody() {
// Print a label for the basic block.
emitBasicBlockStart(MBB);
DenseMap<StringRef, unsigned> MnemonicCounts;
+
+ // Helper to emit a symbol for the prefetch target associated with the given
+ // callsite index in the current MBB.
+ auto EmitPrefetchTargetSymbol = [&](unsigned CallsiteIndex) {
+ MCSymbol *PrefetchTargetSymbol = OutContext.getOrCreateSymbol(
+ Twine("__llvm_prefetch_target_") + MF->getName() + Twine("_") +
+ utostr(MBB.getBBID()->BaseID) + Twine("_") +
+ utostr(static_cast<unsigned>(CallsiteIndex)));
+ // If the function is weak-linkage it may be replaced by a strong
+ // version, in which case the prefetch targets should also be replaced.
+ OutStreamer->emitSymbolAttribute(
+ PrefetchTargetSymbol,
+ MF->getFunction().isWeakForLinker() ? MCSA_Weak : MCSA_Global);
+ OutStreamer->emitLabel(PrefetchTargetSymbol);
+ };
+ SmallVector<unsigned> PrefetchTargets =
+ MBB.getPrefetchTargetCallsiteIndexes();
+ auto PrefetchTargetIt = PrefetchTargets.begin();
+ unsigned LastCallsiteIndex = 0;
+
for (auto &MI : MBB) {
+ if (PrefetchTargetIt != PrefetchTargets.end() &&
+ *PrefetchTargetIt == LastCallsiteIndex) {
+ EmitPrefetchTargetSymbol(*PrefetchTargetIt);
+ ++PrefetchTargetIt;
+ }
+
// Print the assembly for the instruction.
if (!MI.isPosition() && !MI.isImplicitDef() && !MI.isKill() &&
!MI.isDebugInstr()) {
@@ -2123,8 +2149,11 @@ void AsmPrinter::emitFunctionBody() {
break;
}
- if (MI.isCall() && MF->getTarget().Options.BBAddrMap)
- OutStreamer->emitLabel(createCallsiteEndSymbol(MBB));
+ if (MI.isCall()) {
+ if (MF->getTarget().Options.BBAddrMap)
+ OutStreamer->emitLabel(createCallsiteEndSymbol(MBB));
+ LastCallsiteIndex++;
+ }
if (TM.Options.EmitCallGraphSection && MI.isCall())
handleCallsiteForCallgraph(FuncCGInfo, CallSitesInfoMap, MI);
@@ -2136,6 +2165,12 @@ void AsmPrinter::emitFunctionBody() {
for (auto &Handler : Handlers)
Handler->endInstruction();
}
+ // Emit the last prefetch target in case the last instruction was a call.
+ if (PrefetchTargetIt != PrefetchTargets.end() &&
+ *PrefetchTargetIt == LastCallsiteIndex) {
+ EmitPrefetchTargetSymbol(*PrefetchTargetIt);
+ ++PrefetchTargetIt;
+ }
// We must emit temporary symbol for the end of this basic block, if either
// we have BBLabels enabled or if this basic blocks marks the end of a
diff --git a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
index be1c60c57ccf4..c932c0fc0c2e2 100644
--- a/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSectionsProfileReader.cpp
@@ -102,6 +102,13 @@ BasicBlockSectionsProfileReader::getFunctionPathAndClusterInfo(
: std::pair(false, FunctionPathAndClusterInfo());
}
+SmallVector<CallsiteID>
+BasicBlockSectionsProfileReader::getPrefetchTargetsForFunction(
+ StringRef FuncName) const {
+ return ProgramPathAndClusterInfo.lookup(getAliasName(FuncName))
+ .PrefetchTargets;
+}
+
// Reads the version 1 basic block sections profile. Profile for each function
// is encoded as follows:
// m <module_name>
@@ -157,6 +164,36 @@ BasicBlockSectionsProfileReader::getFunctionPathAndClusterInfo(
// +-->: 5 :
// ....
// ****************************************************************************
+// This profile can also specify prefetch targets (starting with 't') which
+// instruct the compiler to emit a prefetch symbol for the given target.
+// A prefetch target is specified by a pair "<bbid>,<subblock_index>" where
+// bbid specifies the target basic block and subblock_index is a zero-based
+// index. Subblock 0 refers to the region at the beginning of the block up to
+// the first callsite. Subblock `i > 0` refers to the region immediately after
+// the `i`-th callsite up to the `i+1`-th callsite (or the end of the block).
+// The prefetch target is always emitted at the beginning of the subblock.
+// This is the beginning of the basic block for `i = 0` and immediately after
+// the `i`-th call for every `i > 0`.
+//
+// Example: A basic block in function "foo" with BBID 10 and two call
+// instructions (call_A, call_B). This block is conceptually split into
+// subblocks, with the prefetch target symbol emitted at the beginning of each
+// subblock.
+//
+// +----------------------------------+
+// | __llvm_prefetch_target_foo_10_0: | <- Subblock 0 (before call_A)
+// | Instruction 1 |
+// | Instruction 2 |
+// | call_A (Callsite 0) |
+// | __llvm_prefetch_target_foo_10_1: | <--- Subblock 1 (after call_A,
+// | | before call_B)
+// | Instruction 3 |
+// | call_B (Callsite 1) |
+// | __llvm_prefetch_target_foo_10_2: | <--- Subblock 2 (after call_B,
+// | | before call_C)
+// | Instruction 4 |
+// +----------------------------------+
+//
Error BasicBlockSectionsProfileReader::ReadV1Profile() {
auto FI = ProgramPathAndClusterInfo.end();
@@ -317,6 +354,27 @@ Error BasicBlockSectionsProfileReader::ReadV1Profile() {
}
continue;
}
+ case 't': { // Callsite target specifier.
+ // Skip the profile when we the profile iterator (FI) refers to the
+ // past-the-end element.
+ if (FI == ProgramPathAndClusterInfo.end())
+ continue;
+ SmallVector<StringRef, 2> PrefetchTargetStr;
+ Values[0].split(PrefetchTargetStr, ',');
+ if (PrefetchTargetStr.size() != 2)
+ return createProfileParseError(Twine("Callsite target expected: ") +
+ Values[0]);
+ auto TargetBBID = parseUniqueBBID(PrefetchTargetStr[0]);
+ if (!TargetBBID)
+ return TargetBBID.takeError();
+ unsigned long long CallsiteIndex;
+ if (getAsUnsignedInteger(PrefetchTargetStr[1], 10, CallsiteIndex))
+ return createProfileParseError(Twine("signed integer expected: '") +
+ PrefetchTargetStr[1]);
+ FI->second.PrefetchTargets.push_back(
+ CallsiteID{*TargetBBID, static_cast<unsigned>(CallsiteIndex)});
+ continue;
+ }
default:
return createProfileParseError(Twine("invalid specifier: '") +
Twine(Specifier) + "'");
@@ -529,6 +587,12 @@ BasicBlockSectionsProfileReaderWrapperPass::getFunctionPathAndClusterInfo(
return BBSPR.getFunctionPathAndClusterInfo(FuncName);
}
+SmallVector<CallsiteID>
+BasicBlockSectionsProfileReaderWrapperPass::getPrefetchTargetsForFunction(
+ StringRef FuncName) const {
+ return BBSPR.getPrefetchTargetsForFunction(FuncName);
+}
+
BasicBlockSectionsProfileReader &
BasicBlockSectionsProfileReaderWrapperPass::getBBSPR() {
return BBSPR;
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index 30237e66ed0ec..47e7e3903c952 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -80,6 +80,7 @@ add_llvm_component_library(LLVMCodeGen
IndirectBrExpandPass.cpp
InitUndef.cpp
InlineSpiller.cpp
+ InsertCodePrefetch.cpp
InterferenceCache.cpp
InterleavedAccessPass.cpp
InterleavedLoadCombinePass.cpp
diff --git a/llvm/lib/CodeGen/InsertCodePrefetch.cpp b/llvm/lib/CodeGen/InsertCodePrefetch.cpp
new file mode 100644
index 0000000000000..44864cbc99c52
--- /dev/null
+++ b/llvm/lib/CodeGen/InsertCodePrefetch.cpp
@@ -0,0 +1,101 @@
+//===-- InsertCodePrefetch.cpp ---=========--------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+/// \file
+/// Code Prefetch Insertion Pass.
+//===----------------------------------------------------------------------===//
+/// This pass inserts code prefetch instructions according to the prefetch
+/// directives in the basic block section profile. The target of a prefetch can
+/// be the beginning of any dynamic basic block, that is the beginning of a
+/// machine basic block, or immediately after a callsite. A global symbol is
+/// emitted at the position of the target so it can be addressed from the
+/// prefetch instruction from any module.
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/CodeGen/BasicBlockSectionUtils.h"
+#include "llvm/CodeGen/BasicBlockSectionsProfileReader.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/InitializePasses.h"
+
+using namespace llvm;
+#define DEBUG_TYPE "insert-code-prefetch"
+
+namespace {
+class InsertCodePrefetch : public MachineFunctionPass {
+public:
+ static char ID;
+
+ InsertCodePrefetch() : MachineFunctionPass(ID) {
+ initializeInsertCodePrefetchPass(*PassRegistry::getPassRegistry());
+ }
+
+ StringRef getPassName() const override {
+ return "Code Prefetch Inserter Pass";
+ }
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override;
+
+ // Sets prefetch targets based on the bb section profile.
+ bool runOnMachineFunction(MachineFunction &MF) override;
+};
+
+} // end anonymous namespace
+
+//===----------------------------------------------------------------------===//
+// Implementation
+//===----------------------------------------------------------------------===//
+
+char InsertCodePrefetch::ID = 0;
+INITIALIZE_PASS_BEGIN(InsertCodePrefetch, DEBUG_TYPE, "Code prefetch insertion",
+ true, false)
+INITIALIZE_PASS_DEPENDENCY(BasicBlockSectionsProfileReaderWrapperPass)
+INITIALIZE_PASS_END(InsertCodePrefetch, DEBUG_TYPE, "Code prefetch insertion",
+ true, false)
+
+bool InsertCodePrefetch::runOnMachineFunction(MachineFunction &MF) {
+ assert(MF.getTarget().getBBSectionsType() == BasicBlockSection::List &&
+ "BB Sections list not enabled!");
+ if (hasInstrProfHashMismatch(MF))
+ return false;
+ // Set each block's prefetch targets so AsmPrinter can emit a special symbol
+ // there.
+ SmallVector<CallsiteID> PrefetchTargets =
+ getAnalysis<BasicBlockSectionsProfileReaderWrapperPass>()
+ .getPrefetchTargetsForFunction(MF.getName());
+ DenseMap<UniqueBBID, SmallVector<unsigned>> PrefetchTargetsByBBID;
+ for (const auto &Target : PrefetchTargets)
+ PrefetchTargetsByBBID[Target.BBID].push_back(Target.CallsiteIndex);
+ // Sort and uniquify the callsite indices for every block.
+ for (auto &[K, V] : PrefetchTargetsByBBID) {
+ llvm::sort(V);
+ V.erase(llvm::unique(V), V.end());
+ }
+ for (auto &MBB : MF) {
+ auto R = PrefetchTargetsByBBID.find(*MBB.getBBID());
+ if (R == PrefetchTargetsByBBID.end())
+ continue;
+ MBB.setPrefetchTargetCallsiteIndexes(R->second);
+ }
+ return false;
+}
+
+void InsertCodePrefetch::getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+ AU.addRequired<BasicBlockSectionsProfileReaderWrapperPass>();
+ MachineFunctionPass::getAnalysisUsage(AU);
+}
+
+MachineFunctionPass *llvm::createInsertCodePrefetchPass() {
+ return new InsertCodePrefetch();
+}
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index 120343d4b349b..db3476623f36b 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -1299,8 +1299,10 @@ void TargetPassConfig::addMachinePasses() {
TM->getBBSectionsFuncListBuf()));
if (BasicBlockSectionMatchInfer)
addPass(llvm::createBasicBlockMatchingAndInferencePass());
- else
+ else {
addPass(llvm::createBasicBlockPathCloningPass());
+ addPass(llvm::createInsertCodePrefetchPass());
+ }
}
addPass(llvm::createBasicBlockSectionsPass());
}
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-code-prefetch.ll b/llvm/test/CodeGen/X86/basic-block-sections-code-prefetch.ll
new file mode 100644
index 0000000000000..e5778b4b77fc2
--- /dev/null
+++ b/llvm/test/CodeGen/X86/basic-block-sections-code-prefetch.ll
@@ -0,0 +1,65 @@
+;; Check prefetch directives in basic block section profiles.
+;;
+;; Specify the bb sections profile:
+; RUN: echo 'v1' > %t
+; RUN: echo 'f _Z3foob' >> %t
+; RUN: echo 't 0,0' >> %t
+; RUN: echo 't 1,0' >> %t
+; RUN: echo 't 1,1' >> %t
+; RUN: echo 't 2,1' >> %t
+; RUN: echo 't 3,0' >> %t
+; RUN: echo 'f _Z3barv' >> %t
+; RUN: echo 't 0,0' >> %t
+; RUN: echo 't 21,1' >> %t
+;;
+; RUN: llc < %s -mtriple=x86_64-pc-linux -asm-verbose=false -function-sections -basic-block-sections=%t -O0 | FileCheck %s
+
+define i32 @_Z3foob(i1 zeroext %0) nounwind {
+ %2 = alloca i32, align 4
+ %3 = alloca i8, align 1
+ %4 = zext i1 %0 to i8
+ store i8 %4, ptr %3, align 1
+ %5 = load i8, ptr %3, align 1
+ %6 = trunc i8 %5 to i1
+ %7 = zext i1 %6 to i32
+ %8 = icmp sgt i32 %7, 0
+ br i1 %8, label %9, label %11
+; CHECK: _Z3foob:
+; CHECK-NEXT: .globl __llvm_prefetch_target__Z3foob_0_0
+; CHECK-NEXT: __llvm_prefetch_target__Z3foob_0_0:
+
+9: ; preds = %1
+ %10 = call i32 @_Z3barv()
+ store i32 %10, ptr %2, align 4
+ br label %13
+; CHECK: .globl __llvm_prefetch_target__Z3foob_1_0
+; CHECK-NEXT: __llvm_prefetch_target__Z3foob_1_0:
+; CHECK-NEXT: callq _Z3barv at PLT
+; CHECK-NEXT: .globl __llvm_prefetch_target__Z3foob_1_1
+; CHECK-NEXT: __llvm_prefetch_target__Z3foob_1_1:
+
+11: ; preds = %1
+ %12 = call i32 @_Z3bazv()
+ store i32 %12, ptr %2, align 4
+ br label %13
+; CHECK: callq _Z3bazv at PLT
+; CHECK-NEXT: .globl __llvm_prefetch_target__Z3foob_2_1
+; CHECK-NEXT: __llvm_prefetch_target__Z3foob_2_1:
+
+13: ; preds = %11, %9
+ %14 = load i32, ptr %2, align 4
+ ret i32 %14
+; CHECK: .LBB0_3:
+; CHECK-NEXT: .globl __llvm_prefetch_target__Z3foob_3_0
+; CHECK-NEXT: __llvm_prefetch_target__Z3foob_3_0:
+}
+
+define weak i32 @_Z3barv() nounwind {
+ %1 = call i32 @_Z3bazv()
+ ret i32 %1
+; CHECK: _Z3barv:
+; CHECK-NEXT: .weak __llvm_prefetch_target__Z3barv_0_0
+; CHECK-NEXT: __llvm_prefetch_target__Z3barv_0_0:
+}
+
+declare i32 @_Z3bazv() #1
>From 32b4f5f01972eed354eff73109b3530e69e1a9dc Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Tue, 9 Dec 2025 00:35:03 +0000
Subject: [PATCH 2/3] Fix remaining conflict.
---
llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
index e4433648a8bc2..197c42e734b05 100644
--- a/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
+++ b/llvm/include/llvm/CodeGen/BasicBlockSectionsProfileReader.h
@@ -215,13 +215,11 @@ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
uint64_t getEdgeCount(StringRef FuncName, const UniqueBBID &SrcBBID,
const UniqueBBID &DestBBID) const;
-<<<<<<< HEAD
std::pair<bool, FunctionPathAndClusterInfo>
getFunctionPathAndClusterInfo(StringRef FuncName) const;
-=======
+
SmallVector<CallsiteID>
getPrefetchTargetsForFunction(StringRef FuncName) const;
->>>>>>> 9bd00b1ae0d0 (feat(AsmPrinter): Add support for emitting prefetch target symbols)
// Initializes the FunctionNameToDIFilename map for the current module and
// then reads the profile for the matching functions.
>From bd650e3659faec62ff197a4d7fd469293e8ba950 Mon Sep 17 00:00:00 2001
From: Rahman Lavaee <rahmanl at google.com>
Date: Sat, 13 Dec 2025 00:47:20 +0000
Subject: [PATCH 3/3] Extend basic-block-sections-code-prefetch.ll with
internal linkage test
---
.../X86/basic-block-sections-code-prefetch.ll | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/llvm/test/CodeGen/X86/basic-block-sections-code-prefetch.ll b/llvm/test/CodeGen/X86/basic-block-sections-code-prefetch.ll
index e5778b4b77fc2..d603e471e44bf 100644
--- a/llvm/test/CodeGen/X86/basic-block-sections-code-prefetch.ll
+++ b/llvm/test/CodeGen/X86/basic-block-sections-code-prefetch.ll
@@ -11,6 +11,9 @@
; RUN: echo 'f _Z3barv' >> %t
; RUN: echo 't 0,0' >> %t
; RUN: echo 't 21,1' >> %t
+; RUN: echo 'f _Z3quxv' >> %t
+; RUN: echo 't 0,0' >> %t
+; RUN: echo 't 0,1' >> %t
;;
; RUN: llc < %s -mtriple=x86_64-pc-linux -asm-verbose=false -function-sections -basic-block-sections=%t -O0 | FileCheck %s
@@ -60,6 +63,18 @@ define weak i32 @_Z3barv() nounwind {
; CHECK: _Z3barv:
; CHECK-NEXT: .weak __llvm_prefetch_target__Z3barv_0_0
; CHECK-NEXT: __llvm_prefetch_target__Z3barv_0_0:
+; CHECK: callq _Z3bazv at PLT
+}
+
+define internal i32 @_Z3quxv() nounwind {
+ %1 = call i32 @_Z3bazv()
+ ret i32 %1
+; CHECK: _Z3quxv:
+; CHECK-NEXT: .globl __llvm_prefetch_target__Z3quxv_0_0
+; CHECK-NEXT: __llvm_prefetch_target__Z3quxv_0_0:
+; CHECK: callq _Z3bazv at PLT
+; CHECK-NEXT: .globl __llvm_prefetch_target__Z3quxv_0_1
+; CHECK-NEXT: __llvm_prefetch_target__Z3quxv_0_1:
}
declare i32 @_Z3bazv() #1
More information about the llvm-commits
mailing list