diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-10-19 10:12:41 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-10-19 10:12:41 +0000 |
commit | 6aa5c26c81071e22a23a6f0ae7dcac6080ad6597 (patch) | |
tree | 3a5596ca7926235cf9519ff63885c06e09f2945a | |
parent | 250c6801e4e16e4118fc130dff94dc89ea9332f1 (diff) | |
download | external_llvm-6aa5c26c81071e22a23a6f0ae7dcac6080ad6597.zip external_llvm-6aa5c26c81071e22a23a6f0ae7dcac6080ad6597.tar.gz external_llvm-6aa5c26c81071e22a23a6f0ae7dcac6080ad6597.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142491 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Analysis/BlockFrequencyInfo.h | 1 | ||||
-rw-r--r-- | lib/Analysis/BlockFrequencyInfo.cpp | 4 | ||||
-rw-r--r-- | test/Analysis/BlockFrequencyInfo/basic.ll | 24 | ||||
-rw-r--r-- | test/Analysis/BlockFrequencyInfo/dg.exp | 3 |
4 files changed, 32 insertions, 0 deletions
diff --git a/include/llvm/Analysis/BlockFrequencyInfo.h b/include/llvm/Analysis/BlockFrequencyInfo.h index 5978d5f..9e698a9 100644 --- a/include/llvm/Analysis/BlockFrequencyInfo.h +++ b/include/llvm/Analysis/BlockFrequencyInfo.h @@ -40,6 +40,7 @@ public: 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 diff --git a/lib/Analysis/BlockFrequencyInfo.cpp b/lib/Analysis/BlockFrequencyInfo.cpp index ee89915..d16665f 100644 --- a/lib/Analysis/BlockFrequencyInfo.cpp +++ b/lib/Analysis/BlockFrequencyInfo.cpp @@ -49,6 +49,10 @@ bool BlockFrequencyInfo::runOnFunction(Function &F) { 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 diff --git a/test/Analysis/BlockFrequencyInfo/basic.ll b/test/Analysis/BlockFrequencyInfo/basic.ll new file mode 100644 index 0000000..c09e3ff --- /dev/null +++ b/test/Analysis/BlockFrequencyInfo/basic.ll @@ -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 +} diff --git a/test/Analysis/BlockFrequencyInfo/dg.exp b/test/Analysis/BlockFrequencyInfo/dg.exp new file mode 100644 index 0000000..f200589 --- /dev/null +++ b/test/Analysis/BlockFrequencyInfo/dg.exp @@ -0,0 +1,3 @@ +load_lib llvm.exp + +RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]] |