[PATCH] D24940: [thinlto] Add cold-callsite import heuristic

Piotr Padlewski via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 26 14:16:16 PDT 2016


Prazek updated this revision to Diff 72566.
Prazek added a comment.

Small typos


https://reviews.llvm.org/D24940

Files:
  lib/Transforms/IPO/FunctionImport.cpp
  test/Transforms/FunctionImport/hotness_based_import.ll

Index: test/Transforms/FunctionImport/hotness_based_import.ll
===================================================================
--- test/Transforms/FunctionImport/hotness_based_import.ll
+++ test/Transforms/FunctionImport/hotness_based_import.ll
@@ -5,12 +5,13 @@
 
 ; Test import with default hot multiplier (3)
 ; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=1 --S | FileCheck %s --check-prefix=CHECK --check-prefix=HOT-DEFAULT
-; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=1 --S -import-hot-multiplier=3.0 | FileCheck %s --check-prefix=CHECK --check-prefix=HOT-DEFAULT
+; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=1 --S -import-hot-multiplier=3.0 -import-cold-multiplier=0.0 | FileCheck %s --check-prefix=CHECK --check-prefix=HOT-DEFAULT
+
 ; HOT-DEFAULT-DAG: define available_externally void @hot1()
 ; HOT-DEFAULT-DAG: define available_externally void @hot2()
-; HOT-DEFAULT-DAG: define available_externally void @cold()
 ; HOT-DEFAULT-DAG: define available_externally void @none1()
 
+; HOT-DEFAULT-NOT: define available_externally void @cold()
 ; HOT-DEFAULT-NOT: define available_externally void @hot3()
 ; HOT-DEFAULT-NOT: define available_externally void @none2()
 ; HOT-DEFAULT-NOT: define available_externally void @none3()
@@ -20,17 +21,26 @@
 ; Test import with hot multiplier 1.0 - treat hot callsites as normal.
 ; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=1 -import-hot-multiplier=1.0 --S | FileCheck %s --check-prefix=CHECK --check-prefix=HOT-ONE
 ; HOT-ONE-DAG: define available_externally void @hot1()
-; HOT-ONE-DAG: define available_externally void @cold()
 ; HOT-ONE-DAG: define available_externally void @none1()
+; HOT-ONE-NOT: define available_externally void @cold()
 ; HOT-ONE-NOT: define available_externally void @hot2()
 ; HOT-ONE-NOT: define available_externally void @hot3()
 ; HOT-ONE-NOT: define available_externally void @none2()
 ; HOT-ONE-NOT: define available_externally void @none3()
 ; HOT-ONE-NOT: define available_externally void @cold2()
 
+; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=1 -import-hot-multiplier=1.0 -import-cold-multiplier=1.0 --S | FileCheck %s --check-prefix=CHECK --check-prefix=HOT-ONE
+; HOT-COLD-ONE-DAG: define available_externally void @hot1()
+; HOT-COLD-ONE-DAG: define available_externally void @cold()
+; HOT-COLD-ONE-DAG: define available_externally void @none1()
+; HOT-COLD-ONE-NOT: define available_externally void @hot2()
+; HOT-COLD-ONE-NOT: define available_externally void @hot3()
+; HOT-COLD-ONE-NOT: define available_externally void @none2()
+; HOT-COLD-ONE-NOT: define available_externally void @none3()
+; HOT-COLD-ONE-NOT: define available_externally void @cold2()
 
 ; Test import with hot multiplier 0.0 and high threshold - don't import functions called from hot callsite.
-; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=10 -import-hot-multiplier=0.0 --S | FileCheck %s --check-prefix=CHECK --check-prefix=HOT-ZERO
+; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=10 -import-hot-multiplier=0.0 -import-cold-multiplier=1.0 --S | FileCheck %s --check-prefix=CHECK --check-prefix=HOT-ZERO
 ; HOT-ZERO-DAG: define available_externally void @cold()
 ; HOT-ZERO-DAG: define available_externally void @none1()
 ; HOT-ZERO-DAG: define available_externally void @none2()
Index: lib/Transforms/IPO/FunctionImport.cpp
===================================================================
--- lib/Transforms/IPO/FunctionImport.cpp
+++ lib/Transforms/IPO/FunctionImport.cpp
@@ -48,11 +48,19 @@
                       cl::desc("As we import functions, multiply the "
                                "`import-instr-limit` threshold by this factor "
                                "before processing newly imported functions"));
+
 static cl::opt<float> ImportHotMultiplier(
     "import-hot-multiplier", cl::init(3.0), cl::Hidden, cl::value_desc("x"),
     cl::ZeroOrMore, cl::desc("Multiply the `import-instr-limit` threshold for "
                              "hot callsites"));
 
+// FIXME: This multiplier was not really tuned up.
+static cl::opt<float>
+    ImportColdMultiplier("import-cold-multiplier", cl::init(0), cl::Hidden,
+                         cl::value_desc("N"), cl::ZeroOrMore,
+                         cl::desc("Multiply the `import-instr-limit` threshold for "
+                                      "cold callsites"));
+
 static cl::opt<bool> PrintImports("print-imports", cl::init(false), cl::Hidden,
                                   cl::desc("Print imported functions"));
 
@@ -285,11 +293,14 @@
       continue;
     }
 
-    // FIXME: Also lower the threshold for cold callsites.
-    const auto NewThreshold =
+    const auto BonusMultiplier =
         Edge.second.Hotness == CalleeInfo::HotnessType::Hot
-            ? Threshold * ImportHotMultiplier
-            : Threshold;
+            ? ImportHotMultiplier
+            : (Edge.second.Hotness == CalleeInfo::HotnessType::Cold
+                   ? ImportColdMultiplier
+                   : 1);
+
+    const auto NewThreshold = Threshold * BonusMultiplier;
     auto *CalleeSummary = selectCallee(GUID, NewThreshold, Index);
     if (!CalleeSummary) {
       DEBUG(dbgs() << "ignored! No qualifying callee with summary found.\n");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24940.72566.patch
Type: text/x-patch
Size: 5454 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160926/86adb999/attachment-0001.bin>


More information about the llvm-commits mailing list