[llvm-commits] [llvm] r142491 - in /llvm/trunk: include/llvm/Analysis/BlockFrequencyInfo.h lib/Analysis/BlockFrequencyInfo.cpp test/Analysis/BlockFrequencyInfo/ test/Analysis/BlockFrequencyInfo/basic.ll test/Analysis/BlockFrequencyInfo/dg.exp

Chandler Carruth chandlerc at gmail.com
Wed Oct 19 03:12:41 PDT 2011


Author: chandlerc
Date: Wed Oct 19 05:12:41 2011
New Revision: 142491

URL: http://llvm.org/viewvc/llvm-project?rev=142491&view=rev
Log:
Add pass printing support to BlockFrequencyInfo pass. The implementation
layer already had support for printing the results of this analysis, but
the wiring was missing.

Now that printing the analysis works, actually bring some of this
analysis, and the BranchProbabilityInfo analysis that it wraps, under
test! I'm planning on fixing some bugs and doing other work here, so
having a nice place to add regression tests and a way to observe the
results is really useful.

Added:
    llvm/trunk/test/Analysis/BlockFrequencyInfo/
    llvm/trunk/test/Analysis/BlockFrequencyInfo/basic.ll
    llvm/trunk/test/Analysis/BlockFrequencyInfo/dg.exp
Modified:
    llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h
    llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp

Modified: llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h?rev=142491&r1=142490&r2=142491&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/BlockFrequencyInfo.h Wed Oct 19 05:12:41 2011
@@ -40,6 +40,7 @@
   void getAnalysisUsage(AnalysisUsage &AU) const;
 
   bool runOnFunction(Function &F);
+  void print(raw_ostream &O, const Module *M) const;
 
   /// getblockFreq - Return block frequency. Return 0 if we don't have the
   /// information. Please note that initial frequency is equal to 1024. It means

Modified: llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp?rev=142491&r1=142490&r2=142491&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BlockFrequencyInfo.cpp Wed Oct 19 05:12:41 2011
@@ -49,6 +49,10 @@
   return false;
 }
 
+void BlockFrequencyInfo::print(raw_ostream &O, const Module *) const {
+  if (BFI) BFI->print(O);
+}
+
 /// getblockFreq - Return block frequency. Return 0 if we don't have the
 /// information. Please note that initial frequency is equal to 1024. It means
 /// that we should not rely on the value itself, but only on the comparison to

Added: llvm/trunk/test/Analysis/BlockFrequencyInfo/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/basic.ll?rev=142491&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/basic.ll (added)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/basic.ll Wed Oct 19 05:12:41 2011
@@ -0,0 +1,24 @@
+; RUN: opt < %s -analyze -block-freq | FileCheck %s
+
+define i32 @test1(i32 %i, i32* %a) {
+; CHECK: Printing analysis {{.*}} for function 'test1'
+; CHECK: entry = 1024
+entry:
+  br label %body
+
+; Loop backedges are weighted and thus their bodies have a greater frequency.
+; CHECK: body = 31744
+body:
+  %iv = phi i32 [ 0, %entry ], [ %next, %body ]
+  %base = phi i32 [ 0, %entry ], [ %sum, %body ]
+  %arrayidx = getelementptr inbounds i32* %a, i32 %iv
+  %0 = load i32* %arrayidx
+  %sum = add nsw i32 %0, %base
+  %next = add i32 %iv, 1
+  %exitcond = icmp eq i32 %next, %i
+  br i1 %exitcond, label %exit, label %body
+
+; CHECK: exit = 1024
+exit:
+  ret i32 %sum
+}

Added: llvm/trunk/test/Analysis/BlockFrequencyInfo/dg.exp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BlockFrequencyInfo/dg.exp?rev=142491&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/BlockFrequencyInfo/dg.exp (added)
+++ llvm/trunk/test/Analysis/BlockFrequencyInfo/dg.exp Wed Oct 19 05:12:41 2011
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]]





More information about the llvm-commits mailing list