forked from OSchip/llvm-project
[PM] port IR based PGO prof-gen pass to new pass manager
llvm-svn: 268710
This commit is contained in:
parent
7946c3f0e2
commit
8aebf44c97
|
@ -123,7 +123,7 @@ void initializeEdgeBundlesPass(PassRegistry&);
|
|||
void initializeExpandPostRAPass(PassRegistry&);
|
||||
void initializeAAResultsWrapperPassPass(PassRegistry &);
|
||||
void initializeGCOVProfilerPass(PassRegistry&);
|
||||
void initializePGOInstrumentationGenPass(PassRegistry&);
|
||||
void initializePGOInstrumentationGenLegacyPassPass(PassRegistry&);
|
||||
void initializePGOInstrumentationUsePass(PassRegistry&);
|
||||
void initializePGOIndirectCallPromotionPass(PassRegistry&);
|
||||
void initializeInstrProfilingLegacyPassPass(PassRegistry &);
|
||||
|
|
|
@ -89,7 +89,7 @@ namespace {
|
|||
(void) llvm::createDomOnlyViewerPass();
|
||||
(void) llvm::createDomViewerPass();
|
||||
(void) llvm::createGCOVProfilerPass();
|
||||
(void) llvm::createPGOInstrumentationGenPass();
|
||||
(void) llvm::createPGOInstrumentationGenLegacyPass();
|
||||
(void) llvm::createPGOInstrumentationUsePass();
|
||||
(void) llvm::createPGOIndirectCallPromotionPass();
|
||||
(void) llvm::createInstrProfilingLegacyPass();
|
||||
|
|
|
@ -80,7 +80,7 @@ ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
|
|||
GCOVOptions::getDefault());
|
||||
|
||||
// PGO Instrumention
|
||||
ModulePass *createPGOInstrumentationGenPass();
|
||||
ModulePass *createPGOInstrumentationGenLegacyPass();
|
||||
ModulePass *
|
||||
createPGOInstrumentationUsePass(StringRef Filename = StringRef(""));
|
||||
ModulePass *createPGOIndirectCallPromotionPass(bool InLTO = false);
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
//===- Transforms/PGOInstrumentation.h - PGO gen/use passes ---*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// \file
|
||||
/// This file provides the interface for IR based instrumentation passes (
|
||||
/// (profile-gen, and profile-use).
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#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 {
|
||||
|
||||
/// The instrumentation (profile-instr-gen) pass for IR based PGO.
|
||||
class PGOInstrumentationGen : public PassInfoMixin<PGOInstrumentationGen> {
|
||||
public:
|
||||
PGOInstrumentationGen() {}
|
||||
|
||||
PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
#endif
|
|
@ -60,6 +60,7 @@
|
|||
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
|
||||
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
||||
#include "llvm/Transforms/InstrProfiling.h"
|
||||
#include "llvm/Transforms/PGOInstrumentation.h"
|
||||
#include "llvm/Transforms/Scalar/ADCE.h"
|
||||
#include "llvm/Transforms/Scalar/DCE.h"
|
||||
#include "llvm/Transforms/Scalar/EarlyCSE.h"
|
||||
|
|
|
@ -46,6 +46,7 @@ MODULE_PASS("instrprof", InstrProfiling())
|
|||
MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
||||
MODULE_PASS("ipsccp", IPSCCPPass())
|
||||
MODULE_PASS("no-op-module", NoOpModulePass())
|
||||
MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
|
||||
MODULE_PASS("print", PrintModulePass(dbgs()))
|
||||
MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))
|
||||
MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
|
||||
|
|
|
@ -212,7 +212,7 @@ void PassManagerBuilder::populateFunctionPassManager(
|
|||
// Do PGO instrumentation generation or use pass as the option specified.
|
||||
void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) {
|
||||
if (!PGOInstrGen.empty()) {
|
||||
MPM.add(createPGOInstrumentationGenPass());
|
||||
MPM.add(createPGOInstrumentationGenLegacyPass());
|
||||
// Add the profile lowering pass.
|
||||
InstrProfOptions Options;
|
||||
Options.InstrProfileOutput = PGOInstrGen;
|
||||
|
|
|
@ -60,7 +60,7 @@ void llvm::initializeInstrumentation(PassRegistry &Registry) {
|
|||
initializeAddressSanitizerModulePass(Registry);
|
||||
initializeBoundsCheckingPass(Registry);
|
||||
initializeGCOVProfilerPass(Registry);
|
||||
initializePGOInstrumentationGenPass(Registry);
|
||||
initializePGOInstrumentationGenLegacyPassPass(Registry);
|
||||
initializePGOInstrumentationUsePass(Registry);
|
||||
initializePGOIndirectCallPromotionPass(Registry);
|
||||
initializeInstrProfilingLegacyPassPass(Registry);
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/PGOInstrumentation.h"
|
||||
#include "CFGMST.h"
|
||||
#include "IndirectCallSiteVisitor.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
|
@ -71,6 +72,7 @@
|
|||
#include "llvm/Support/JamCRC.h"
|
||||
#include "llvm/Transforms/Instrumentation.h"
|
||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
@ -110,12 +112,13 @@ static cl::opt<unsigned> MaxNumAnnotations(
|
|||
"call callsite"));
|
||||
|
||||
namespace {
|
||||
class PGOInstrumentationGen : public ModulePass {
|
||||
class PGOInstrumentationGenLegacyPass : public ModulePass {
|
||||
public:
|
||||
static char ID;
|
||||
|
||||
PGOInstrumentationGen() : ModulePass(ID) {
|
||||
initializePGOInstrumentationGenPass(*PassRegistry::getPassRegistry());
|
||||
PGOInstrumentationGenLegacyPass() : ModulePass(ID), PGOInstrGen() {
|
||||
initializePGOInstrumentationGenLegacyPassPass(
|
||||
*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
const char *getPassName() const override {
|
||||
|
@ -123,6 +126,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
PGOInstrumentationGen PGOInstrGen;
|
||||
bool runOnModule(Module &M) override;
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
|
@ -157,16 +161,16 @@ private:
|
|||
};
|
||||
} // end anonymous namespace
|
||||
|
||||
char PGOInstrumentationGen::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(PGOInstrumentationGen, "pgo-instr-gen",
|
||||
char PGOInstrumentationGenLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(PGOInstrumentationGenLegacyPass, "pgo-instr-gen",
|
||||
"PGO instrumentation.", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(BlockFrequencyInfoWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)
|
||||
INITIALIZE_PASS_END(PGOInstrumentationGen, "pgo-instr-gen",
|
||||
INITIALIZE_PASS_END(PGOInstrumentationGenLegacyPass, "pgo-instr-gen",
|
||||
"PGO instrumentation.", false, false)
|
||||
|
||||
ModulePass *llvm::createPGOInstrumentationGenPass() {
|
||||
return new PGOInstrumentationGen();
|
||||
ModulePass *llvm::createPGOInstrumentationGenLegacyPass() {
|
||||
return new PGOInstrumentationGenLegacyPass();
|
||||
}
|
||||
|
||||
char PGOInstrumentationUse::ID = 0;
|
||||
|
@ -788,7 +792,7 @@ static bool InstrumentAllFunctions(
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PGOInstrumentationGen::runOnModule(Module &M) {
|
||||
bool PGOInstrumentationGenLegacyPass::runOnModule(Module &M) {
|
||||
if (skipModule(M))
|
||||
return false;
|
||||
|
||||
|
@ -801,6 +805,24 @@ bool PGOInstrumentationGen::runOnModule(Module &M) {
|
|||
return InstrumentAllFunctions(M, LookupBPI, LookupBFI);
|
||||
}
|
||||
|
||||
PreservedAnalyses PGOInstrumentationGen::run(Module &M,
|
||||
AnalysisManager<Module> &AM) {
|
||||
|
||||
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
|
||||
auto LookupBPI = [&FAM](Function &F) -> BranchProbabilityInfo & {
|
||||
return FAM.getResult<BranchProbabilityAnalysis>(F);
|
||||
};
|
||||
|
||||
auto LookupBFI = [&FAM](Function &F) -> BlockFrequencyInfo & {
|
||||
return FAM.getResult<BlockFrequencyAnalysis>(F);
|
||||
};
|
||||
|
||||
if (!InstrumentAllFunctions(M, LookupBPI, LookupBFI))
|
||||
return PreservedAnalyses::all();
|
||||
|
||||
return PreservedAnalyses::none();
|
||||
}
|
||||
|
||||
static void setPGOCountOnFunc(PGOUseFunc &Func,
|
||||
IndexedInstrProfReader *PGOReader) {
|
||||
if (Func.readCounters(PGOReader)) {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
; 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 -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
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -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: opt < %s -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"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -pgo-instr-gen -instrprof -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=pgo-instr-gen,instrprof -S | FileCheck %s
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -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: opt < %s -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"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-apple-macosx10.12.0"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -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: opt < %s -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"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -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: opt < %s -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"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -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: opt < %s -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"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||
; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -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: opt < %s -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"
|
||||
|
|
Loading…
Reference in New Issue