mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-11 20:22:02 +00:00
[PM]: port IR based profUse pass to new pass manager
llvm-svn: 269129
This commit is contained in:
parent
1f4208a29c
commit
cde638dcef
@ -14,9 +14,7 @@
|
|||||||
#ifndef LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
|
#ifndef LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
|
||||||
#define LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
|
#define LLVM_TRANSFORMS_PGOINSTRUMENTATION_H
|
||||||
|
|
||||||
#include "llvm/IR/IntrinsicInst.h"
|
|
||||||
#include "llvm/IR/PassManager.h"
|
#include "llvm/IR/PassManager.h"
|
||||||
#include "llvm/ProfileData/InstrProf.h"
|
|
||||||
#include "llvm/Transforms/Instrumentation.h"
|
#include "llvm/Transforms/Instrumentation.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@ -27,5 +25,15 @@ public:
|
|||||||
PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);
|
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
|
} // End llvm namespace
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,6 +48,7 @@ MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
|||||||
MODULE_PASS("ipsccp", IPSCCPPass())
|
MODULE_PASS("ipsccp", IPSCCPPass())
|
||||||
MODULE_PASS("no-op-module", NoOpModulePass())
|
MODULE_PASS("no-op-module", NoOpModulePass())
|
||||||
MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
|
MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
|
||||||
|
MODULE_PASS("pgo-instr-use", PGOInstrumentationUse())
|
||||||
MODULE_PASS("print", PrintModulePass(dbgs()))
|
MODULE_PASS("print", PrintModulePass(dbgs()))
|
||||||
MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))
|
MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))
|
||||||
MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
|
MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
|
||||||
|
@ -151,13 +151,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool annotateAllFunctions(
|
|
||||||
Module &M, function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
|
|
||||||
function_ref<BlockFrequencyInfo *(Function &)> LookupBFI);
|
|
||||||
std::string ProfileFileName;
|
std::string ProfileFileName;
|
||||||
std::unique_ptr<IndexedInstrProfReader> PGOReader;
|
|
||||||
bool runOnModule(Module &M) override;
|
|
||||||
|
|
||||||
|
bool runOnModule(Module &M) override;
|
||||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||||
AU.addRequired<BlockFrequencyInfoWrapperPass>();
|
AU.addRequired<BlockFrequencyInfoWrapperPass>();
|
||||||
}
|
}
|
||||||
@ -835,8 +831,9 @@ static void setPGOCountOnFunc(PGOUseFunc &Func,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PGOInstrumentationUseLegacyPass::annotateAllFunctions(
|
static bool annotateAllFunctions(
|
||||||
Module &M, function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
|
Module &M, StringRef ProfileFileName,
|
||||||
|
function_ref<BranchProbabilityInfo *(Function &)> LookupBPI,
|
||||||
function_ref<BlockFrequencyInfo *(Function &)> LookupBFI) {
|
function_ref<BlockFrequencyInfo *(Function &)> LookupBFI) {
|
||||||
DEBUG(dbgs() << "Read in profile counters: ");
|
DEBUG(dbgs() << "Read in profile counters: ");
|
||||||
auto &Ctx = M.getContext();
|
auto &Ctx = M.getContext();
|
||||||
@ -848,10 +845,11 @@ bool PGOInstrumentationUseLegacyPass::annotateAllFunctions(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PGOReader = std::move(ReaderOrErr.get());
|
std::unique_ptr<IndexedInstrProfReader> PGOReader =
|
||||||
|
std::move(ReaderOrErr.get());
|
||||||
if (!PGOReader) {
|
if (!PGOReader) {
|
||||||
Ctx.diagnose(DiagnosticInfoPGOProfile(ProfileFileName.data(),
|
Ctx.diagnose(DiagnosticInfoPGOProfile(ProfileFileName.data(),
|
||||||
"Cannot get PGOReader"));
|
StringRef("Cannot get PGOReader")));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO: might need to change the warning once the clang option is finalized.
|
// TODO: might need to change the warning once the clang option is finalized.
|
||||||
@ -891,6 +889,30 @@ bool PGOInstrumentationUseLegacyPass::annotateAllFunctions(
|
|||||||
return true;
|
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) {
|
bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) {
|
||||||
if (skipModule(M))
|
if (skipModule(M))
|
||||||
return false;
|
return false;
|
||||||
@ -902,5 +924,5 @@ bool PGOInstrumentationUseLegacyPass::runOnModule(Module &M) {
|
|||||||
return &this->getAnalysis<BlockFrequencyInfoWrapperPass>(F).getBFI();
|
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 -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
|
; 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 -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: 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: 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
|
; 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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
; GEN-DARWIN-LINKONCE: target triple = "x86_64-apple-darwin"
|
; 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: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||||
; RUN: llvm-profdata merge %S/Inputs/branch2.proftext -o %t.profdata
|
; 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 -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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
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: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||||
; RUN: llvm-profdata merge %S/Inputs/criticaledge.proftext -o %t.profdata
|
; 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 -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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
; RUN: llvm-profdata merge %S/Inputs/diag_FE.proftext -o %t.profdata
|
; 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 -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
|
; CHECK: Not an IR level instrumentation profile
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
; RUN: llvm-profdata merge %S/Inputs/diag.proftext -o %t.profdata
|
; 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 -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
|
; 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: 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 -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
|
; 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 -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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
; RUN: llvm-profdata merge %S/Inputs/indirect_call.proftext -o %t.profdata
|
; 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 -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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
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: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||||
; RUN: llvm-profdata merge %S/Inputs/landingpad.proftext -o %t.profdata
|
; 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 -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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
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: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||||
; RUN: llvm-profdata merge %S/Inputs/loop1.proftext -o %t.profdata
|
; 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 -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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
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: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||||
; RUN: llvm-profdata merge %S/Inputs/loop2.proftext -o %t.profdata
|
; 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 -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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
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: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||||
; RUN: llvm-profdata merge %S/Inputs/switch.proftext -o %t.profdata
|
; 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 -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 datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
target triple = "x86_64-unknown-linux-gnu"
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user