diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:17:04 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:17:04 +0000 |
| commit | b915e9e0fc85ba6f398b3fab0db6a81a8913af94 (patch) | |
| tree | 98b8f811c7aff2547cab8642daf372d6c59502fb /test/Transforms/FunctionImport | |
| parent | 6421cca32f69ac849537a3cff78c352195e99f1b (diff) | |
Notes
Diffstat (limited to 'test/Transforms/FunctionImport')
7 files changed, 325 insertions, 1 deletions
diff --git a/test/Transforms/FunctionImport/Inputs/funcimport.ll b/test/Transforms/FunctionImport/Inputs/funcimport.ll index fa96b8ea2663..c4ef37a168f2 100644 --- a/test/Transforms/FunctionImport/Inputs/funcimport.ll +++ b/test/Transforms/FunctionImport/Inputs/funcimport.ll @@ -11,6 +11,7 @@ define void @globalfunc1() #0 { entry: call void @funcwithpersonality() + call void (...) @variadic() ret void } @@ -146,4 +147,8 @@ entry: ret void } +; Variadic function should not be imported because inliner doesn't handle it. +define void @variadic(...) { + ret void +} diff --git a/test/Transforms/FunctionImport/Inputs/hotness_based_import.ll b/test/Transforms/FunctionImport/Inputs/hotness_based_import.ll new file mode 100644 index 000000000000..6951b65818d5 --- /dev/null +++ b/test/Transforms/FunctionImport/Inputs/hotness_based_import.ll @@ -0,0 +1,81 @@ +; ModuleID = 'thinlto-function-summary-callgraph-profile-summary2.ll' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + + +define void @hot1() #1 { + ret void +} +define void @hot2() #1 !prof !20 { + call void @calledFromHot() + call void @calledFromHot() + ret void +} +define void @hot3() #1 !prof !20 { + call void @calledFromHot() + call void @calledFromHot() + call void @calledFromHot() + ret void +} +define void @cold() #1 !prof !0 { + ret void +} +define void @cold2() #1 !prof !0 { + call void @calledFromCold() + call void @calledFromCold() + ret void +} + +define void @none1() #1 { + ret void +} + +define void @none2() #1 { + call void @calledFromNone() + ret void +} +define void @none3() #1 { + call void @calledFromNone() + call void @calledFromNone() + ret void +} + +define void @calledFromCold() { + ret void +} + +define void @calledFromHot() !prof !20 { + call void @calledFromHot2() + ret void +} + +define void @calledFromHot2() !prof !20 { + call void @calledFromHot3() + ret void +} + +define void @calledFromNone() !prof !0 { + ret void +} + +declare void @calledFromHot3() + +!0 = !{!"function_entry_count", i64 1} +!20 = !{!"function_entry_count", i64 110} + +!llvm.module.flags = !{!1} + +!1 = !{i32 1, !"ProfileSummary", !2} +!2 = !{!3, !4, !5, !6, !7, !8, !9, !10} +!3 = !{!"ProfileFormat", !"InstrProf"} +!4 = !{!"TotalCount", i64 10000} +!5 = !{!"MaxCount", i64 10} +!6 = !{!"MaxInternalCount", i64 1} +!7 = !{!"MaxFunctionCount", i64 1000} +!8 = !{!"NumCounts", i64 3} +!9 = !{!"NumFunctions", i64 3} +!10 = !{!"DetailedSummary", !11} +!11 = !{!12, !13, !14} +!12 = !{i32 10000, i64 100, i32 1} +!13 = !{i32 999000, i64 100, i32 1} +!14 = !{i32 999999, i64 1, i32 2}
\ No newline at end of file diff --git a/test/Transforms/FunctionImport/Inputs/hotness_based_import2.ll b/test/Transforms/FunctionImport/Inputs/hotness_based_import2.ll new file mode 100644 index 000000000000..4f17cb2cd9a1 --- /dev/null +++ b/test/Transforms/FunctionImport/Inputs/hotness_based_import2.ll @@ -0,0 +1,42 @@ +; ModuleID = 'thinlto-function-summary-callgraph-profile-summary2.ll' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + + +define void @hot() #1 !prof !28 { + call void @calledFromHot() + ret void +} + +; 9 instructions so it is above decayed cold threshold of 7 and below +; decayed hot threshold of 10. +define void @calledFromHot() !prof !28 { + %b = alloca i32, align 4 + store i32 1, i32* %b, align 4 + store i32 1, i32* %b, align 4 + store i32 1, i32* %b, align 4 + store i32 1, i32* %b, align 4 + store i32 1, i32* %b, align 4 + store i32 1, i32* %b, align 4 + store i32 1, i32* %b, align 4 + ret void +} + +!llvm.module.flags = !{!1} + +!1 = !{i32 1, !"ProfileSummary", !2} +!2 = !{!3, !4, !5, !6, !7, !8, !9, !10} +!3 = !{!"ProfileFormat", !"InstrProf"} +!4 = !{!"TotalCount", i64 222} +!5 = !{!"MaxCount", i64 110} +!6 = !{!"MaxInternalCount", i64 1} +!7 = !{!"MaxFunctionCount", i64 110} +!8 = !{!"NumCounts", i64 4} +!9 = !{!"NumFunctions", i64 3} +!10 = !{!"DetailedSummary", !11} +!11 = !{!12, !13, !14} +!12 = !{i32 10000, i64 110, i32 2} +!13 = !{i32 999000, i64 2, i32 4} +!14 = !{i32 999999, i64 2, i32 4} +!28 = !{!"function_entry_count", i64 110} +!29 = !{!"function_entry_count", i64 1} diff --git a/test/Transforms/FunctionImport/funcimport.ll b/test/Transforms/FunctionImport/funcimport.ll index 7f7e57b35743..97c18488af64 100644 --- a/test/Transforms/FunctionImport/funcimport.ll +++ b/test/Transforms/FunctionImport/funcimport.ll @@ -5,6 +5,8 @@ ; Do the import now ; RUN: opt -disable-force-link-odr -function-import -stats -print-imports -enable-import-metadata -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF +; Try again with new pass manager +; RUN: opt -disable-force-link-odr -passes='function-import' -stats -print-imports -enable-import-metadata -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=INSTLIMDEF ; "-stats" requires +Asserts. ; REQUIRES: asserts @@ -30,6 +32,7 @@ entry: call void (...) @weakfunc() call void (...) @linkoncefunc2() call void (...) @referencelargelinkonce() + call void (...) @variadic() ret i32 0 } @@ -103,6 +106,9 @@ declare void @linkoncefunc2(...) #1 ; INSTLIMDEF-DAG: define available_externally hidden void @funcwithpersonality.llvm.{{.*}}() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !thinlto_src_module !0 { ; INSTLIM5-DAG: declare hidden void @funcwithpersonality.llvm.{{.*}}() +; CHECK-DAG: declare void @variadic(...) +declare void @variadic(...) + ; INSTLIMDEF-DAG: Import globalfunc2 ; INSTLIMDEF-DAG: 13 function-import - Number of functions imported ; CHECK-DAG: !0 = !{!"{{.*}}/Inputs/funcimport.ll"} diff --git a/test/Transforms/FunctionImport/hotness_based_import.ll b/test/Transforms/FunctionImport/hotness_based_import.ll new file mode 100644 index 000000000000..9de8714072de --- /dev/null +++ b/test/Transforms/FunctionImport/hotness_based_import.ll @@ -0,0 +1,137 @@ +; Test to check the callgraph in summary when there is PGO +; RUN: opt -module-summary %s -o %t.bc +; RUN: opt -module-summary %p/Inputs/hotness_based_import.ll -o %t2.bc +; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc + +; Test import with default hot multiplier (3) and default hot-evolution-factor (1.0) +; 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 -import-cold-multiplier=0.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 | 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-instr-evolution-factor=0.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-hot-evolution-factor=1.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 @calledFromHot() +; HOT-DEFAULT-DAG: define available_externally void @calledFromHot2() +; 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() +; HOT-DEFAULT-NOT: define available_externally void @cold2() +; HOT-DEFAULT-NOT: define available_externally void @calledFromCold() +; HOT-DEFAULT-NOT: define available_externally void @calledFromNone() + +; This one tests if we decay threshold for hot callsites. With hot-evolution-factor of 0 +; we should not import any of calledFromHot functions +; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=1 --S -import-hot-multiplier=3.0 -import-hot-evolution-factor=0.0 | FileCheck %s --check-prefix=CHECK --check-prefix=HOT-EVOLUTION +; HOT-EVOLUTION-DAG: define available_externally void @hot1() +; HOT-EVOLUTION-DAG: define available_externally void @hot2() +; HOT-EVOLUTION-DAG: define available_externally void @none1() +; HOT-EVOLUTION-NOT: define available_externally void @hot3() +; HOT-EVOLUTION-NOT: define available_externally void @cold() +; HOT-EVOLUTION-NOT: define available_externally void @none2() +; HOT-EVOLUTION-NOT: define available_externally void @none3() +; HOT-EVOLUTION-NOT: define available_externally void @cold2() +; HOT-EVOLUTION-NOT: define available_externally void @calledFromHot() +; HOT-EVOLUTION-NOT: define available_externally void @calledFromHot2() + +; 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 @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 -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() +; HOT-ZERO-DAG: define available_externally void @none3() +; HOT-ZERO-DAG: define available_externally void @cold2() +; HOT-ZERO-DAG: define available_externally void @calledFromCold() +; HOT-ZERO-DAG: define available_externally void @calledFromNone() +; HOT-ZERO-NOT: define available_externally void @hot2() +; HOT-ZERO-NOT: define available_externally void @hot1() +; HOT-ZERO-NOT: define available_externally void @hot3() +; HOT-ZERO-NOT: define available_externally void @calledFromHot() +; HOT-ZERO-NOT: define available_externally void @calledFromHot2() + + +; ModuleID = 'thinlto-function-summary-callgraph.ll' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; This function have high profile count, so entry block is hot. +define void @hot_function(i1 %a, i1 %a2) !prof !20 { +entry: + call void @hot1() + br i1 %a, label %Cold, label %Hot, !prof !41 +Cold: ; 1/1000 goes here + call void @cold() + call void @cold2() + call void @hot2() + call void @none1() + br label %exit +Hot: ; 999/1000 goes here + call void @hot2() + call void @hot3() + br i1 %a2, label %None1, label %None2, !prof !42 +None1: ; half goes here + call void @none1() + call void @none2() + br label %exit +None2: ; half goes here + call void @none3() + br label %exit +exit: + ret void +} + +declare void @hot1() #1 +declare void @hot2() #1 +declare void @hot3() #1 +declare void @cold() #1 +declare void @cold2() #1 +declare void @none1() #1 +declare void @none2() #1 +declare void @none3() #1 + + +!41 = !{!"branch_weights", i32 1, i32 1000} +!42 = !{!"branch_weights", i32 1, i32 1} + + + +!llvm.module.flags = !{!1} +!20 = !{!"function_entry_count", i64 110} + +!1 = !{i32 1, !"ProfileSummary", !2} +!2 = !{!3, !4, !5, !6, !7, !8, !9, !10} +!3 = !{!"ProfileFormat", !"InstrProf"} +!4 = !{!"TotalCount", i64 10000} +!5 = !{!"MaxCount", i64 10} +!6 = !{!"MaxInternalCount", i64 1} +!7 = !{!"MaxFunctionCount", i64 1000} +!8 = !{!"NumCounts", i64 3} +!9 = !{!"NumFunctions", i64 3} +!10 = !{!"DetailedSummary", !11} +!11 = !{!12, !13, !14} +!12 = !{i32 10000, i64 100, i32 1} +!13 = !{i32 999000, i64 100, i32 1} +!14 = !{i32 999999, i64 1, i32 2} diff --git a/test/Transforms/FunctionImport/hotness_based_import2.ll b/test/Transforms/FunctionImport/hotness_based_import2.ll new file mode 100644 index 000000000000..50de33199f69 --- /dev/null +++ b/test/Transforms/FunctionImport/hotness_based_import2.ll @@ -0,0 +1,53 @@ +; Test to check that callee reached from cold and then hot path gets +; hot thresholds. +; RUN: opt -module-summary %s -o %t.bc +; RUN: opt -module-summary %p/Inputs/hotness_based_import2.ll -o %t2.bc +; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc + +; Teset with limit set to 10 and multipliers set to 1. Since cold call to +; hot is first in the other module, we'll first add calledFromHot to worklist +; with threshold decayed by default 0.7 factor. Test ensures that when we +; encounter it again from hot path, we re-enqueue with higher non-decayed +; threshold which will allow it to be imported. +; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -import-instr-limit=10 -import-hot-multiplier=1.0 -import-cold-multiplier=1.0 -S | FileCheck %s --check-prefix=CHECK +; CHECK-DAG: define available_externally void @hot() +; CHECK-DAG: define available_externally void @calledFromHot() + +; ModuleID = 'thinlto-function-summary-callgraph.ll' +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; This function has a high profile count, so entry block is hot. +define void @hot_function(i1 %a, i1 %a2) !prof !28 { +entry: + call void @hot() + ret void +} + +; This function has a low profile count, so entry block is hot. +define void @cold_function(i1 %a, i1 %a2) !prof !29 { +entry: + call void @hot() + ret void +} + +declare void @hot() #1 + +!llvm.module.flags = !{!1} + +!1 = !{i32 1, !"ProfileSummary", !2} +!2 = !{!3, !4, !5, !6, !7, !8, !9, !10} +!3 = !{!"ProfileFormat", !"InstrProf"} +!4 = !{!"TotalCount", i64 222} +!5 = !{!"MaxCount", i64 110} +!6 = !{!"MaxInternalCount", i64 1} +!7 = !{!"MaxFunctionCount", i64 110} +!8 = !{!"NumCounts", i64 4} +!9 = !{!"NumFunctions", i64 3} +!10 = !{!"DetailedSummary", !11} +!11 = !{!12, !13, !14} +!12 = !{i32 10000, i64 110, i32 2} +!13 = !{i32 999000, i64 2, i32 4} +!14 = !{i32 999999, i64 2, i32 4} +!28 = !{!"function_entry_count", i64 110} +!29 = !{!"function_entry_count", i64 1} diff --git a/test/Transforms/FunctionImport/inlineasm.ll b/test/Transforms/FunctionImport/inlineasm.ll index d0516f146534..de6fd7a9cfcd 100644 --- a/test/Transforms/FunctionImport/inlineasm.ll +++ b/test/Transforms/FunctionImport/inlineasm.ll @@ -6,7 +6,7 @@ ; Attempt the import now, ensure below that file containing inline assembly ; is not imported from. Otherwise we would need to promote its local variable ; used in the inline assembly, which would not see the rename. -; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s --check-prefix=CHECK +; RUN: opt -function-import -summary-file %t3.thinlto.bc %t.bc -S 2>&1 | FileCheck %s define i32 @main() #0 { entry: |
