Skip to content

Commit 642c8d3

Browse files
committed
[LTO] Load sample profile in LTO link step.
Summary: Load sample profile in LTO link step. ThinLTO calls populateModulePassManager to load the profile Reviewers: tejohnson, davidxl, danielcdh Subscribers: mehdi_amini, inglorion, steven_wu, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D54564 llvm-svn: 346971
1 parent 924f193 commit 642c8d3

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,13 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging,
10041004
assert(Level != O0 && "Must request optimizations for the default pipeline!");
10051005
ModulePassManager MPM(DebugLogging);
10061006

1007+
if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
1008+
// Load sample profile before running the LTO optimization pipeline.
1009+
MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile,
1010+
PGOOpt->ProfileRemappingFile,
1011+
false /* ThinLTOPhase::PreLink */));
1012+
}
1013+
10071014
// Remove unused virtual tables to improve the quality of code generated by
10081015
// whole-program devirtualization and bitset lowering.
10091016
MPM.addPass(GlobalDCEPass());

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,12 @@ void PassManagerBuilder::populateModulePassManager(
747747
}
748748

749749
void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
750+
// Load sample profile before running the LTO optimization pipeline.
751+
if (!PGOSampleUse.empty()) {
752+
PM.add(createPruneEHPass());
753+
PM.add(createSampleProfileLoaderPass(PGOSampleUse));
754+
}
755+
750756
// Remove unused virtual tables to improve the quality of code generated by
751757
// whole-program devirtualization and bitset lowering.
752758
PM.add(createGlobalDCEPass());
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; Test that LTO pipeline loads profile.
2+
;
3+
; RUN: opt < %s -o %t.bc
4+
5+
; Run the old pm LTO pipeline.
6+
; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps \
7+
; RUN: -r %t.bc,foo,px -r %t.bc,bar,x \
8+
; RUN: -lto-sample-profile-file=%S/Inputs/load-sample-prof.prof
9+
; RUN: llvm-dis %t.out.0.4.opt.bc -o - | FileCheck %s
10+
11+
; Run the new pm LTO pipeline.
12+
; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps -use-new-pm \
13+
; RUN: -r %t.bc,foo,px -r %t.bc,bar,x \
14+
; RUN: -lto-sample-profile-file=%S/Inputs/load-sample-prof.prof
15+
; RUN: llvm-dis %t.out.0.4.opt.bc -o - | FileCheck %s
16+
17+
; Make sure profile information is attached.
18+
; CHECK: !prof
19+
20+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
21+
target triple = "x86_64-unknown-linux-gnu"
22+
23+
define void @foo() local_unnamed_addr !dbg !7 {
24+
entry:
25+
tail call void @bar(), !dbg !10
26+
ret void, !dbg !11
27+
}
28+
29+
declare void @bar() local_unnamed_addr
30+
31+
!llvm.dbg.cu = !{!0}
32+
!llvm.module.flags = !{!3, !4, !5}
33+
!llvm.ident = !{!6}
34+
35+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
36+
!1 = !DIFile(filename: "test.c", directory: "/tmp")
37+
!2 = !{}
38+
!3 = !{i32 2, !"Dwarf Version", i32 4}
39+
!4 = !{i32 2, !"Debug Info Version", i32 3}
40+
!5 = !{i32 1, !"wchar_size", i32 4}
41+
!6 = !{!"clang version 6.0.0 "}
42+
!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !0, retainedNodes: !2)
43+
!8 = !DISubroutineType(types: !9)
44+
!9 = !{null}
45+
!10 = !DILocation(line: 4, column: 5, scope: !7)
46+
!11 = !DILocation(line: 5, column: 1, scope: !7)

0 commit comments

Comments
 (0)