[llvm] r346971 - [LTO] Load sample profile in LTO link step.
Xin Tong via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 15 10:06:42 PST 2018
Author: trentxintong
Date: Thu Nov 15 10:06:42 2018
New Revision: 346971
URL: http://llvm.org/viewvc/llvm-project?rev=346971&view=rev
Log:
[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
Added:
llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-lto.ll
Modified:
llvm/trunk/lib/Passes/PassBuilder.cpp
llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=346971&r1=346970&r2=346971&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Thu Nov 15 10:06:42 2018
@@ -1004,6 +1004,13 @@ PassBuilder::buildLTODefaultPipeline(Opt
assert(Level != O0 && "Must request optimizations for the default pipeline!");
ModulePassManager MPM(DebugLogging);
+ if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
+ // Load sample profile before running the LTO optimization pipeline.
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile,
+ PGOOpt->ProfileRemappingFile,
+ false /* ThinLTOPhase::PreLink */));
+ }
+
// Remove unused virtual tables to improve the quality of code generated by
// whole-program devirtualization and bitset lowering.
MPM.addPass(GlobalDCEPass());
Modified: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=346971&r1=346970&r2=346971&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp Thu Nov 15 10:06:42 2018
@@ -747,6 +747,12 @@ void PassManagerBuilder::populateModuleP
}
void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
+ // Load sample profile before running the LTO optimization pipeline.
+ if (!PGOSampleUse.empty()) {
+ PM.add(createPruneEHPass());
+ PM.add(createSampleProfileLoaderPass(PGOSampleUse));
+ }
+
// Remove unused virtual tables to improve the quality of code generated by
// whole-program devirtualization and bitset lowering.
PM.add(createGlobalDCEPass());
Added: llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-lto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-lto.ll?rev=346971&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-lto.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-lto.ll Thu Nov 15 10:06:42 2018
@@ -0,0 +1,46 @@
+; Test that LTO pipeline loads profile.
+;
+; RUN: opt < %s -o %t.bc
+
+; Run the old pm LTO pipeline.
+; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps \
+; RUN: -r %t.bc,foo,px -r %t.bc,bar,x \
+; RUN: -lto-sample-profile-file=%S/Inputs/load-sample-prof.prof
+; RUN: llvm-dis %t.out.0.4.opt.bc -o - | FileCheck %s
+
+; Run the new pm LTO pipeline.
+; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps -use-new-pm \
+; RUN: -r %t.bc,foo,px -r %t.bc,bar,x \
+; RUN: -lto-sample-profile-file=%S/Inputs/load-sample-prof.prof
+; RUN: llvm-dis %t.out.0.4.opt.bc -o - | FileCheck %s
+
+; Make sure profile information is attached.
+; CHECK: !prof
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @foo() local_unnamed_addr !dbg !7 {
+entry:
+ tail call void @bar(), !dbg !10
+ ret void, !dbg !11
+}
+
+declare void @bar() local_unnamed_addr
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "/tmp")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 6.0.0 "}
+!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)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !DILocation(line: 4, column: 5, scope: !7)
+!11 = !DILocation(line: 5, column: 1, scope: !7)
More information about the llvm-commits
mailing list