[llvm] r309780 - Update the new PM pipeline to make ICP aware if it is SamplePGO build.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 1 18:28:31 PDT 2017
Author: dehao
Date: Tue Aug 1 18:28:31 2017
New Revision: 309780
URL: http://llvm.org/viewvc/llvm-project?rev=309780&view=rev
Log:
Update the new PM pipeline to make ICP aware if it is SamplePGO build.
Summary: In ThinLTO backend compile, OPTOptions are not set so that the ICP in ThinLTO backend does not know if it is a SamplePGO build, in which profile count needs to be annotated directly on call instructions. This patch cleaned up the PGOOptions handling logic and passes down PGOOptions to ThinLTO backend.
Reviewers: chandlerc, tejohnson, davidxl
Reviewed By: chandlerc
Subscribers: sanjoy, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D36052
Added:
llvm/trunk/test/LTO/Resolution/X86/Inputs/load-sample-prof-icp.prof
llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-icp.ll
Modified:
llvm/trunk/lib/LTO/LTOBackend.cpp
llvm/trunk/lib/Passes/PassBuilder.cpp
Modified: llvm/trunk/lib/LTO/LTOBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOBackend.cpp?rev=309780&r1=309779&r2=309780&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOBackend.cpp (original)
+++ llvm/trunk/lib/LTO/LTOBackend.cpp Tue Aug 1 18:28:31 2017
@@ -131,9 +131,13 @@ createTargetMachine(Config &Conf, const
Conf.CodeModel, Conf.CGOptLevel));
}
-static void runNewPMPasses(Module &Mod, TargetMachine *TM, unsigned OptLevel,
- bool IsThinLTO) {
- PassBuilder PB(TM);
+static void runNewPMPasses(Config &Conf, Module &Mod, TargetMachine *TM,
+ unsigned OptLevel, bool IsThinLTO) {
+ Optional<PGOOptions> PGOOpt;
+ if (!Conf.SampleProfile.empty())
+ PGOOpt = PGOOptions("", "", Conf.SampleProfile, false, true);
+
+ PassBuilder PB(TM, PGOOpt);
AAManager AA;
// Parse a custom AA pipeline if asked to.
@@ -262,7 +266,7 @@ bool opt(Config &Conf, TargetMachine *TM
runNewPMCustomPasses(Mod, TM, Conf.OptPipeline, Conf.AAPipeline,
Conf.DisableVerify);
else if (Conf.UseNewPM)
- runNewPMPasses(Mod, TM, Conf.OptLevel, IsThinLTO);
+ runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO);
else
runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary);
return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=309780&r1=309779&r2=309780&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Tue Aug 1 18:28:31 2017
@@ -571,23 +571,12 @@ PassBuilder::buildModuleSimplificationPi
GlobalCleanupPM.addPass(SimplifyCFGPass());
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
- // Add all the requested passes for PGO, if requested.
- if (PGOOpt) {
- if (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())
- // Instrumentation based PGO (gen and use)
- addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
- PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
- else if (!PGOOpt->SampleProfileFile.empty())
- // SamplePGO use
- MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
-
- // Indirect call promotion that promotes intra-module targes only.
- // Do not enable it in PreLinkThinLTO phase during sample PGO because
- // it changes IR to makes profile annotation in back compile inaccurate.
- if ((Phase != ThinLTOPhase::PreLink && !PGOOpt->SampleProfileFile.empty())
- || !PGOOpt->ProfileUseFile.empty())
- MPM.addPass(PGOIndirectCallPromotion(
- false, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
+ // Add all the requested passes for instrumentation PGO, if requested.
+ if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
+ (!PGOOpt->ProfileGenFile.empty() || !PGOOpt->ProfileUseFile.empty())) {
+ addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
+ PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
+ MPM.addPass(PGOIndirectCallPromotion(false, false));
}
// Require the GlobalsAA analysis for the module so we can query it within
@@ -779,8 +768,13 @@ PassBuilder::buildPerModuleDefaultPipeli
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
- if (PGOOpt && PGOOpt->SamplePGOSupport)
+ if (PGOOpt && PGOOpt->SamplePGOSupport) {
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
+ if (!PGOOpt->SampleProfileFile.empty()) {
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
+ MPM.addPass(PGOIndirectCallPromotion(false, true));
+ }
+ }
// Add the core simplification pipeline.
MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
@@ -802,8 +796,14 @@ PassBuilder::buildThinLTOPreLinkDefaultP
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
- if (PGOOpt && PGOOpt->SamplePGOSupport)
+ // Invoke the SamplePGO annotation pass for the first time to annotate
+ // profile for functions in the current module to give ThinLink info
+ // about module grouping.
+ if (PGOOpt && PGOOpt->SamplePGOSupport) {
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
+ if (!PGOOpt->SampleProfileFile.empty())
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
+ }
// If we are planning to perform ThinLTO later, we don't bloat the code with
// unrolling/vectorization/... now. Just simplify the module as much as we
@@ -839,12 +839,16 @@ PassBuilder::buildThinLTODefaultPipeline
// Force any function attributes we want the rest of the pipeline to observe.
MPM.addPass(ForceFunctionAttrsPass());
+ // Invoke the SamplePGO annotation pass for the second time to annotate on
+ // functions imported from other modules.
+ if (PGOOpt && !PGOOpt->SampleProfileFile.empty())
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
+
// During the ThinLTO backend phase we perform early indirect call promotion
// here, before globalopt. Otherwise imported available_externally functions
// look unreferenced and are removed.
MPM.addPass(PGOIndirectCallPromotion(
- true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
- !PGOOpt->ProfileUseFile.empty()));
+ true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
// Add the core simplification pipeline.
MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
Added: llvm/trunk/test/LTO/Resolution/X86/Inputs/load-sample-prof-icp.prof
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/Inputs/load-sample-prof-icp.prof?rev=309780&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/Inputs/load-sample-prof-icp.prof (added)
+++ llvm/trunk/test/LTO/Resolution/X86/Inputs/load-sample-prof-icp.prof Tue Aug 1 18:28:31 2017
@@ -0,0 +1,2 @@
+test:1000:0
+ 1: 1000 bar:1000
Added: llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-icp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-icp.ll?rev=309780&view=auto
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-icp.ll (added)
+++ llvm/trunk/test/LTO/Resolution/X86/load-sample-prof-icp.ll Tue Aug 1 18:28:31 2017
@@ -0,0 +1,46 @@
+; Test that llvm-lto2 handles the -lto-sample-profile-file option and pass
+; down to the ICP correctly.
+;
+; RUN: opt -module-summary < %s -o %t.bc
+; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps \
+; RUN: -r %t.bc,test,px -r %t.bc,bar,x \
+; RUN: -lto-sample-profile-file=%S/Inputs/load-sample-prof-icp.prof
+; RUN: llvm-dis %t.out.0.4.opt.bc -o - | FileCheck %s
+; RUN: llvm-lto2 run -o %t.out %t.bc -save-temps \
+; RUN: -r %t.bc,test,px -r %t.bc,bar,x -use-new-pm \
+; RUN: -lto-sample-profile-file=%S/Inputs/load-sample-prof-icp.prof
+; RUN: llvm-dis %t.out.0.4.opt.bc -o - | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: @test
+; Checks that the call instruction is promoted to direct call and has
+; profile count annotated on the direct call.
+define void @test(void ()*) !dbg !7 {
+ %2 = alloca void ()*
+ store void ()* %0, void ()** %2
+ %3 = load void ()*, void ()** %2
+ ; CHECK: call void @bar(),{{.*}}!prof
+ call void %3(), !dbg !10
+ ret void
+}
+
+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: "test", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !0, variables: !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