[llvm-branch-commits] [llvm] [SampleProfile] Recover missing inline contexts from top-level profiles (PR #245375)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 23 12:56:18 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Kunal Pathak (kunalspathak)

<details>
<summary>Changes</summary>

The compiler and the sample pre-inliner can make different inlining decisions. When the compiler inlines a function that the profile kept separate, the sample loader can lose access to that function’s profile and its nested inline decisions.

For example, consider `G -> R -> ext`. The profile keeps `R` as a top-level function and marks `ext` for inlining into it. During ThinLTO pre-link, the regular inliner instead inlines `R` into `G` and removes its standalone definition.

In post-link, the loader looks for `R` underneath `G`’s profile. That context does not exist: `R`’s samples, including the decision to inline `ext`, are still stored in its separate root profile. Even when `ext` has been imported, the loader can miss that decision.

This patch lets the loader recover a missing inline context from the function’s top-level profile. It also makes those profiles available to the stale-profile matcher, so it can match locations inside an inlined function whose standalone definition has disappeared.

Recovery also handles deeper inline chains and frames inside imported code, including cases where an outer frame has no profile. For extbinary profiles, it selectively loads missing roots in batches and prefers an existing nested profile.

Finding a root does not automatically allow its samples to be reused. Recovery retains checks on the surviving definition, call counts, and available probe checksum information.

The behavior is controlled by `-sample-profile-preserve-orphaned-inlines`, enabled by default.
This is the profile-recovery follow-up to the import-hint preservation change in #<!-- -->243577

Assisted-by: GPT-6 Astra


---

Patch is 49.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/245375.diff


9 Files Affected:

- (modified) llvm/include/llvm/ProfileData/SampleProf.h (+12-2) 
- (modified) llvm/include/llvm/ProfileData/SampleProfReader.h (+7) 
- (modified) llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h (+5-3) 
- (modified) llvm/lib/ProfileData/SampleProf.cpp (+11-9) 
- (modified) llvm/lib/ProfileData/SampleProfReader.cpp (+97) 
- (modified) llvm/lib/Transforms/IPO/SampleProfile.cpp (+77-7) 
- (modified) llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp (+95-77) 
- (added) llvm/test/Transforms/SampleProfile/thinlto-orphaned-local-root.ll (+306) 
- (added) llvm/test/Transforms/SampleProfile/thinlto-orphaned-nonlocal-root.ll (+104) 


``````````diff
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 9944fdb8a08aa2..87dfc48691b09f 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -18,6 +18,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/Eytzinger.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/SortedVectorMap.h"
 #include "llvm/ADT/StringExtras.h"
@@ -1304,6 +1305,10 @@ class FunctionSamples {
 
   uint64_t getFunctionHash() const { return FunctionHash; }
 
+  bool hasIRToProfileLocationMap() const {
+    return IRToProfileLocationMap && !IRToProfileLocationMap->empty();
+  }
+
   void setIRToProfileLocationMap(const LocToLocMap *LTLM) {
     assert(IRToProfileLocationMap == nullptr && "this should be set only once");
     IRToProfileLocationMap = LTLM;
@@ -1426,12 +1431,17 @@ class FunctionSamples {
   /// \returns the FunctionSamples pointer to the inlined instance.
   /// If \p Remapper or \p FuncNameToProfNameMap is not nullptr, it will be used
   /// to find matching FunctionSamples with not exactly the same but equivalent
-  /// name.
+  /// name. If \p Fallback is not null, it is called for an inlined frame that
+  /// has no profile under its caller, with the caller's profile, the call site,
+  /// and the frame's name; a non-null result is used instead.
   LLVM_ABI const FunctionSamples *findFunctionSamples(
       const DILocation *DIL,
       SampleProfileReaderItaniumRemapper *Remapper = nullptr,
       const HashKeyMap<DenseMap, FunctionId, FunctionId>
-          *FuncNameToProfNameMap = nullptr) const LLVM_LIFETIME_BOUND;
+          *FuncNameToProfNameMap = nullptr,
+      function_ref<const FunctionSamples *(const FunctionSamples &,
+                                           const LineLocation &, StringRef)>
+          Fallback = nullptr) const LLVM_LIFETIME_BOUND;
 
   SampleContext &getContext() const LLVM_LIFETIME_BOUND { return Context; }
 
diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index 2bb616bb94b1fb..f40c5b5ade84dd 100644
--- a/llvm/include/llvm/ProfileData/SampleProfReader.h
+++ b/llvm/include/llvm/ProfileData/SampleProfReader.h
@@ -607,6 +607,13 @@ class SampleProfileReader {
     return sampleprof_error::success;
   }
 
+  /// Load missing roots referenced by inline frames, preferring existing
+  /// nested profiles. Collect the frames once and batch reads by inline depth;
+  /// each missing name is requested at most once. Matching also needs roots
+  /// when the caller's recorded locations no longer match the IR.
+  LLVM_ABI std::error_code readInlineFunctionProfiles(const Module &M,
+                                                      bool ForMatching = false);
+
   /// The implementaion to read sample profiles from the associated file.
   virtual std::error_code readImpl() = 0;
 
diff --git a/llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h b/llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h
index c78eba37dafa7a..0c78c9809e0d20 100644
--- a/llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h
+++ b/llvm/include/llvm/Transforms/IPO/SampleProfileMatcher.h
@@ -162,8 +162,10 @@ class SampleProfileMatcher {
                              const AnchorMap &ProfileAnchors,
                              AnchorList &FilteredIRAnchorsList,
                              AnchorList &FilteredProfileAnchorList);
-  void runOnFunction(Function &F);
-  void findIRAnchors(const Function &F, AnchorMap &IRAnchors) const;
+  void runOnFunction(Function &F, StringMap<AnchorMap> &InlineAnchors);
+  void findIRAnchors(const Function &F, AnchorMap &IRAnchors,
+                     StringMap<AnchorMap> *InlineAnchors = nullptr) const;
+  void matchInlinedFunctions(const StringMap<AnchorMap> &InlineAnchors);
   void findProfileAnchors(const FunctionSamples &FS,
                           AnchorMap &ProfileAnchors) const;
   bool anchorsMatch(const FunctionId &IRAnchor,
@@ -217,7 +219,7 @@ class SampleProfileMatcher {
   void matchNonCallsiteLocs(const LocToLocMap &AnchorMatchings,
                             const AnchorMap &IRAnchors,
                             LocToLocMap &IRToProfileLocationMap);
-  void runStaleProfileMatching(const Function &F, const AnchorMap &IRAnchors,
+  void runStaleProfileMatching(StringRef Name, const AnchorMap &IRAnchors,
                                const AnchorMap &ProfileAnchors,
                                LocToLocMap &IRToProfileLocationMap,
                                bool RunCFGMatching, bool RunCGMatching);
diff --git a/llvm/lib/ProfileData/SampleProf.cpp b/llvm/lib/ProfileData/SampleProf.cpp
index 5e090d6e5c765c..11b4fc4517a377 100644
--- a/llvm/lib/ProfileData/SampleProf.cpp
+++ b/llvm/lib/ProfileData/SampleProf.cpp
@@ -303,20 +303,18 @@ LineLocation FunctionSamples::getCallSiteIdentifier(const DILocation *DIL,
 
 const FunctionSamples *FunctionSamples::findFunctionSamples(
     const DILocation *DIL, SampleProfileReaderItaniumRemapper *Remapper,
-    const HashKeyMap<DenseMap, FunctionId, FunctionId> *FuncNameToProfNameMap)
-    const {
+    const HashKeyMap<DenseMap, FunctionId, FunctionId> *FuncNameToProfNameMap,
+    function_ref<const FunctionSamples *(const FunctionSamples &,
+                                         const LineLocation &, StringRef)>
+        Fallback) const {
   assert(DIL);
   SmallVector<std::pair<LineLocation, StringRef>, 10> S;
 
   const DILocation *PrevDIL = DIL;
   for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
-    // Use C++ linkage name if possible.
-    StringRef Name = PrevDIL->getScope()->getSubprogram()->getLinkageName();
-    if (Name.empty())
-      Name = PrevDIL->getScope()->getSubprogram()->getName();
     S.emplace_back(FunctionSamples::getCallSiteIdentifier(
                        DIL, FunctionSamples::ProfileIsFS),
-                   Name);
+                   PrevDIL->getSubprogramLinkageName());
     PrevDIL = DIL;
   }
 
@@ -324,8 +322,12 @@ const FunctionSamples *FunctionSamples::findFunctionSamples(
     return this;
   const FunctionSamples *FS = this;
   for (int i = S.size() - 1; i >= 0 && FS != nullptr; i--) {
-    FS = FS->findFunctionSamplesAt(S[i].first, S[i].second, Remapper,
-                                   FuncNameToProfNameMap);
+    const auto &[Loc, Name] = S[i];
+    const FunctionSamples *Inlinee =
+        FS->findFunctionSamplesAt(Loc, Name, Remapper, FuncNameToProfNameMap);
+    if (!Inlinee && Fallback)
+      Inlinee = Fallback(*FS, Loc, Name);
+    FS = Inlinee;
   }
   return FS;
 }
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index b8b33c11f5662c..620e17e10a5834 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -24,12 +24,16 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/InstIterator.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ProfileSummary.h"
+#include "llvm/IR/PseudoProbe.h"
 #include "llvm/ProfileData/ProfileCommon.h"
 #include "llvm/ProfileData/SampleProf.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compression.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/LEB128.h"
@@ -1121,6 +1125,99 @@ SampleProfileReaderExtBinaryBase::read(const DenseSet<StringRef> &FuncsToUse,
   return sampleprof_error::success;
 }
 
+std::error_code
+SampleProfileReader::readInlineFunctionProfiles(const Module &M,
+                                                bool ForMatching) {
+  if (getFormat() != SPF_Ext_Binary || profileIsCS())
+    return sampleprof_error::success;
+
+  struct Frame {
+    const FunctionSamples *Samples;
+    const DILocation *Location;
+    unsigned Parent, Depth;
+  };
+  SmallVector<Frame> Frames;
+  SmallVector<SmallVector<unsigned>> Levels(1);
+  using FrameKey = std::pair<const DILocation *, const DISubprogram *>;
+  for (const Function &F : M) {
+    if (F.isDeclaration() || !F.hasFnAttribute("use-sample-profile"))
+      continue;
+    unsigned Root = Frames.size();
+    Frames.push_back({getSamplesFor(F), nullptr, Root, 0});
+    DenseMap<FrameKey, unsigned> Seen;
+    for (const Instruction &I : instructions(F)) {
+      const DILocation *DIL = I.getDebugLoc();
+      if (!DIL || (profileIsProbeBased() && !extractProbe(I)))
+        continue;
+      SmallVector<const DILocation *, 4> Path;
+      unsigned Parent = Root;
+      for (; DIL->getInlinedAt(); DIL = DIL->getInlinedAt()) {
+        FrameKey Key = {DIL->getInlinedAt(), DIL->getScope()->getSubprogram()};
+        auto It = Seen.find(Key);
+        if (It != Seen.end()) {
+          Parent = It->second;
+          break;
+        }
+        Path.push_back(DIL);
+      }
+      for (const DILocation *DIL : reverse(Path)) {
+        unsigned ID = Frames.size();
+        unsigned Depth = Frames[Parent].Depth + 1;
+        Frames.push_back({nullptr, DIL, Parent, Depth});
+        Seen.try_emplace(
+            FrameKey{DIL->getInlinedAt(), DIL->getScope()->getSubprogram()},
+            ID);
+        if (Levels.size() <= Depth)
+          Levels.resize(Depth + 1);
+        Levels[Depth].push_back(ID);
+        Parent = ID;
+      }
+    }
+  }
+
+  DenseSet<StringRef> Requested;
+  for (const auto &Level : Levels) {
+    DenseSet<StringRef> Names;
+    SmallVector<std::pair<StringRef, Frame *>> Missing;
+    for (unsigned ID : Level) {
+      Frame &F = Frames[ID];
+      StringRef Name = FunctionSamples::getCanonicalFnName(
+          F.Location->getSubprogramLinkageName());
+      const FunctionSamples *Parent = Frames[F.Parent].Samples;
+      LineLocation Loc = FunctionSamples::getCallSiteIdentifier(
+          F.Location->getInlinedAt(), FunctionSamples::ProfileIsFS);
+      if (Parent)
+        F.Samples = Parent->findFunctionSamplesAt(Loc, Name, getRemapper(),
+                                                  FuncNameToProfNameMap);
+      if (F.Samples)
+        continue;
+      // A known caller without this target cannot use its root for annotation.
+      // An unknown caller must not hide deeper frames: it may itself be inlined
+      // later, acquiring a nested profile in its new caller.
+      if (Parent && !ForMatching) {
+        auto Targets = Parent->findCallTargetMapAt(Loc);
+        if (!Targets || Targets->find(getRepInFormat(Name)) == Targets->end())
+          continue;
+      }
+      F.Samples = getSamplesFor(Name);
+      if (!F.Samples) {
+        Missing.emplace_back(Name, &F);
+        if (Requested.insert(Name).second)
+          Names.insert(Name);
+      }
+    }
+    if (std::error_code EC = read(Names))
+      return EC;
+    for (const auto &[Name, F] : Missing)
+      F->Samples = getSamplesFor(Name);
+    LLVM_DEBUG(for (StringRef Name : Names) {
+      if (getSamplesFor(Name))
+        dbgs() << "Loaded inline frame root: " << Name << "\n";
+    });
+  }
+  return sampleprof_error::success;
+}
+
 bool SampleProfileReaderExtBinaryBase::collectFuncsFromModule() {
   if (!M)
     return false;
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 67a30fe80b2b5d..f8a4c04d716d5f 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -48,6 +48,7 @@
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/InstIterator.h"
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
@@ -106,6 +107,8 @@ STATISTIC(NumMismatchedProfile,
 STATISTIC(NumMatchedProfile, "Number of functions with CFG matched profile");
 STATISTIC(NumDuplicatedInlinesite,
           "Number of inlined callsites with a partial distribution factor");
+STATISTIC(NumOrphanedRootsLoaded,
+          "Number of orphaned root profiles loaded on demand");
 
 STATISTIC(NumCSInlinedHitMinLimit,
           "Number of functions with FDO inline stopped due to min size limit");
@@ -154,8 +157,9 @@ static cl::opt<bool> PreserveDeferredInlines(
 
 static cl::opt<bool> PreserveOrphanedInlines(
     "sample-profile-preserve-orphaned-inlines", cl::Hidden, cl::init(true),
-    cl::desc("In ThinLTO pre-link, preserve import GUIDs "
-             "of functions that pre-link inlines and deletes."));
+    cl::desc(
+        "In ThinLTO, preserve the import GUIDs and profile inline decisions "
+        "of functions that pre-link inlines and deletes."));
 
 namespace llvm {
 extern cl::opt<bool> EnableExtTspBlockPlacement;
@@ -337,6 +341,9 @@ class SampleProfileLoader final : public SampleProfileLoaderBaseImpl<Function> {
   findFunctionSamples(const Instruction &I) const override;
   std::vector<const FunctionSamples *>
   findIndirectCallFunctionSamples(const Instruction &I, uint64_t &Sum) const;
+  const FunctionSamples *findOrphanedRoot(const FunctionSamples &CallerFS,
+                                          const LineLocation &Loc,
+                                          StringRef Name) const;
   void findExternalInlineCandidate(CallBase *CB, const FunctionSamples *Samples,
                                    DenseSet<GlobalValue::GUID> &InlinedGUIDs,
                                    uint64_t Threshold);
@@ -618,15 +625,61 @@ SampleProfileLoader::findFunctionSamples(const Instruction &Inst) const {
 
   auto it = DILocation2SampleMap.try_emplace(DIL,nullptr);
   if (it.second) {
-    if (FunctionSamples::ProfileIsCS)
+    if (FunctionSamples::ProfileIsCS) {
       it.first->second = ContextTracker->getContextSamplesFor(DIL);
-    else
+    } else {
       it.first->second = Samples->findFunctionSamples(
-          DIL, Reader->getRemapper(), &FuncNameToProfNameMap);
+          DIL, Reader->getRemapper(), &FuncNameToProfNameMap,
+          [this](const FunctionSamples &CallerFS, const LineLocation &Loc,
+                 StringRef Name) {
+            return findOrphanedRoot(CallerFS, Loc, Name);
+          });
+    }
   }
   return it.first->second;
 }
 
+/// Recover the top-level profile of \p Name for a missing inline context at
+/// \p Loc of \p CallerFS. Pre-link may have inlined and deleted a function
+/// whose profile the pre-inliner kept top-level. Require no definition in this
+/// module and check the call-site count before reusing the root. Retrieving
+/// a root for matching does not by itself justify reusing its sample counts.
+const FunctionSamples *
+SampleProfileLoader::findOrphanedRoot(const FunctionSamples &CallerFS,
+                                      const LineLocation &Loc,
+                                      StringRef Name) const {
+  if (!PreserveOrphanedInlines ||
+      LTOPhase != ThinOrFullLTOPhase::ThinLTOPostLink)
+    return nullptr;
+  StringRef Canonical = FunctionSamples::getCanonicalFnName(Name);
+  const Function *Def = SymbolMap.lookup(FunctionId(Canonical));
+  if (Def && !Def->isDeclarationForLinker())
+    return nullptr;
+  const FunctionSamples *Root = Reader->getSamplesFor(Canonical);
+  // Require this call site to account for all entries of the function, so
+  // that inlined copies at other call sites do not reuse the same samples.
+  auto Targets = CallerFS.findCallTargetMapAt(Loc);
+  if (!Targets)
+    return nullptr;
+  auto Target =
+      Targets->find(Root ? Root->getFunction() : getRepInFormat(Canonical));
+  if (Target == Targets->end())
+    return nullptr;
+  // A zero head count cannot establish that this inline site owns the root.
+  if (!Root || !Root->getHeadSamples() ||
+      Target->second < Root->getHeadSamples())
+    return nullptr;
+  // Import does not copy llvm.pseudo_probe_desc, so an imported inline frame
+  // may have no descriptor in this module. Check its hash when one is present.
+  if (FunctionSamples::ProfileIsProbeBased) {
+    const PseudoProbeDescriptor *Desc = ProbeManager->getDesc(Root->getGUID());
+    if (Desc && ProbeManager->profileIsHashMismatched(*Desc, *Root) &&
+        !Root->hasIRToProfileLocationMap())
+      return nullptr;
+  }
+  return Root;
+}
+
 /// Check whether the indirect call promotion history of \p Inst allows
 /// the promotion for \p Candidate.
 /// If the profile count for the promotion candidate \p Candidate is
@@ -1988,8 +2041,6 @@ void SampleProfileLoader::removePseudoProbeInstsDiscriminator(Module &M) {
 
 bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager &AM,
                                       ProfileSummaryInfo *_PSI) {
-  GUIDToFuncNameMapper Mapper(M, *Reader, GUIDToFuncNameMap);
-
   PSI = _PSI;
   if (M.getProfileSummary(/* IsCS */ false) == nullptr) {
     M.setProfileSummary(Reader->getSummary().getMD(M.getContext()),
@@ -2029,6 +2080,25 @@ bool SampleProfileLoader::runOnModule(Module &M, ModuleAnalysisManager &AM,
     }
   }
 
+  // Inline frames can outlive their standalone Function. Load their missing
+  // roots before either consumer runs; matching and annotation have different
+  // rules for using a root, but share the same selective retrieval.
+  if ((PreserveOrphanedInlines &&
+       LTOPhase == ThinOrFullLTOPhase::ThinLTOPostLink) ||
+      SalvageStaleProfile) {
+    size_t Before = Reader->getProfiles().size();
+    if (std::error_code EC =
+            Reader->readInlineFunctionProfiles(M, SalvageStaleProfile)) {
+      M.getContext().diagnose(DiagnosticInfoSampleProfile(
+          Filename, "profile reading failed: " + EC.message()));
+      return false;
+    }
+    NumOrphanedRootsLoaded += Reader->getProfiles().size() - Before;
+  }
+
+  // Created after all profiles are loaded, so that it covers them all.
+  GUIDToFuncNameMapper Mapper(M, *Reader, GUIDToFuncNameMap);
+
   // Stale profile matching.
   if (Opts.report_profile_staleness || Opts.persist_profile_staleness ||
       SalvageStaleProfile) {
diff --git a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
index c5b421f64bcdc9..6460584477ce71 100644
--- a/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfileMatcher.cpp
@@ -33,72 +33,50 @@ namespace llvm {
 
 } // end namespace llvm
 
-void SampleProfileMatcher::findIRAnchors(const Function &F,
-                                         AnchorMap &IRAnchors) const {
-  // For inlined code, recover the original callsite and callee by finding the
-  // top-level inline frame. e.g. For frame stack "main:1 @ foo:2 @ bar:3", the
-  // top-level frame is "main:1", the callsite is "1" and the callee is "foo".
-  auto FindTopLevelInlinedCallsite = [](const DILocation *DIL) {
-    assert((DIL && DIL->getInlinedAt()) && "No inlined callsite");
-    const DILocation *PrevDIL = nullptr;
-    do {
-      PrevDIL = DIL;
-      DIL = DIL->getInlinedAt();
-    } while (DIL->getInlinedAt());
-
-    LineLocation Callsite = FunctionSamples::getCallSiteIdentifier(
-        DIL, FunctionSamples::ProfileIsFS);
-    StringRef CalleeName = PrevDIL->getSubprogramLinkageName();
-    return std::make_pair(Callsite, FunctionId(CalleeName));
-  };
-
-  auto GetCanonicalCalleeName = [](const CallBase *CB) {
-    StringRef CalleeName = UnknownIndirectCallee;
-    if (Function *Callee = CB->getCalledFunction())
-      CalleeName = FunctionSamples::getCanonicalFnName(Callee->getName());
-    return CalleeName;
-  };
-
-  // Extract profile matching anchors in the IR.
-  for (auto &BB : F) {
-    for (auto &I : BB) {
-      DILocation *DIL = I.getDebugLoc();
+void SampleProfileMatcher::findIRAnchors(
+    const Function &F, AnchorMap &IRAnchors,
+    StringMap<AnchorMap> *InlineAnchors) const {
+  DenseSet<std::pair<const DILocation *, const DISubprogram *>> Seen;
+  for (const BasicBlock &BB : F) {
+    for (const Instruction &I : BB) {
+      const DILocation *DIL = I.getDebugLoc();
       if (!DIL)
         continue;
-
+      std::optional<PseudoProbe> Probe;
       if (FunctionSamples::ProfileIsProbeBased) {
-        if (auto Probe = extractProbe(I)) {
-          // Flatten inlined IR for the matching.
-          if (DIL->getInlinedAt()) {
-            IRAnchors.emplace(FindTopLevelInlinedCallsite(DIL));
-          } else {
-            // Use empty StringRef for ba...
[truncated]

``````````

</details>


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


More information about the llvm-branch-commits mailing list