summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorXinliang David Li <davidxl@google.com>2016-05-10 21:59:52 +0000
committerXinliang David Li <davidxl@google.com>2016-05-10 21:59:52 +0000
commitda1955835d7e9ac5c85ab1cead49d866bcc5c2e2 (patch)
tree6f9fadad5db624c24d0b97dea83286cd00ae9d8e /llvm
parent2ef275d3423e84655608c91a193351c4c6b0593d (diff)
downloadbcm5719-llvm-da1955835d7e9ac5c85ab1cead49d866bcc5c2e2.tar.gz
bcm5719-llvm-da1955835d7e9ac5c85ab1cead49d866bcc5c2e2.zip
[PM]: port IR based profUse pass to new pass manager
llvm-svn: 269129
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Transforms/PGOInstrumentation.h12
-rw-r--r--llvm/lib/Passes/PassRegistry.def1
-rw-r--r--llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp42
-rw-r--r--llvm/test/Transforms/PGOProfile/branch1.ll5
-rw-r--r--llvm/test/Transforms/PGOProfile/branch2.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/criticaledge.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/diag_FE_profile.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/diag_mismatch.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/diag_no_funcprofdata.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/diag_no_profile.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/indirect_call_annotation.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/landingpad.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/loop1.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/loop2.ll1
-rw-r--r--llvm/test/Transforms/PGOProfile/switch.ll1
15 files changed, 59 insertions, 12 deletions
diff --git a/llvm/include/llvm/Transforms/PGOInstrumentation.h b/llvm/include/llvm/Transforms/PGOInstrumentation.h
index 42f1e175b5b..9ab82ea0cb6 100644
--- a/llvm/include/llvm/Transforms/PGOInstrumentation.h
+++ b/llvm/include/llvm/Transforms/PGOInstrumentation.h
@@ -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
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index d79a39cf952..a9c896029f6 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -48,6 +48,7 @@ MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
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()))
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index ef496840fab..e5e798b3fd0 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -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 &Func,
}
}
-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::annotateAllFunctions(
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::annotateAllFunctions(
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::runOnModule(Module &M) {
return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
};
- return annotateAllFunctions(M, LookupBPI, LookupBFI);
+ return annotateAllFunctions(M, ProfileFileName, LookupBPI, LookupBFI);
}
diff --git a/llvm/test/Transforms/PGOProfile/branch1.ll b/llvm/test/Transforms/PGOProfile/branch1.ll
index 7d78e8a60d4..317fae2d88d 100644
--- a/llvm/test/Transforms/PGOProfile/branch1.ll
+++ b/llvm/test/Transforms/PGOProfile/branch1.ll
@@ -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"
diff --git a/llvm/test/Transforms/PGOProfile/branch2.ll b/llvm/test/Transforms/PGOProfile/branch2.ll
index a31792a1f41..f8df54b94d4 100644
--- a/llvm/test/Transforms/PGOProfile/branch2.ll
+++ b/llvm/test/Transforms/PGOProfile/branch2.ll
@@ -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"
diff --git a/llvm/test/Transforms/PGOProfile/criticaledge.ll b/llvm/test/Transforms/PGOProfile/criticaledge.ll
index de6893b48d8..4b2ea6becfe 100644
--- a/llvm/test/Transforms/PGOProfile/criticaledge.ll
+++ b/llvm/test/Transforms/PGOProfile/criticaledge.ll
@@ -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"
diff --git a/llvm/test/Transforms/PGOProfile/diag_FE_profile.ll b/llvm/test/Transforms/PGOProfile/diag_FE_profile.ll
index 30abe6d3519..cd33954284f 100644
--- a/llvm/test/Transforms/PGOProfile/diag_FE_profile.ll
+++ b/llvm/test/Transforms/PGOProfile/diag_FE_profile.ll
@@ -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
diff --git a/llvm/test/Transforms/PGOProfile/diag_mismatch.ll b/llvm/test/Transforms/PGOProfile/diag_mismatch.ll
index a2d0b20620f..e2b7f8cdcc5 100644
--- a/llvm/test/Transforms/PGOProfile/diag_mismatch.ll
+++ b/llvm/test/Transforms/PGOProfile/diag_mismatch.ll
@@ -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
diff --git a/llvm/test/Transforms/PGOProfile/diag_no_funcprofdata.ll b/llvm/test/Transforms/PGOProfile/diag_no_funcprofdata.ll
index 2e5ec0444b4..d49751a62b9 100644
--- a/llvm/test/Transforms/PGOProfile/diag_no_funcprofdata.ll
+++ b/llvm/test/Transforms/PGOProfile/diag_no_funcprofdata.ll
@@ -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
diff --git a/llvm/test/Transforms/PGOProfile/diag_no_profile.ll b/llvm/test/Transforms/PGOProfile/diag_no_profile.ll
index ce7b59b8f69..222d9bd0986 100644
--- a/llvm/test/Transforms/PGOProfile/diag_no_profile.ll
+++ b/llvm/test/Transforms/PGOProfile/diag_no_profile.ll
@@ -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"
diff --git a/llvm/test/Transforms/PGOProfile/indirect_call_annotation.ll b/llvm/test/Transforms/PGOProfile/indirect_call_annotation.ll
index e2479d72bf6..6f72a998784 100644
--- a/llvm/test/Transforms/PGOProfile/indirect_call_annotation.ll
+++ b/llvm/test/Transforms/PGOProfile/indirect_call_annotation.ll
@@ -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"
diff --git a/llvm/test/Transforms/PGOProfile/landingpad.ll b/llvm/test/Transforms/PGOProfile/landingpad.ll
index bd6c063580a..9452cd41b00 100644
--- a/llvm/test/Transforms/PGOProfile/landingpad.ll
+++ b/llvm/test/Transforms/PGOProfile/landingpad.ll
@@ -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"
diff --git a/llvm/test/Transforms/PGOProfile/loop1.ll b/llvm/test/Transforms/PGOProfile/loop1.ll
index 4f2c17c713d..5d3be183694 100644
--- a/llvm/test/Transforms/PGOProfile/loop1.ll
+++ b/llvm/test/Transforms/PGOProfile/loop1.ll
@@ -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"
diff --git a/llvm/test/Transforms/PGOProfile/loop2.ll b/llvm/test/Transforms/PGOProfile/loop2.ll
index edf546f685e..1fad53a90dc 100644
--- a/llvm/test/Transforms/PGOProfile/loop2.ll
+++ b/llvm/test/Transforms/PGOProfile/loop2.ll
@@ -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"
diff --git a/llvm/test/Transforms/PGOProfile/switch.ll b/llvm/test/Transforms/PGOProfile/switch.ll
index 447d274fa80..e590e217013 100644
--- a/llvm/test/Transforms/PGOProfile/switch.ll
+++ b/llvm/test/Transforms/PGOProfile/switch.ll
@@ -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"
OpenPOWER on IntegriCloud