[llvm] 5f59f40 - [CSSPGO] Minor tweak for inline candidate priority tie breaker

Wenlei He via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 25 21:28:45 PDT 2021


Author: Wenlei He
Date: 2021-03-25T21:15:36-07:00
New Revision: 5f59f407f59f69c248be2452e5923e6735e7019a

URL: https://github.com/llvm/llvm-project/commit/5f59f407f59f69c248be2452e5923e6735e7019a
DIFF: https://github.com/llvm/llvm-project/commit/5f59f407f59f69c248be2452e5923e6735e7019a.diff

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

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.

Differential Revision: https://reviews.llvm.org/D99370

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 561165aea9b8..548a8ad216b1 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -321,11 +321,16 @@ struct CandidateComparer {
     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(LCS->getName()) < RCS->getGUID(RCS->getName());
   }
 };
 


        


More information about the llvm-commits mailing list