forked from OSchip/llvm-project
[PM] Port the Sample FDO to new PM (part-2)
llvm-svn: 271072
This commit is contained in:
parent
ea2aef4a1d
commit
d38392ecd6
|
@ -0,0 +1,27 @@
|
|||
//===- Transforms/SampleProfile.h - SamplePGO pass--------------*- 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 the sampled PGO loader pass.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_SAMPLEPROFILE_H
|
||||
#define LLVM_TRANSFORMS_SAMPLEPROFILE_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
/// The instrumentation (profile-instr-gen) pass for IR based PGO.
|
||||
class SampleProfileLoaderPass : public PassInfoMixin<SampleProfileLoaderPass> {
|
||||
public:
|
||||
PreservedAnalyses run(Module &M, AnalysisManager<Module> &AM);
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
#endif
|
|
@ -62,6 +62,7 @@
|
|||
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
||||
#include "llvm/Transforms/InstrProfiling.h"
|
||||
#include "llvm/Transforms/PGOInstrumentation.h"
|
||||
#include "llvm/Transforms/SampleProfile.h"
|
||||
#include "llvm/Transforms/Scalar/ADCE.h"
|
||||
#include "llvm/Transforms/Scalar/BDCE.h"
|
||||
#include "llvm/Transforms/Scalar/DCE.h"
|
||||
|
|
|
@ -53,6 +53,7 @@ MODULE_PASS("pgo-instr-use", PGOInstrumentationUse())
|
|||
MODULE_PASS("print", PrintModulePass(dbgs()))
|
||||
MODULE_PASS("print-callgraph", CallGraphPrinterPass(dbgs()))
|
||||
MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
|
||||
MODULE_PASS("sample-profile", SampleProfileLoaderPass())
|
||||
MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass())
|
||||
MODULE_PASS("verify", VerifierPass())
|
||||
#undef MODULE_PASS
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/SampleProfile.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
|
@ -34,8 +35,8 @@
|
|||
#include "llvm/IR/Dominators.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/InstIterator.h"
|
||||
#include "llvm/IR/IntrinsicInst.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
#include "llvm/IR/IntrinsicInst.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/MDBuilder.h"
|
||||
#include "llvm/IR/Metadata.h"
|
||||
|
@ -1225,10 +1226,8 @@ bool SampleProfileLoader::emitAnnotations(Function &F) {
|
|||
}
|
||||
|
||||
char SampleProfileLoaderLegacyPass::ID = 0;
|
||||
INITIALIZE_PASS_BEGIN(SampleProfileLoaderLegacyPass, "sample-profile",
|
||||
"Sample Profile loader", false, false)
|
||||
INITIALIZE_PASS_END(SampleProfileLoaderLegacyPass, "sample-profile",
|
||||
"Sample Profile loader", false, false)
|
||||
INITIALIZE_PASS(SampleProfileLoaderLegacyPass, "sample-profile",
|
||||
"Sample Profile loader", false, false)
|
||||
|
||||
bool SampleProfileLoader::doInitialization(Module &M) {
|
||||
auto &Ctx = M.getContext();
|
||||
|
@ -1279,3 +1278,16 @@ bool SampleProfileLoader::runOnFunction(Function &F) {
|
|||
return emitAnnotations(F);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreservedAnalyses SampleProfileLoaderPass::run(Module &M,
|
||||
AnalysisManager<Module> &AM) {
|
||||
|
||||
SampleProfileLoader SampleLoader(SampleProfileFile);
|
||||
|
||||
SampleLoader.doInitialization(M);
|
||||
|
||||
if (!SampleLoader.runOnModule(M))
|
||||
return PreservedAnalyses::all();
|
||||
|
||||
return PreservedAnalyses::none();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/branch.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/branch.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
|
||||
; Original C++ code for this test case:
|
||||
;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -instcombine -sample-profile -sample-profile-file=%S/Inputs/calls.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
; RUN: opt < %s -passes="function(instcombine),sample-profile" -sample-profile-file=%S/Inputs/calls.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
|
||||
; Original C++ test case
|
||||
;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -instcombine -sample-profile -sample-profile-file=%S/Inputs/cov-zero-samples.prof -sample-profile-check-record-coverage=100 -pass-remarks=sample-profile -o /dev/null 2>&1 | FileCheck %s
|
||||
; RUN: opt < %s -passes="function(instcombine),sample-profile" -sample-profile-file=%S/Inputs/cov-zero-samples.prof -sample-profile-check-record-coverage=100 -pass-remarks=sample-profile -o /dev/null 2>&1 | FileCheck %s
|
||||
;
|
||||
; CHECK: remark: cov-zero-samples.cc:9:29: Applied 404065 samples from profile (offset: 2.1)
|
||||
; CHECK: remark: cov-zero-samples.cc:10:9: Applied 443089 samples from profile (offset: 3)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/coverage-warning.prof -sample-profile-check-record-coverage=90 -sample-profile-check-sample-coverage=100 -o /dev/null 2>&1 | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/coverage-warning.prof -sample-profile-check-record-coverage=90 -sample-profile-check-sample-coverage=100 -o /dev/null 2>&1 | FileCheck %s
|
||||
define i32 @foo(i32 %i) !dbg !4 {
|
||||
; The profile has samples for line locations that are no longer present.
|
||||
; Coverage does not reach 90%, so we should get this warning:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/discriminator.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/discriminator.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
|
||||
; Original code
|
||||
;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/entry_counts.prof -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/entry_counts.prof -S | FileCheck %s
|
||||
|
||||
; According to the profile, function empty() was called 13,293 times.
|
||||
; CHECK: {{.*}} = !{!"function_entry_count", i64 13293}
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.binprof | opt -analyze -branch-prob | FileCheck %s
|
||||
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/fnptr.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/fnptr.binprof | opt -analyze -branch-prob | FileCheck %s
|
||||
|
||||
; CHECK: edge for.body3 -> if.then probability is 0x1a4f3959 / 0x80000000 = 20.55%
|
||||
; CHECK: edge for.body3 -> if.else probability is 0x65b0c6a7 / 0x80000000 = 79.45%
|
||||
; CHECK: edge for.inc -> for.inc12 probability is 0x33d4a4c1 / 0x80000000 = 40.49%
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/gcc-simple.afdo -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/gcc-simple.afdo -S | FileCheck %s
|
||||
; XFAIL: powerpc64-, s390x, mips-, mips64-, sparc
|
||||
; Original code:
|
||||
;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -instcombine -sample-profile -sample-profile-file=%S/Inputs/inline-combine.prof -S | FileCheck %s
|
||||
; RUN: opt < %s -passes="function(instcombine),sample-profile" -sample-profile-file=%S/Inputs/inline-combine.prof -S | FileCheck %s
|
||||
|
||||
%"class.llvm::FoldingSetNodeID" = type { %"class.llvm::SmallVector" }
|
||||
%"class.llvm::SmallVector" = type { %"class.llvm::SmallVectorImpl.base", %"struct.llvm::SmallVectorStorage" }
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -instcombine -sample-profile -sample-profile-file=%S/Inputs/inline-coverage.prof -sample-profile-check-record-coverage=100 -sample-profile-check-sample-coverage=110 -pass-remarks=sample-profile -o /dev/null 2>&1 | FileCheck %s
|
||||
; RUN: opt < %s -passes="function(instcombine),sample-profile" -sample-profile-file=%S/Inputs/inline-coverage.prof -sample-profile-check-record-coverage=100 -sample-profile-check-sample-coverage=110 -pass-remarks=sample-profile -o /dev/null 2>&1 | FileCheck %s
|
||||
;
|
||||
; Original code:
|
||||
;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt %s -sample-profile -sample-profile-file=%S/Inputs/inline-hint.prof -pass-remarks=sample-profile -o /dev/null 2>&1 | FileCheck %s
|
||||
; RUN: opt %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline-hint.prof -pass-remarks=sample-profile -o /dev/null 2>&1 | FileCheck %s
|
||||
;
|
||||
; CHECK: Applied cold hint to globally cold function '_Z7cold_fnRxi' with 0.1
|
||||
define void @_Z7cold_fnRxi() !dbg !4 {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/inline.prof -sample-profile-inline-hot-threshold=1 -S | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/inline.prof -sample-profile-inline-hot-threshold=1 -S | FileCheck %s
|
||||
|
||||
; Original C++ test case
|
||||
;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/nolocinfo.prof -S -pass-remarks=sample-profile 2>&1 | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/nolocinfo.prof -S -pass-remarks=sample-profile 2>&1 | FileCheck %s
|
||||
|
||||
define i32 @foo(i32 %i) !dbg !4 {
|
||||
entry:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/offset.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/offset.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
|
||||
; Original C++ code for this test case:
|
||||
;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/propagate.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/propagate.prof | opt -analyze -branch-prob | FileCheck %s
|
||||
|
||||
; Original C++ code for this test case:
|
||||
;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile 2>&1 | FileCheck %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile 2>&1 | FileCheck %s
|
||||
;
|
||||
; Original test case.
|
||||
;
|
||||
|
|
|
@ -7,6 +7,15 @@
|
|||
; RUN: not opt < %s -sample-profile -sample-profile-file=%S/Inputs/bad_samples.prof 2>&1 | FileCheck -check-prefix=BAD-SAMPLES %s
|
||||
; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/bad_mangle.prof 2>&1 >/dev/null
|
||||
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/syntax.prof 2>&1 | FileCheck -check-prefix=NO-DEBUG %s
|
||||
; RUN: not opt < %s -passes=sample-profile -sample-profile-file=missing.prof 2>&1 | FileCheck -check-prefix=MISSING-FILE %s
|
||||
; RUN: not opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/bad_fn_header.prof 2>&1 | FileCheck -check-prefix=BAD-FN-HEADER %s
|
||||
; RUN: not opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/bad_sample_line.prof 2>&1 | FileCheck -check-prefix=BAD-SAMPLE-LINE %s
|
||||
; RUN: not opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/bad_line_values.prof 2>&1 | FileCheck -check-prefix=BAD-LINE-VALUES %s
|
||||
; RUN: not opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/bad_discriminator_value.prof 2>&1 | FileCheck -check-prefix=BAD-DISCRIMINATOR-VALUE %s
|
||||
; RUN: not opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/bad_samples.prof 2>&1 | FileCheck -check-prefix=BAD-SAMPLES %s
|
||||
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/bad_mangle.prof 2>&1 >/dev/null
|
||||
|
||||
define void @empty() {
|
||||
entry:
|
||||
ret void
|
||||
|
|
Loading…
Reference in New Issue