mirror of
https://github.com/RPCSX/llvm.git
synced 2025-01-23 12:45:47 +00:00
[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
This commit is contained in:
parent
8fd08e9630
commit
e052ee9da4
@ -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
|
||||
|
@ -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()))
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user