llvm.org GIT mirror llvm / ea2fb7d
[PM] port IR based PGO prof-gen pass to new pass manager git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268710 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 3 years ago
20 changed file(s) with 85 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
122122 void initializeExpandPostRAPass(PassRegistry&);
123123 void initializeAAResultsWrapperPassPass(PassRegistry &);
124124 void initializeGCOVProfilerPass(PassRegistry&);
125 void initializePGOInstrumentationGenPass(PassRegistry&);
125 void initializePGOInstrumentationGenLegacyPassPass(PassRegistry&);
126126 void initializePGOInstrumentationUsePass(PassRegistry&);
127127 void initializePGOIndirectCallPromotionPass(PassRegistry&);
128128 void initializeInstrProfilingLegacyPassPass(PassRegistry &);
8888 (void) llvm::createDomOnlyViewerPass();
8989 (void) llvm::createDomViewerPass();
9090 (void) llvm::createGCOVProfilerPass();
91 (void) llvm::createPGOInstrumentationGenPass();
91 (void) llvm::createPGOInstrumentationGenLegacyPass();
9292 (void) llvm::createPGOInstrumentationUsePass();
9393 (void) llvm::createPGOIndirectCallPromotionPass();
9494 (void) llvm::createInstrProfilingLegacyPass();
7979 GCOVOptions::getDefault());
8080
8181 // PGO Instrumention
82 ModulePass *createPGOInstrumentationGenPass();
82 ModulePass *createPGOInstrumentationGenLegacyPass();
8383 ModulePass *
8484 createPGOInstrumentationUsePass(StringRef Filename = StringRef(""));
8585 ModulePass *createPGOIndirectCallPromotionPass(bool InLTO = false);
0 //===- Transforms/PGOInstrumentation.h - PGO gen/use passes ---*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This file provides the interface for IR based instrumentation passes (
10 /// (profile-gen, and profile-use).
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
14 #define LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
15
16 #include "llvm/IR/IntrinsicInst.h"
17 #include "llvm/IR/PassManager.h"
18 #include "llvm/ProfileData/InstrProf.h"
19 #include "llvm/Transforms/Instrumentation.h"
20
21 namespace llvm {
22
23 /// The instrumentation (profile-instr-gen) pass for IR based PGO.
24 class PGOInstrumentationGen : public PassInfoMixin {
25 public:
26 PGOInstrumentationGen() {}
27
28 PreservedAnalyses run(Module &M, AnalysisManager &AM);
29 };
30
31 } // End llvm namespace
32 #endif
5959 #include "llvm/Transforms/IPO/StripDeadPrototypes.h"
6060 #include "llvm/Transforms/InstCombine/InstCombine.h"
6161 #include "llvm/Transforms/InstrProfiling.h"
62 #include "llvm/Transforms/PGOInstrumentation.h"
6263 #include "llvm/Transforms/Scalar/ADCE.h"
6364 #include "llvm/Transforms/Scalar/DCE.h"
6465 #include "llvm/Transforms/Scalar/EarlyCSE.h"
4545 MODULE_PASS("invalidate", InvalidateAllAnalysesPass())
4646 MODULE_PASS("ipsccp", IPSCCPPass())
4747 MODULE_PASS("no-op-module", NoOpModulePass())
48 MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
4849 MODULE_PASS("print", PrintModulePass(dbgs()))
4950 MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))
5051 MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
211211 // Do PGO instrumentation generation or use pass as the option specified.
212212 void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) {
213213 if (!PGOInstrGen.empty()) {
214 MPM.add(createPGOInstrumentationGenPass());
214 MPM.add(createPGOInstrumentationGenLegacyPass());
215215 // Add the profile lowering pass.
216216 InstrProfOptions Options;
217217 Options.InstrProfileOutput = PGOInstrGen;
5959 initializeAddressSanitizerModulePass(Registry);
6060 initializeBoundsCheckingPass(Registry);
6161 initializeGCOVProfilerPass(Registry);
62 initializePGOInstrumentationGenPass(Registry);
62 initializePGOInstrumentationGenLegacyPassPass(Registry);
6363 initializePGOInstrumentationUsePass(Registry);
6464 initializePGOIndirectCallPromotionPass(Registry);
6565 initializeInstrProfilingLegacyPassPass(Registry);
4747 //
4848 //===----------------------------------------------------------------------===//
4949
50 #include "llvm/Transforms/PGOInstrumentation.h"
5051 #include "CFGMST.h"
5152 #include "IndirectCallSiteVisitor.h"
5253 #include "llvm/ADT/STLExtras.h"
7071 #include "llvm/Support/JamCRC.h"
7172 #include "llvm/Transforms/Instrumentation.h"
7273 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
74 #include
7375 #include
7476 #include
7577 #include
109111 "call callsite"));
110112
111113 namespace {
112 class PGOInstrumentationGen : public ModulePass {
114 class PGOInstrumentationGenLegacyPass : public ModulePass {
113115 public:
114116 static char ID;
115117
116 PGOInstrumentationGen() : ModulePass(ID) {
117 initializePGOInstrumentationGenPass(*PassRegistry::getPassRegistry());
118 PGOInstrumentationGenLegacyPass() : ModulePass(ID), PGOInstrGen() {
119 initializePGOInstrumentationGenLegacyPassPass(
120 *PassRegistry::getPassRegistry());
118121 }
119122
120123 const char *getPassName() const override {
122125 }
123126
124127 private:
128 PGOInstrumentationGen PGOInstrGen;
125129 bool runOnModule(Module &M) override;
126130
127131 void getAnalysisUsage(AnalysisUsage &AU) const override {
156160 };
157161 } // end anonymous namespace
158162
159 char PGOInstrumentationGen::ID = 0;
160 INITIALIZE_PASS_BEGIN(PGOInstrumentationGen, "pgo-instr-gen",
163 char PGOInstrumentationGenLegacyPass::ID = 0;
164 INITIALIZE_PASS_BEGIN(PGOInstrumentationGenLegacyPass, "pgo-instr-gen",
161165 "PGO instrumentation.", false, false)
162166 INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
163167 INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)
164 INITIALIZE_PASS_END(PGOInstrumentationGen, "pgo-instr-gen",
168 INITIALIZE_PASS_END(PGOInstrumentationGenLegacyPass, "pgo-instr-gen",
165169 "PGO instrumentation.", false, false)
166170
167 ModulePass *llvm::createPGOInstrumentationGenPass() {
168 return new PGOInstrumentationGen();
171 ModulePass *llvm::createPGOInstrumentationGenLegacyPass() {
172 return new PGOInstrumentationGenLegacyPass();
169173 }
170174
171175 char PGOInstrumentationUse::ID = 0;
787791 return true;
788792 }
789793
790 bool PGOInstrumentationGen::runOnModule(Module &M) {
794 bool PGOInstrumentationGenLegacyPass::runOnModule(Module &M) {
791795 if (skipModule(M))
792796 return false;
793797
798802 return this->getAnalysis(F).getBFI();
799803 };
800804 return InstrumentAllFunctions(M, LookupBPI, LookupBFI);
805 }
806
807 PreservedAnalyses PGOInstrumentationGen::run(Module &M,
808 AnalysisManager &AM) {
809
810 auto &FAM = AM.getResult(M).getManager();
811 auto LookupBPI = [&FAM](Function &F) -> BranchProbabilityInfo & {
812 return FAM.getResult(F);
813 };
814
815 auto LookupBFI = [&FAM](Function &F) -> BlockFrequencyInfo & {
816 return FAM.getResult(F);
817 };
818
819 if (!InstrumentAllFunctions(M, LookupBPI, LookupBFI))
820 return PreservedAnalyses::all();
821
822 return PreservedAnalyses::none();
801823 }
802824
803825 static void setPGOCountOnFunc(PGOUseFunc &Func,
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-COMDAT
11 ; RUN: opt < %s -mtriple=x86_64-apple-darwin -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-DARWIN-LINKONCE
2
3 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-COMDAT
4 ; RUN: opt < %s -mtriple=x86_64-apple-darwin -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-DARWIN-LINKONCE
5
26 ; RUN: llvm-profdata merge %S/Inputs/branch1.proftext -o %t.profdata
37 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
48 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
1 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
12 ; RUN: llvm-profdata merge %S/Inputs/branch2.proftext -o %t.profdata
23 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
34 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
0 ; RUN: opt < %s -pgo-instr-gen -instrprof -S | FileCheck %s
1 ; RUN: opt < %s -passes=pgo-instr-gen,instrprof -S | FileCheck %s
12 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
23 target triple = "x86_64-unknown-linux-gnu"
34
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
1 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
12 ; RUN: llvm-profdata merge %S/Inputs/criticaledge.proftext -o %t.profdata
23 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
34 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
1 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
12
23 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
34 target triple = "x86_64-apple-macosx10.12.0"
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
1 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
12 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
23 target triple = "x86_64-unknown-linux-gnu"
34
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
1 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
12 ; RUN: llvm-profdata merge %S/Inputs/landingpad.proftext -o %t.profdata
23 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
34 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
1 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
12 ; RUN: llvm-profdata merge %S/Inputs/loop1.proftext -o %t.profdata
23 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
34 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
1 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
12 ; RUN: llvm-profdata merge %S/Inputs/loop2.proftext -o %t.profdata
23 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
34 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
1 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
12 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
23 target triple = "x86_64-unknown-linux-gnu"
34
0 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
1 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
12 ; RUN: llvm-profdata merge %S/Inputs/switch.proftext -o %t.profdata
23 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
34 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"