From e536db08ac81c41f614ed1c5502d3abd023df376 Mon Sep 17 00:00:00 2001 From: Dehao Chen Date: Tue, 19 Sep 2017 21:18:14 +0000 Subject: [PATCH] Import all inlined indirect call targets for SamplePGO. Summary: In the ThinLTO compilation, if a function is inlined in the profiling binary, we need to inline it before annotation. If the callee is not available in the primary module, a first step is needed to import that callee function. For the current implementation, if the call is an indirect call, which has been promoted to >1 targets and inlined, SamplePGO will only import one target with the largest sample count. This patch fixed the bug to import all targets instead. Reviewers: tejohnson, davidxl Reviewed By: tejohnson Subscribers: sanjoy, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D36637 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313678 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/SampleProfile.cpp | 8 +++++--- test/Transforms/SampleProfile/Inputs/import.prof | 6 +++++- test/Transforms/SampleProfile/import.ll | 16 +++++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/Transforms/IPO/SampleProfile.cpp b/lib/Transforms/IPO/SampleProfile.cpp index 039fed0360f..5258746dbb9 100644 --- a/lib/Transforms/IPO/SampleProfile.cpp +++ b/lib/Transforms/IPO/SampleProfile.cpp @@ -756,9 +756,11 @@ bool SampleProfileLoader::inlineHotFunctions( continue; } if (!CalledFunction || !CalledFunction->getSubprogram()) { - findCalleeFunctionSamples(*I)->findImportedFunctions( - ImportGUIDs, F.getParent(), - Samples->getTotalSamples() * SampleProfileHotThreshold / 100); + // Handles functions that are imported from other modules. + for (const FunctionSamples *FS : findIndirectCallFunctionSamples(*I)) + FS->findImportedFunctions( + ImportGUIDs, F.getParent(), + Samples->getTotalSamples() * SampleProfileHotThreshold / 100); continue; } assert(isa(DI) || isa(DI)); diff --git a/test/Transforms/SampleProfile/Inputs/import.prof b/test/Transforms/SampleProfile/Inputs/import.prof index efadc0c5c9c..aae072ac191 100644 --- a/test/Transforms/SampleProfile/Inputs/import.prof +++ b/test/Transforms/SampleProfile/Inputs/import.prof @@ -1,4 +1,8 @@ -main:10000:0 +test:10000:0 3: foo:1000 3: bar:200 4: baz:10 + 4: foo1:1000 + 1: 1000 + 4: foo2:1000 + 1: 1000 diff --git a/test/Transforms/SampleProfile/import.ll b/test/Transforms/SampleProfile/import.ll index 1ee45fb4fd3..ad9c2d55aa9 100644 --- a/test/Transforms/SampleProfile/import.ll +++ b/test/Transforms/SampleProfile/import.ll @@ -5,14 +5,19 @@ declare void @foo() -define void @main() !dbg !7 { +define void @test(void ()*) !dbg !7 { + %2 = alloca void ()* + store void ()* %0, void ()** %2 + %3 = load void ()*, void ()** %2 + ; CHECK: call {{.*}}, !prof ![[PROF:[0-9]+]] call void @foo(), !dbg !18 + call void %3(), !dbg !19 ret void } -; GUIDs of foo and bar should be included in the metadata to make sure hot -; inline stacks are imported. -; CHECK: !{!"function_entry_count", i64 1, i64 6699318081062747564, i64 -2012135647395072713} +; GUIDs of foo, bar, foo1 and foo2 should be included in the metadata to make +; sure hot inline stacks are imported. +; CHECK: !{!"function_entry_count", i64 1, i64 2494702099028631698, i64 6699318081062747564, i64 7682762345278052905, i64 -2012135647395072713} !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!8, !9} @@ -22,10 +27,11 @@ define void @main() !dbg !7 { !1 = !DIFile(filename: "calls.cc", directory: ".") !2 = !{} !6 = !DISubroutineType(types: !2) -!7 = distinct !DISubprogram(name: "main", line: 7, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 7, file: !1, scope: !1, type: !6, variables: !2) +!7 = distinct !DISubprogram(name: "test", line: 7, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 7, file: !1, scope: !1, type: !6, variables: !2) !8 = !{i32 2, !"Dwarf Version", i32 4} !9 = !{i32 1, !"Debug Info Version", i32 3} !10 = !{!"clang version 3.5 "} !15 = !DILexicalBlockFile(discriminator: 1, file: !1, scope: !7) !17 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !7) !18 = !DILocation(line: 10, scope: !17) +!19 = !DILocation(line: 11, scope: !17)