[PATCH] D99370: [CSSPGO] Minor tweak for inline candidate priority tie breaker

Wenlei He via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 25 12:51:17 PDT 2021


wenlei created this revision.
wenlei added reviewers: hoy, wmi, davidxl.
Herald added subscribers: modimo, lxfind, hiraditya.
wenlei requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When prioritize call site to consider for inlining in sample loader, use number of samples as a first tier breaker before using name/guid comparison. This would favor smaller functions when hotness is the same (from the same block). We could try to retrieve accurate function size if this turns out to be more important.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99370

Files:
  llvm/lib/Transforms/IPO/SampleProfile.cpp


Index: llvm/lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -321,11 +321,17 @@
     if (LHS.CallsiteCount != RHS.CallsiteCount)
       return LHS.CallsiteCount < RHS.CallsiteCount;
 
+    const FunctionSamples *LCS = LHS.CalleeSamples;
+    const FunctionSamples *RCS = RHS.CalleeSamples;
+    assert(LCS && RCS && "Expect non-null FunctionSamples");
+
+    // Tie breaker using number of samples try to favor smaller functions first
+    if (LCS->getBodySamples().size() != RCS->getBodySamples().size())
+      return LCS->getBodySamples().size() > RCS->getBodySamples().size();
+
     // Tie breaker using GUID so we have stable/deterministic inlining order
-    assert(LHS.CalleeSamples && RHS.CalleeSamples &&
-           "Expect non-null FunctionSamples");
-    return LHS.CalleeSamples->getGUID(LHS.CalleeSamples->getName()) <
-           RHS.CalleeSamples->getGUID(RHS.CalleeSamples->getName());
+    return LCS->getGUID(LHS.CalleeSamples->getName()) <
+           RCS->getGUID(RHS.CalleeSamples->getName());
   }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99370.333399.patch
Type: text/x-patch
Size: 1179 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210325/4ee7f125/attachment.bin>


More information about the llvm-commits mailing list