Skip to content

Commit

Permalink
[thinlto] Add cold-callsite import heuristic
Browse files Browse the repository at this point in the history
Summary:
Not tunned up heuristic, but with this small heuristic there is about
+0.10% improvement on SPEC 2006

Reviewers: tejohnson, mehdi_amini, eraman

Subscribers: mehdi_amini, llvm-commits

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

llvm-svn: 282733
  • Loading branch information
prazek committed Sep 29, 2016
1 parent 3ace13a commit ba72b95
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
22 changes: 16 additions & 6 deletions llvm/lib/Transforms/IPO/FunctionImport.cpp
Expand Up @@ -48,10 +48,15 @@ static cl::opt<float>
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"));
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::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"));
Expand Down Expand Up @@ -285,11 +290,16 @@ static void computeImportForFunction(
continue;
}

// FIXME: Also lower the threshold for cold callsites.
auto GetBonusMultiplier = [](CalleeInfo::HotnessType Hotness) -> float {
if (Hotness == CalleeInfo::HotnessType::Hot)
return ImportHotMultiplier;
if (Hotness == CalleeInfo::HotnessType::Cold)
return ImportColdMultiplier;
return 1.0;
};

const auto NewThreshold =
Edge.second.Hotness == CalleeInfo::HotnessType::Hot
? Threshold * ImportHotMultiplier
: Threshold;
Threshold * GetBonusMultiplier(Edge.second.Hotness);
auto *CalleeSummary = selectCallee(GUID, NewThreshold, Index);
if (!CalleeSummary) {
DEBUG(dbgs() << "ignored! No qualifying callee with summary found.\n");
Expand Down
18 changes: 14 additions & 4 deletions llvm/test/Transforms/FunctionImport/hotness_based_import.ll
Expand Up @@ -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()
Expand All @@ -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-COLD-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()
Expand Down

0 comments on commit ba72b95

Please sign in to comment.