#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>
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;
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;
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) {
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();
+}
#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"
#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())
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()))
; 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)
; 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':
; 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':
; 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
; 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.
; 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.
; 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"
; 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
; 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
; 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