[llvm] Insert symbols for prefetch targets read from basic blocks section profile. (PR #168439)

Sriraman Tallam via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 19 15:46:41 PST 2025


================
@@ -1985,7 +1985,33 @@ void AsmPrinter::emitFunctionBody() {
     // Print a label for the basic block.
     emitBasicBlockStart(MBB);
     DenseMap<StringRef, unsigned> MnemonicCounts;
+
+    SmallVector<unsigned> PrefetchTargets =
+        MBB.getPrefetchTargetCallsiteIndexes();
+    auto PrefetchTargetIt = PrefetchTargets.begin();
+    unsigned LastCallsiteIndex = 0;
+    // Helper to emit a symbol for the prefetch target and proceed to the next
+    // one.
+    auto EmitPrefetchTargetSymbolIfNeeded = [&]() {
+      if (PrefetchTargetIt != PrefetchTargets.end() &&
+          *PrefetchTargetIt == LastCallsiteIndex) {
+        MCSymbol *PrefetchTargetSymbol = OutContext.getOrCreateSymbol(
+            Twine("__llvm_prefetch_target_") + MF->getName() + Twine("_") +
+            utostr(MBB.getBBID()->BaseID) + Twine("_") +
+            utostr(static_cast<unsigned>(*PrefetchTargetIt)));
+        // 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);
----------------
tmsri wrote:

What happens to internal linkage?  Can you make this symbol a global, that would conflict.

https://github.com/llvm/llvm-project/pull/168439


More information about the llvm-commits mailing list