[PM] port Branch Frequency Analaysis pass to new PM
llvm-svn: 268687
This commit is contained in:
parent
5f57b6ee0f
commit
28a932742c
|
@ -15,6 +15,7 @@
|
|||
#define LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H
|
||||
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Support/BlockFrequency.h"
|
||||
#include <climits>
|
||||
|
@ -31,10 +32,16 @@ class BlockFrequencyInfo {
|
|||
typedef BlockFrequencyInfoImpl<BasicBlock> ImplType;
|
||||
std::unique_ptr<ImplType> BFI;
|
||||
|
||||
void operator=(const BlockFrequencyInfo &) = delete;
|
||||
BlockFrequencyInfo(const BlockFrequencyInfo &) = delete;
|
||||
|
||||
public:
|
||||
BlockFrequencyInfo();
|
||||
BlockFrequencyInfo(const Function &F, const BranchProbabilityInfo &BPI,
|
||||
const LoopInfo &LI);
|
||||
BlockFrequencyInfo(BlockFrequencyInfo &&Arg);
|
||||
|
||||
BlockFrequencyInfo &operator=(BlockFrequencyInfo &&RHS);
|
||||
|
||||
const Function *getFunction() const;
|
||||
void view() const;
|
||||
|
@ -71,6 +78,30 @@ public:
|
|||
void print(raw_ostream &OS) const;
|
||||
};
|
||||
|
||||
/// \brief Analysis pass which computes \c BlockFrequencyInfo.
|
||||
class BlockFrequencyAnalysis
|
||||
: public AnalysisInfoMixin<BlockFrequencyAnalysis> {
|
||||
friend AnalysisInfoMixin<BlockFrequencyAnalysis>;
|
||||
static char PassID;
|
||||
|
||||
public:
|
||||
/// \brief Provide the result typedef for this analysis pass.
|
||||
typedef BlockFrequencyInfo Result;
|
||||
|
||||
/// \brief Run the analysis pass over a function and produce BPI.
|
||||
BlockFrequencyInfo run(Function &F, AnalysisManager<Function> &AM);
|
||||
};
|
||||
|
||||
/// \brief Printer pass for the \c BlockFrequencyInfo results.
|
||||
class BlockFrequencyPrinterPass
|
||||
: public PassInfoMixin<BlockFrequencyPrinterPass> {
|
||||
raw_ostream &OS;
|
||||
|
||||
public:
|
||||
explicit BlockFrequencyPrinterPass(raw_ostream &OS) : OS(OS) {}
|
||||
PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM);
|
||||
};
|
||||
|
||||
/// \brief Legacy analysis pass which computes \c BlockFrequencyInfo.
|
||||
class BlockFrequencyInfoWrapperPass : public FunctionPass {
|
||||
BlockFrequencyInfo BFI;
|
||||
|
|
|
@ -113,6 +113,15 @@ BlockFrequencyInfo::BlockFrequencyInfo(const Function &F,
|
|||
calculate(F, BPI, LI);
|
||||
}
|
||||
|
||||
BlockFrequencyInfo::BlockFrequencyInfo(BlockFrequencyInfo &&Arg)
|
||||
: BFI(std::move(Arg.BFI)) {}
|
||||
|
||||
BlockFrequencyInfo &BlockFrequencyInfo::operator=(BlockFrequencyInfo &&RHS) {
|
||||
releaseMemory();
|
||||
BFI = std::move(RHS.BFI);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void BlockFrequencyInfo::calculate(const Function &F,
|
||||
const BranchProbabilityInfo &BPI,
|
||||
const LoopInfo &LI) {
|
||||
|
@ -225,3 +234,21 @@ bool BlockFrequencyInfoWrapperPass::runOnFunction(Function &F) {
|
|||
BFI.calculate(F, BPI, LI);
|
||||
return false;
|
||||
}
|
||||
|
||||
char BlockFrequencyAnalysis::PassID;
|
||||
BlockFrequencyInfo BlockFrequencyAnalysis::run(Function &F,
|
||||
AnalysisManager<Function> &AM) {
|
||||
BlockFrequencyInfo BFI;
|
||||
BFI.calculate(F, AM.getResult<BranchProbabilityAnalysis>(F),
|
||||
AM.getResult<LoopAnalysis>(F));
|
||||
return BFI;
|
||||
}
|
||||
|
||||
PreservedAnalyses
|
||||
BlockFrequencyPrinterPass::run(Function &F, AnalysisManager<Function> &AM) {
|
||||
OS << "Printing analysis results of BFI for function "
|
||||
<< "'" << F.getName() << "':"
|
||||
<< "\n";
|
||||
AM.getResult<BlockFrequencyAnalysis>(F).print(OS);
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include "llvm/Analysis/AliasAnalysisEvaluator.h"
|
||||
#include "llvm/Analysis/AssumptionCache.h"
|
||||
#include "llvm/Analysis/BasicAliasAnalysis.h"
|
||||
#include "llvm/Analysis/BlockFrequencyInfo.h"
|
||||
#include "llvm/Analysis/BlockFrequencyInfoImpl.h"
|
||||
#include "llvm/Analysis/BranchProbabilityInfo.h"
|
||||
#include "llvm/Analysis/CFLAliasAnalysis.h"
|
||||
#include "llvm/Analysis/CGSCCPassManager.h"
|
||||
|
|
|
@ -72,6 +72,7 @@ CGSCC_PASS("no-op-cgscc", NoOpCGSCCPass())
|
|||
#endif
|
||||
FUNCTION_ANALYSIS("aa", AAManager())
|
||||
FUNCTION_ANALYSIS("assumptions", AssumptionAnalysis())
|
||||
FUNCTION_ANALYSIS("block-freq", BlockFrequencyAnalysis())
|
||||
FUNCTION_ANALYSIS("branch-prob", BranchProbabilityAnalysis())
|
||||
FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis())
|
||||
FUNCTION_ANALYSIS("postdomtree", PostDominatorTreeAnalysis())
|
||||
|
@ -112,6 +113,7 @@ FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
|
|||
FUNCTION_PASS("gvn", GVN())
|
||||
FUNCTION_PASS("print", PrintFunctionPass(dbgs()))
|
||||
FUNCTION_PASS("print<assumptions>", AssumptionPrinterPass(dbgs()))
|
||||
FUNCTION_PASS("print<block-freq>", BlockFrequencyPrinterPass(dbgs()))
|
||||
FUNCTION_PASS("print<branch-prob>", BranchProbabilityPrinterPass(dbgs()))
|
||||
FUNCTION_PASS("print<domtree>", DominatorTreePrinterPass(dbgs()))
|
||||
FUNCTION_PASS("print<postdomtree>", PostDominatorTreePrinterPass(dbgs()))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -analyze -block-freq | FileCheck %s
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
|
||||
|
||||
declare void @g(i32 %x)
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -analyze -block-freq | FileCheck %s
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
|
||||
|
||||
define i32 @test1(i32 %i, i32* %a) {
|
||||
; CHECK-LABEL: Printing analysis {{.*}} for function 'test1':
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -analyze -block-freq | FileCheck %s
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
|
||||
|
||||
define void @double_backedge(i1 %x) {
|
||||
; CHECK-LABEL: Printing analysis {{.*}} for function 'double_backedge':
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -analyze -block-freq | FileCheck %s
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK-LABEL: Printing analysis {{.*}} for function 'double_exit':
|
||||
; CHECK-NEXT: block-frequency-info: double_exit
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -analyze -block-freq | FileCheck %s
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
|
||||
|
||||
; PR21622: Check for a crasher when the sum of exits to the same successor of a
|
||||
; loop overflows.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -analyze -block-freq | FileCheck %s
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
|
||||
|
||||
; A loop with multiple exits isn't irreducible. It should be handled
|
||||
; correctly.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -analyze -block-freq
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output
|
||||
|
||||
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 -analyze -block-freq | FileCheck %s
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK-LABEL: Printing analysis {{.*}} for function 'loop_with_branch':
|
||||
; CHECK-NEXT: block-frequency-info: loop_with_branch
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -analyze -block-freq | FileCheck %s
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
|
||||
|
||||
; This code contains three loops. One is triple-nested, the
|
||||
; second is double nested and the third is a single loop. At
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
; RUN: opt < %s -analyze -block-freq | FileCheck %s
|
||||
; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
|
||||
|
||||
; CHECK-LABEL: Printing analysis {{.*}} for function 'nested_loop_with_branches'
|
||||
; CHECK-NEXT: block-frequency-info: nested_loop_with_branches
|
||||
|
|
Loading…
Reference in New Issue