[llvm] r269129 - [PM]: port IR based profUse pass to new pass manager
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Tue May 10 14:59:53 PDT 2016
Author: davidxl
Date: Tue May 10 16:59:52 2016
New Revision: 269129
URL: http://llvm.org/viewvc/llvm-project?rev=269129&view=rev
Log:
[PM]: port IR based profUse pass to new pass manager
Modified:
llvm/trunk/include/llvm/Transforms/PGOInstrumentation.h
llvm/trunk/lib/Passes/PassRegistry.def
llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/trunk/test/Transforms/PGOProfile/branch1.ll
llvm/trunk/test/Transforms/PGOProfile/branch2.ll
llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll
llvm/trunk/test/Transforms/PGOProfile/diag_FE_profile.ll
llvm/trunk/test/Transforms/PGOProfile/diag_mismatch.ll
llvm/trunk/test/Transforms/PGOProfile/diag_no_funcprofdata.ll
llvm/trunk/test/Transforms/PGOProfile/diag_no_profile.ll
llvm/trunk/test/Transforms/PGOProfile/indirect_call_annotation.ll
llvm/trunk/test/Transforms/PGOProfile/landingpad.ll
llvm/trunk/test/Transforms/PGOProfile/loop1.ll
llvm/trunk/test/Transforms/PGOProfile/loop2.ll
llvm/trunk/test/Transforms/PGOProfile/switch.ll
Modified: llvm/trunk/include/llvm/Transforms/PGOInstrumentation.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/PGOInstrumentation.h?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/PGOInstrumentation.h (original)
+++ llvm/trunk/include/llvm/Transforms/PGOInstrumentation.h Tue May 10 16:59:52 2016
@@ -14,9 +14,7 @@
#ifndef LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
#define LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
-#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PassManager.h"
-#include "llvm/ProfileData/InstrProf.h"
#include "llvm/Transforms/Instrumentation.h"
namespace llvm {
@@ -27,5 +25,15 @@ public:
PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);
};
+/// The profile annotation (profile-instr-use) pass for IR based PGO.
+class PGOInstrumentationUse : public PassInfoMixin<PGOInstrumentationUse> {
+public:
+ PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);
+ PGOInstrumentationUse(std::string Filename = "");
+
+private:
+ std::string ProfileFileName;
+};
+
} // End llvm namespace
#endif
Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Tue May 10 16:59:52 2016
@@ -48,6 +48,7 @@ MODULE_PASS("invalidate<all>", Invalidat
MODULE_PASS("ipsccp", IPSCCPPass())
MODULE_PASS("no-op-module", NoOpModulePass())
MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
+MODULE_PASS("pgo-instr-use", PGOInstrumentationUse())
MODULE_PASS("print", PrintModulePass(dbgs()))
MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))
MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
Modified: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Tue May 10 16:59:52 2016
@@ -151,13 +151,9 @@ public:
}
private:
- bool annotateAllFunctions(
- Module &M, function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
- function_ref<BlockFrequencyInfo *(Function &)> LookupBFI);
std::string ProfileFileName;
- std::unique_ptr<IndexedInstrProfReader> PGOReader;
- bool runOnModule(Module &M) override;
+ bool runOnModule(Module &M) override;
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<BlockFrequencyInfoWrapperPass>();
}
@@ -835,8 +831,9 @@ static void setPGOCountOnFunc(PGOUseFunc
}
}
-bool PGOInstrumentationUseLegacyPass::annotateAllFunctions(
- Module &M, function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
+static bool annotateAllFunctions(
+ Module &M, StringRef ProfileFileName,
+ function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
function_ref<BlockFrequencyInfo *(Function &)> LookupBFI) {
DEBUG(dbgs() << "Read in profile counters: ");
auto &Ctx = M.getContext();
@@ -848,10 +845,11 @@ bool PGOInstrumentationUseLegacyPass::an
return false;
}
- PGOReader = std::move(ReaderOrErr.get());
+ std::unique_ptr<IndexedInstrProfReader> PGOReader =
+ std::move(ReaderOrErr.get());
if (!PGOReader) {
Ctx.diagnose(DiagnosticInfoPGOProfile(ProfileFileName.data(),
- "Cannot get PGOReader"));
+ StringRef("Cannot get PGOReader")));
return false;
}
// TODO: might need to change the warning once the clang option is finalized.
@@ -891,6 +889,30 @@ bool PGOInstrumentationUseLegacyPass::an
return true;
}
+PGOInstrumentationUse::PGOInstrumentationUse(std::string Filename)
+ : ProfileFileName(Filename) {
+ if (!PGOTestProfileFile.empty())
+ ProfileFileName = PGOTestProfileFile;
+}
+
+PreservedAnalyses PGOInstrumentationUse::run(Module &M,
+ AnalysisManager<Module> &AM) {
+
+ auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+ auto LookupBPI = [&FAM](Function &F) {
+ return &FAM.getResult<BranchProbabilityAnalysis>(F);
+ };
+
+ auto LookupBFI = [&FAM](Function &F) {
+ return &FAM.getResult<BlockFrequencyAnalysis>(F);
+ };
+
+ if (!annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI))
+ return PreservedAnalyses::all();
+
+ return PreservedAnalyses::none();
+}
+
bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) {
if (skipModule(M))
return false;
@@ -902,5 +924,5 @@ bool PGOInstrumentationUseLegacyPass::ru
return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
};
- return annotateAllFunctions(M, LookupBPI, LookupBFI);
+ return annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI);
}
Modified: llvm/trunk/test/Transforms/PGOProfile/branch1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/branch1.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/branch1.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/branch1.ll Tue May 10 16:59:52 2016
@@ -1,11 +1,16 @@
; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-COMDAT
; RUN: opt < %s -mtriple=x86_64-apple-darwin -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-DARWIN-LINKONCE
+; New PM
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-COMDAT
; RUN: opt < %s -mtriple=x86_64-apple-darwin -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN --check-prefix=GEN-DARWIN-LINKONCE
; RUN: llvm-profdata merge %S/Inputs/branch1.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
+
+; New PM
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; GEN-DARWIN-LINKONCE: target triple = "x86_64-apple-darwin"
Modified: llvm/trunk/test/Transforms/PGOProfile/branch2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/branch2.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/branch2.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/branch2.ll Tue May 10 16:59:52 2016
@@ -2,6 +2,7 @@
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
; RUN: llvm-profdata merge %S/Inputs/branch2.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Modified: llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll Tue May 10 16:59:52 2016
@@ -2,6 +2,7 @@
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
; RUN: llvm-profdata merge %S/Inputs/criticaledge.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Modified: llvm/trunk/test/Transforms/PGOProfile/diag_FE_profile.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/diag_FE_profile.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/diag_FE_profile.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/diag_FE_profile.ll Tue May 10 16:59:52 2016
@@ -1,5 +1,6 @@
; RUN: llvm-profdata merge %S/Inputs/diag_FE.proftext -o %t.profdata
; RUN: not opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
+; RUN: not opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
; CHECK: Not an IR level instrumentation profile
Modified: llvm/trunk/test/Transforms/PGOProfile/diag_mismatch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/diag_mismatch.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/diag_mismatch.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/diag_mismatch.ll Tue May 10 16:59:52 2016
@@ -1,5 +1,6 @@
; RUN: llvm-profdata merge %S/Inputs/diag.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
; CHECK: Function control flow change detected (hash mismatch) foo
Modified: llvm/trunk/test/Transforms/PGOProfile/diag_no_funcprofdata.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/diag_no_funcprofdata.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/diag_no_funcprofdata.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/diag_no_funcprofdata.ll Tue May 10 16:59:52 2016
@@ -1,5 +1,6 @@
; RUN: llvm-profdata merge %S/Inputs/diag.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1 | FileCheck %s
; CHECK: No profile data available for function bar
Modified: llvm/trunk/test/Transforms/PGOProfile/diag_no_profile.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/diag_no_profile.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/diag_no_profile.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/diag_no_profile.ll Tue May 10 16:59:52 2016
@@ -1,4 +1,5 @@
; RUN: not opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1
+; RUN: not opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S 2>&1
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Modified: llvm/trunk/test/Transforms/PGOProfile/indirect_call_annotation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/indirect_call_annotation.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/indirect_call_annotation.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/indirect_call_annotation.ll Tue May 10 16:59:52 2016
@@ -1,5 +1,6 @@
; RUN: llvm-profdata merge %S/Inputs/indirect_call.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=VP-ANNOTATION
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=VP-ANNOTATION
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Modified: llvm/trunk/test/Transforms/PGOProfile/landingpad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/landingpad.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/landingpad.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/landingpad.ll Tue May 10 16:59:52 2016
@@ -2,6 +2,7 @@
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
; RUN: llvm-profdata merge %S/Inputs/landingpad.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Modified: llvm/trunk/test/Transforms/PGOProfile/loop1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/loop1.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/loop1.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/loop1.ll Tue May 10 16:59:52 2016
@@ -2,6 +2,7 @@
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
; RUN: llvm-profdata merge %S/Inputs/loop1.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Modified: llvm/trunk/test/Transforms/PGOProfile/loop2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/loop2.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/loop2.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/loop2.ll Tue May 10 16:59:52 2016
@@ -2,6 +2,7 @@
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
; RUN: llvm-profdata merge %S/Inputs/loop2.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
Modified: llvm/trunk/test/Transforms/PGOProfile/switch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/switch.ll?rev=269129&r1=269128&r2=269129&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/switch.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/switch.ll Tue May 10 16:59:52 2016
@@ -2,6 +2,7 @@
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
; RUN: llvm-profdata merge %S/Inputs/switch.proftext -o %t.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
+; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list