]> granicus.if.org Git - llvm/commitdiff
[PM] port Branch Frequency Analaysis pass to new PM
authorXinliang David Li <davidxl@google.com>
Thu, 5 May 2016 21:13:27 +0000 (21:13 +0000)
committerXinliang David Li <davidxl@google.com>
Thu, 5 May 2016 21:13:27 +0000 (21:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268687 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
include/llvm/Analysis/BlockFrequencyInfo.h
lib/Analysis/BlockFrequencyInfo.cpp
lib/Passes/PassBuilder.cpp
lib/Passes/PassRegistry.def
test/Analysis/BlockFrequencyInfo/bad_input.ll
test/Analysis/BlockFrequencyInfo/basic.ll
test/Analysis/BlockFrequencyInfo/double_backedge.ll
test/Analysis/BlockFrequencyInfo/double_exit.ll
test/Analysis/BlockFrequencyInfo/extremely-likely-loop-successor.ll
test/Analysis/BlockFrequencyInfo/irreducible.ll
test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll
test/Analysis/BlockFrequencyInfo/loop_with_branch.ll
test/Analysis/BlockFrequencyInfo/loops_with_profile_info.ll
test/Analysis/BlockFrequencyInfo/nested_loop_with_branches.ll

index 875775439b1372c723724afbebecc32b8c68eff4..ca9b129feb7869436106996fd7209d050a5c8e95 100644 (file)
@@ -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;
index 8b19b2e19c4190b9e7be8757203d6c3d10565655..a0c472d7c72c79e2da2ab1bd7a5fd52600b8d5ef 100644 (file)
@@ -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();
+}
index d26e796bb544d838db6e3837ca8b2f40ed4b9009..a81634cbb96641988cebbb0c951282b789097ee0 100644 (file)
@@ -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"
index d8c56070ce018558c8479855de09faf471366a6d..ca8b1033499cb0d216c1825422a8c9b295fd8be6 100644 (file)
@@ -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()))
index 20b87e6dfcb407d14f7c65610b6594b874300b08..39009a5ba838f24507db7258cac82ed093a805fb 100644 (file)
@@ -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)
 
index 8e81cc2ea31cc2817e1507abe971965681228369..44bfc36a71185f1964854ff1ec17c23b5c5d920f 100644 (file)
@@ -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':
index 597bf8329b263767107f494adfbde22c779bae27..4431c3a68219e50fad42d151e6b7ee061506f89b 100644 (file)
@@ -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':
index 3063ba70173101de75725a8f01c2218bf20b720e..5e9dded162c41369274d2dfed070588183cca3c8 100644 (file)
@@ -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
index e55deaff428df0059cc4d00bd922cbe52bab56e7..b9623683fe5a8ceac497aa907725aa428f2964db 100644 (file)
@@ -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.
index c1b1c2a7a23c16c05c60c05c6d45408a2f8ef3fb..83b0056636cfd2f090b5108cb4e5d809368ab8fc 100644 (file)
@@ -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.
index 2bcd088dd16ed3a9a6d5a96b15774b0ad933aeae..8cd334f04bca196f9fcf9506ac0379ada9c54140 100644 (file)
@@ -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"
index 9a86564c548ddd04ec31820409880887f780cd23..40d9e82351fd1316053b9e8c3e12aa1db5fc5818 100644 (file)
@@ -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
index 29a9f3b29fb08b6112bf43b3d09c5587b9863f0b..3133e167de5fbb4b6f0a5e2c335be5dff266263a 100644 (file)
@@ -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
index 19d165805b04601201fdf48780ea0514481a12f1..7025b5d16a45071780e0ba9db61ee57c52cecbe3 100644 (file)
@@ -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