[PATCH] D56435: We can improve the performance (generally) by memo-izing the action to map a debug location to its function summary.

David Callahan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 8 05:38:32 PST 2019


david2050 created this revision.
Herald added a subscriber: llvm-commits.

Here are timings (as reported by "opt -time-passes") for
sample-profile pass for some files holding hot functions from a major
serviceĀ©r. Average 17% reduction. Delta column is 100*(old-new)/old.

  Old    New    Delta
  0.0537 0.0538 -0.2%
  0.8155 0.6522 20.0%
  0.0779 0.0751  3.6%
  0.0727 0.0913 -25.6%
  0.1622 0.1302 19.7%
  0.0627 0.0594  5.3%
  0.0766 0.0744  2.9%
  0.6426 0.4387 31.7%
  0.3521 0.2776 21.2%
  0.3549 0.2721 23.3%
  0.0912 0.0904  0.9%
  0.1236 0.1059 14.3%
  0.0854 0.0866 -1.4%
  0.0757 0.0722  4.6%
  0.1293 0.1147 11.3%
  0.1354 0.1122 17.1%
  0.0767 0.0770 -0.4%
  0.1135 0.0968 14.7%
  0.0524 0.0608 -16.0%
  0.1279 0.1106 13.5%
  ==========
  3.6820 3.0520 17.1% Total


Repository:
  rL LLVM

https://reviews.llvm.org/D56435

Files:
  lib/Transforms/IPO/SampleProfile.cpp


Index: lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- lib/Transforms/IPO/SampleProfile.cpp
+++ lib/Transforms/IPO/SampleProfile.cpp
@@ -215,10 +215,11 @@
   bool emitAnnotations(Function &F);
   ErrorOr<uint64_t> getInstWeight(const Instruction &I);
   ErrorOr<uint64_t> getBlockWeight(const BasicBlock *BB);
-  const FunctionSamples *findCalleeFunctionSamples(const Instruction &I) const;
+  const FunctionSamples *findCalleeFunctionSamples(const Instruction &I);
   std::vector<const FunctionSamples *>
-  findIndirectCallFunctionSamples(const Instruction &I, uint64_t &Sum) const;
-  const FunctionSamples *findFunctionSamples(const Instruction &I) const;
+  findIndirectCallFunctionSamples(const Instruction &I, uint64_t &Sum);
+  DenseMap<const DILocation *, const FunctionSamples *> DILocation2SampleMap;
+  const FunctionSamples *findFunctionSamples(const Instruction &I);
   bool inlineCallInstruction(Instruction *I);
   bool inlineHotFunctions(Function &F,
                           DenseSet<GlobalValue::GUID> &InlinedGUIDs);
@@ -645,7 +646,7 @@
 ///
 /// \returns The FunctionSamples pointer to the inlined instance.
 const FunctionSamples *
-SampleProfileLoader::findCalleeFunctionSamples(const Instruction &Inst) const {
+SampleProfileLoader::findCalleeFunctionSamples(const Instruction &Inst) {
   const DILocation *DIL = Inst.getDebugLoc();
   if (!DIL) {
     return nullptr;
@@ -669,8 +670,8 @@
 /// of \p Inst. The vector is sorted by the total number of samples. Stores
 /// the total call count of the indirect call in \p Sum.
 std::vector<const FunctionSamples *>
-SampleProfileLoader::findIndirectCallFunctionSamples(
-    const Instruction &Inst, uint64_t &Sum) const {
+SampleProfileLoader::findIndirectCallFunctionSamples(const Instruction &Inst,
+                                                     uint64_t &Sum) {
   const DILocation *DIL = Inst.getDebugLoc();
   std::vector<const FunctionSamples *> R;
 
@@ -718,13 +719,17 @@
 ///
 /// \returns the FunctionSamples pointer to the inlined instance.
 const FunctionSamples *
-SampleProfileLoader::findFunctionSamples(const Instruction &Inst) const {
+SampleProfileLoader::findFunctionSamples(const Instruction &Inst) {
   SmallVector<std::pair<LineLocation, StringRef>, 10> S;
   const DILocation *DIL = Inst.getDebugLoc();
   if (!DIL)
     return Samples;
-
-  return Samples->findFunctionSamples(DIL);
+  auto it = DILocation2SampleMap.find(DIL);
+  if (it != DILocation2SampleMap.end())
+    return it->second;
+  const FunctionSamples *s = Samples->findFunctionSamples(DIL);
+  DILocation2SampleMap.try_emplace(DIL, s);
+  return s;
 }
 
 bool SampleProfileLoader::inlineCallInstruction(Instruction *I) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56435.180645.patch
Type: text/x-patch
Size: 2753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190108/01211b37/attachment.bin>


More information about the llvm-commits mailing list