[llvm] r268687 - [PM] port Branch Frequency Analaysis pass to new PM

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 14:13:27 PDT 2016


Author: davidxl
Date: Thu May  5 16:13:27 2016
New Revision: 268687

URL: http://llvm.org/viewvc/llvm-project?rev=268687&view=rev
Log:
[PM] port Branch Frequency Analaysis pass to new PM

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

Modified: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h Thu May  5 16:13:27 2016
@@ -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;

Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp Thu May  5 16:13:27 2016
@@ -113,6 +113,15 @@ BlockFrequencyInfo::BlockFrequencyInfo(c
   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::runO
   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();
+}

Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Thu May  5 16:13:27 2016
@@ -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"

Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Thu May  5 16:13:27 2016
@@ -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", LowerExpec
 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()))

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/bad_input.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/bad_input.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/bad_input.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/bad_input.ll Thu May  5 16:13:27 2016
@@ -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)
 

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/basic.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/basic.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/basic.ll Thu May  5 16:13:27 2016
@@ -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':

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/double_backedge.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/double_backedge.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/double_backedge.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/double_backedge.ll Thu May  5 16:13:27 2016
@@ -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':

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/double_exit.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/double_exit.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/double_exit.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/double_exit.ll Thu May  5 16:13:27 2016
@@ -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

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/extremely-likely-loop-successor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/extremely-likely-loop-successor.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/extremely-likely-loop-successor.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/extremely-likely-loop-successor.ll Thu May  5 16:13:27 2016
@@ -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.

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible.ll Thu May  5 16:13:27 2016
@@ -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.

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/irreducible_loop_crash.ll Thu May  5 16:13:27 2016
@@ -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"

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/loop_with_branch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/loop_with_branch.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/loop_with_branch.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/loop_with_branch.ll Thu May  5 16:13:27 2016
@@ -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

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/loops_with_profile_info.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/loops_with_profile_info.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/loops_with_profile_info.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/loops_with_profile_info.ll Thu May  5 16:13:27 2016
@@ -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

Modified: llvm/trunk/test/Analysis/BlockFrequencyInfo/nested_loop_with_branches.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/nested_loop_with_branches.ll?rev=268687&r1=268686&r2=268687&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/nested_loop_with_branches.ll (original)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/nested_loop_with_branches.ll Thu May  5 16:13:27 2016
@@ -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




More information about the llvm-commits mailing list