diff --git a/lld/test/COFF/thinlto-index-only.ll b/lld/test/COFF/thinlto-index-only.ll --- a/lld/test/COFF/thinlto-index-only.ll +++ b/lld/test/COFF/thinlto-index-only.ll @@ -39,7 +39,6 @@ ; BACKEND2-NEXT: ; BACKEND2-NEXT: ; BACKEND2-NEXT: ; BACKEND2-NEXT: ; BACKEND2-NEXT: ; BACKEND2-NEXT: ScalePartialSampleProfileWorkingSetSize; + // Walk through the operands of a given User via worklist iteration and populate // the set of GlobalValue references encountered. Invoked either on an // Instruction or a GlobalVariable (which walks its initializer). @@ -477,7 +479,9 @@ } } } - Index.addBlockCount(F.size()); + + if (PSI->hasPartialSampleProfile() && ScalePartialSampleProfileWorkingSetSize) + Index.addBlockCount(F.size()); std::vector Refs; if (IsThinLTO) { diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4247,8 +4247,9 @@ NameVals.clear(); } - Stream.EmitRecord(bitc::FS_BLOCK_COUNT, - ArrayRef{Index->getBlockCount()}); + if (Index->getBlockCount()) + Stream.EmitRecord(bitc::FS_BLOCK_COUNT, + ArrayRef{Index->getBlockCount()}); Stream.ExitBlock(); } @@ -4578,8 +4579,9 @@ } } - Stream.EmitRecord(bitc::FS_BLOCK_COUNT, - ArrayRef{Index.getBlockCount()}); + if (Index.getBlockCount()) + Stream.EmitRecord(bitc::FS_BLOCK_COUNT, + ArrayRef{Index.getBlockCount()}); Stream.ExitBlock(); } diff --git a/llvm/test/Bitcode/Inputs/thinlto-function-summary-callgraph-partial-sample-profile-summary.ll b/llvm/test/Bitcode/Inputs/thinlto-function-summary-callgraph-partial-sample-profile-summary.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Bitcode/Inputs/thinlto-function-summary-callgraph-partial-sample-profile-summary.ll @@ -0,0 +1,50 @@ +; 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 { + ret void +} +define void @hot3() #1 { + ret void +} +define void @cold1() #1 { + ret void +} +define void @cold2() #1 { + ret void +} +define void @cold3() #1 { + ret void +} +define void @none1() #1 { + ret void +} +define void @none2() #1 { + ret void +} +define void @none3() #1 { + ret void +} + +!llvm.module.flags = !{!1} + +!1 = !{i32 1, !"ProfileSummary", !2} +!2 = !{!3, !4, !5, !6, !7, !8, !9, !10, !11, !12} +!3 = !{!"ProfileFormat", !"SampleProfile"} +!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 = !{!"IsPartialProfile", i64 1} +!11 = !{!"PartialProfileRatio", double 0.5} +!12 = !{!"DetailedSummary", !13} +!13 = !{!14, !15, !16} +!14 = !{i32 10000, i64 100, i32 1} +!15 = !{i32 999000, i64 100, i32 1} +!16 = !{i32 999999, i64 1, i32 2} diff --git a/llvm/test/Bitcode/thinlto-alias.ll b/llvm/test/Bitcode/thinlto-alias.ll --- a/llvm/test/Bitcode/thinlto-alias.ll +++ b/llvm/test/Bitcode/thinlto-alias.ll @@ -22,7 +22,6 @@ ; See if the call to func is registered. ; The value id 1 matches the second FUNCTION record above. ; CHECK-NEXT: -; CHECK-NEXT: ; CHECK-NEXT: ; CHECK: ; COMBINED-NEXT: ; COMBINED-NEXT: ; CHECK-NEXT: -; CHECK-NEXT: ; CHECK-NEXT: ; ModuleID = 'thinlto-alias2.ll' diff --git a/llvm/test/Bitcode/thinlto-function-summary-callgraph-cast.ll b/llvm/test/Bitcode/thinlto-function-summary-callgraph-cast.ll --- a/llvm/test/Bitcode/thinlto-function-summary-callgraph-cast.ll +++ b/llvm/test/Bitcode/thinlto-function-summary-callgraph-cast.ll @@ -12,7 +12,6 @@ ; CHECK-NEXT: ; CHECK-NEXT: -; CHECK-NEXT: ; CHECK-NEXT: ; ModuleID = 'thinlto-function-summary-callgraph-cast.ll' diff --git a/llvm/test/Bitcode/thinlto-function-summary-callgraph-sample-profile-summary.ll b/llvm/test/Bitcode/thinlto-function-summary-callgraph-partial-sample-profile-summary.ll copy from llvm/test/Bitcode/thinlto-function-summary-callgraph-sample-profile-summary.ll copy to llvm/test/Bitcode/thinlto-function-summary-callgraph-partial-sample-profile-summary.ll --- a/llvm/test/Bitcode/thinlto-function-summary-callgraph-sample-profile-summary.ll +++ b/llvm/test/Bitcode/thinlto-function-summary-callgraph-partial-sample-profile-summary.ll @@ -1,7 +1,7 @@ ; Test to check the callgraph in summary when there is PGO ; RUN: opt -module-summary %s -o %t.o ; RUN: llvm-bcanalyzer -dump %t.o | FileCheck %s -; RUN: opt -module-summary %p/Inputs/thinlto-function-summary-callgraph-sample-profile-summary.ll -o %t2.o +; RUN: opt -module-summary %p/Inputs/thinlto-function-summary-callgraph-partial-sample-profile-summary.ll -o %t2.o ; RUN: llvm-lto -thinlto -o %t3 %t.o %t2.o ; RUN: llvm-bcanalyzer -dump %t3.thinlto.bc | FileCheck %s --check-prefix=COMBINED @@ -30,9 +30,9 @@ ; CHECK-LABEL: +; CHECK-NEXT: ; op4=none1 op6=hot1 op8=cold1 op10=none2 op12=hot2 op14=cold2 op16=none3 op18=hot3 op20=cold3 op22=123 -; CHECK-NEXT: +; CHECK-NEXT: ; CHECK-NEXT: ; CHECK-NEXT: @@ -74,18 +74,18 @@ define void @hot_function(i1 %a, i1 %a2) !prof !20 { entry: call void @none1() - call void @hot1(), !prof !15 - call void @cold1(), !prof !16 + call void @hot1(), !prof !17 + call void @cold1(), !prof !18 br i1 %a, label %Cold, label %Hot, !prof !41 Cold: ; 1/1000 goes here call void @none2() - call void @hot2(), !prof !15 - call void @cold2(), !prof !16 + call void @hot2(), !prof !17 + call void @cold2(), !prof !18 br label %exit Hot: ; 999/1000 goes here call void @none3() - call void @hot3(), !prof !15 - call void @cold3(), !prof !16 + call void @hot3(), !prof !17 + call void @cold3(), !prof !18 br label %exit exit: ret void @@ -107,7 +107,7 @@ !20 = !{!"function_entry_count", i64 110, i64 123} !1 = !{i32 1, !"ProfileSummary", !2} -!2 = !{!3, !4, !5, !6, !7, !8, !9, !10} +!2 = !{!3, !4, !5, !6, !7, !8, !9, !10, !11, !12} !3 = !{!"ProfileFormat", !"SampleProfile"} !4 = !{!"TotalCount", i64 10000} !5 = !{!"MaxCount", i64 10} @@ -115,10 +115,12 @@ !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} -!15 = !{!"branch_weights", i32 100} -!16 = !{!"branch_weights", i32 1} +!10 = !{!"IsPartialProfile", i64 1} +!11 = !{!"PartialProfileRatio", double 0.5} +!12 = !{!"DetailedSummary", !13} +!13 = !{!14, !15, !16} +!14 = !{i32 10000, i64 100, i32 1} +!15 = !{i32 999000, i64 100, i32 1} +!16 = !{i32 999999, i64 1, i32 2} +!17 = !{!"branch_weights", i32 100} +!18 = !{!"branch_weights", i32 1} diff --git a/llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll b/llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll --- a/llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll +++ b/llvm/test/Bitcode/thinlto-function-summary-callgraph-pgo.ll @@ -19,7 +19,6 @@ ; CHECK-NEXT: -; CHECK-NEXT: ; CHECK-NEXT: ; CHECK: -; COMBINED-NEXT: ; COMBINED-NEXT: ; ModuleID = 'thinlto-function-summary-callgraph.ll' diff --git a/llvm/test/Bitcode/thinlto-function-summary-callgraph-profile-summary.ll b/llvm/test/Bitcode/thinlto-function-summary-callgraph-profile-summary.ll --- a/llvm/test/Bitcode/thinlto-function-summary-callgraph-profile-summary.ll +++ b/llvm/test/Bitcode/thinlto-function-summary-callgraph-profile-summary.ll @@ -50,7 +50,6 @@ ; CHECK-NEXT: ; op4=hot1 op6=cold op8=hot2 op10=hot4 op12=none1 op14=hot3 op16=none2 op18=none3 op20=123 ; CHECK-NEXT: -; CHECK-NEXT: ; CHECK-NEXT: ; CHECK: ; COMBINED-NEXT: ; COMBINED-NEXT: diff --git a/llvm/test/Bitcode/thinlto-function-summary-callgraph-relbf.ll b/llvm/test/Bitcode/thinlto-function-summary-callgraph-relbf.ll --- a/llvm/test/Bitcode/thinlto-function-summary-callgraph-relbf.ll +++ b/llvm/test/Bitcode/thinlto-function-summary-callgraph-relbf.ll @@ -15,7 +15,6 @@ ; CHECK-NEXT: ; CHECK-NEXT: ; CHECK: ; op4=none1 op6=hot1 op8=cold1 op10=none2 op12=hot2 op14=cold2 op16=none3 op18=hot3 op20=cold3 op22=123 ; CHECK-NEXT: -; CHECK-NEXT: ; CHECK-NEXT: ; CHECK: ; COMBINED-NEXT: ; COMBINED-NEXT: diff --git a/llvm/test/Bitcode/thinlto-function-summary-callgraph.ll b/llvm/test/Bitcode/thinlto-function-summary-callgraph.ll --- a/llvm/test/Bitcode/thinlto-function-summary-callgraph.ll +++ b/llvm/test/Bitcode/thinlto-function-summary-callgraph.ll @@ -20,7 +20,6 @@ ; CHECK-NEXT: ; CHECK-NEXT: ; CHECK: -; COMBINED-NEXT: ; COMBINED-NEXT: ; ModuleID = 'thinlto-function-summary-callgraph.ll' diff --git a/llvm/test/Bitcode/thinlto-function-summary-originalnames.ll b/llvm/test/Bitcode/thinlto-function-summary-originalnames.ll --- a/llvm/test/Bitcode/thinlto-function-summary-originalnames.ll +++ b/llvm/test/Bitcode/thinlto-function-summary-originalnames.ll @@ -15,7 +15,6 @@ ; COMBINED-DAG: ; COMBINED-DAG: -; COMBINED-NEXT: ; COMBINED-NEXT: source_filename = "/path/to/source.c" diff --git a/llvm/test/Bitcode/thinlto-function-summary-paramaccess.ll b/llvm/test/Bitcode/thinlto-function-summary-paramaccess.ll --- a/llvm/test/Bitcode/thinlto-function-summary-paramaccess.ll +++ b/llvm/test/Bitcode/thinlto-function-summary-paramaccess.ll @@ -338,4 +338,3 @@ ; COMBINED-NEXT: ; COMBINED-NEXT: \ No newline at end of file diff --git a/llvm/test/Bitcode/thinlto-function-summary.ll b/llvm/test/Bitcode/thinlto-function-summary.ll --- a/llvm/test/Bitcode/thinlto-function-summary.ll +++ b/llvm/test/Bitcode/thinlto-function-summary.ll @@ -24,7 +24,6 @@ ; BC-NEXT: ; BC-NEXT: ; BACKEND1-NEXT: ; BACKEND2-NEXT: ; COMBINED-NEXT: