llvm.org GIT mirror llvm / e052ee9
[PM]: port IR based profUse pass to new pass manager git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269129 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 3 years ago
15 changed file(s) with 60 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
1414 #define LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
1515
16 #include "llvm/IR/IntrinsicInst.h"
1716 #include "llvm/IR/PassManager.h"
18 #include "llvm/ProfileData/InstrProf.h"
1917 #include "llvm/Transforms/Instrumentation.h"
2018
2119 namespace llvm {
2624 PreservedAnalyses run(Module &M, AnalysisManager &AM);
2725 };
2826
27 /// The profile annotation (profile-instr-use) pass for IR based PGO.
28 class PGOInstrumentationUse : public PassInfoMixin {
29 public:
30 PreservedAnalyses run(Module &M, AnalysisManager &AM);
31 PGOInstrumentationUse(std::string Filename = "");
32
33 private:
34 std::string ProfileFileName;
35 };
36
2937 } // End llvm namespace
3038 #endif
4747 MODULE_PASS("ipsccp", IPSCCPPass())
4848 MODULE_PASS("no-op-module", NoOpModulePass())
4949 MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
50 MODULE_PASS("pgo-instr-use", PGOInstrumentationUse())
5051 MODULE_PASS("print", PrintModulePass(dbgs()))
5152 MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))
5253 MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
150150 }
151151
152152 private:
153 bool annotateAllFunctions(
154 Module &M, function_ref LookupBPI,
155 function_ref LookupBFI);
156153 std::string ProfileFileName;
157 std::unique_ptr PGOReader;
154
158155 bool runOnModule(Module &M) override;
159
160156 void getAnalysisUsage(AnalysisUsage &AU) const override {
161157 AU.addRequired();
162158 }
834830 }
835831 }
836832
837 bool PGOInstrumentationUseLegacyPass::annotateAllFunctions(
838 Module &M, function_ref LookupBPI,
833 static bool annotateAllFunctions(
834 Module &M, StringRef ProfileFileName,
835 function_ref LookupBPI,
839836 function_ref LookupBFI) {
840837 DEBUG(dbgs() << "Read in profile counters: ");
841838 auto &Ctx = M.getContext();
847844 return false;
848845 }
849846
850 PGOReader = std::move(ReaderOrErr.get());
847 std::unique_ptr PGOReader =
848 std::move(ReaderOrErr.get());
851849 if (!PGOReader) {
852850 Ctx.diagnose(DiagnosticInfoPGOProfile(ProfileFileName.data(),
853 "Cannot get PGOReader"));
851 StringRef("Cannot get PGOReader")));
854852 return false;
855853 }
856854 // TODO: might need to change the warning once the clang option is finalized.
890888 return true;
891889 }
892890
891 PGOInstrumentationUse::PGOInstrumentationUse(std::string Filename)
892 : ProfileFileName(Filename) {
893 if (!PGOTestProfileFile.empty())
894 ProfileFileName = PGOTestProfileFile;
895 }
896
897 PreservedAnalyses PGOInstrumentationUse::run(Module &M,
898 AnalysisManager &AM) {
899
900 auto &FAM = AM.getResult(M).getManager();
901 auto LookupBPI = [&FAM](Function &F) {
902 return &FAM.getResult(F);
903 };
904
905 auto LookupBFI = [&FAM](Function &F) {
906 return &FAM.getResult(F);
907 };
908
909 if (!annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI))
910 return PreservedAnalyses::all();
911
912 return PreservedAnalyses::none();
913 }
914
893915 bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) {
894916 if (skipModule(M))
895917 return false;
901923 return &this->getAnalysis(F).getBFI();
902924 };
903925
904 return annotateAllFunctions(M, LookupBPI, LookupBFI);
905 }
926 return annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI);
927 }
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
22
3 ; New PM
34 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-COMDAT
45 ; RUN: opt < %s -mtriple=x86_64-apple-darwin -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-DARWIN-LINKONCE
56
67 ; RUN: llvm-profdata merge %S/Inputs/branch1.proftext -o %t.profdata
78 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
9
10 ; New PM
11 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
12
813 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
914 target triple = "x86_64-unknown-linux-gnu"
1015 ; GEN-DARWIN-LINKONCE: target triple = "x86_64-apple-darwin"
11 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
22 ; RUN: llvm-profdata merge %S/Inputs/branch2.proftext -o %t.profdata
33 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
4 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
45 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
56 target triple = "x86_64-unknown-linux-gnu"
67
11 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
22 ; RUN: llvm-profdata merge %S/Inputs/criticaledge.proftext -o %t.profdata
33 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
4 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
45 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
56 target triple = "x86_64-unknown-linux-gnu"
67
0 ; RUN: llvm-profdata merge %S/Inputs/diag_FE.proftext -o %t.profdata
11 ; RUN: not opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
2 ; RUN: not opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
23
34 ; CHECK: Not an IR level instrumentation profile
45
0 ; RUN: llvm-profdata merge %S/Inputs/diag.proftext -o %t.profdata
11 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
2 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
23
34 ; CHECK: Function control flow change detected (hash mismatch) foo
45
0 ; RUN: llvm-profdata merge %S/Inputs/diag.proftext -o %t.profdata
11 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
2 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
23
34 ; CHECK: No profile data available for function bar
45
0 ; RUN: not opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1
1 ; RUN: not opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1
12
23 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
34 target triple = "x86_64-unknown-linux-gnu"
0 ; RUN: llvm-profdata merge %S/Inputs/indirect_call.proftext -o %t.profdata
11 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=VP-ANNOTATION
2 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=VP-ANNOTATION
23 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
34 target triple = "x86_64-unknown-linux-gnu"
45
11 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
22 ; RUN: llvm-profdata merge %S/Inputs/landingpad.proftext -o %t.profdata
33 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
4 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
45 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
56 target triple = "x86_64-unknown-linux-gnu"
67
11 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
22 ; RUN: llvm-profdata merge %S/Inputs/loop1.proftext -o %t.profdata
33 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
4 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
45 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
56 target triple = "x86_64-unknown-linux-gnu"
67
11 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
22 ; RUN: llvm-profdata merge %S/Inputs/loop2.proftext -o %t.profdata
33 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
4 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
45 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
56 target triple = "x86_64-unknown-linux-gnu"
67
11 ; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
22 ; RUN: llvm-profdata merge %S/Inputs/switch.proftext -o %t.profdata
33 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
4 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
45 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
56 target triple = "x86_64-unknown-linux-gnu"
67