[llvm-commits] CVS: llvm/tools/llvm-prof/ProfileInfo.cpp ProfileInfo.h llvm-prof.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 28 15:26:01 PST 2003


Changes in directory llvm/tools/llvm-prof:

ProfileInfo.cpp updated: 1.2 -> 1.3
ProfileInfo.h updated: 1.2 -> 1.3
llvm-prof.cpp updated: 1.3 -> 1.4

---
Log message:

Add support for reading block frequencies.  Fix bug in attribution of counts
to functions



---
Diffs of the changes:  (+48 -2)

Index: llvm/tools/llvm-prof/ProfileInfo.cpp
diff -u llvm/tools/llvm-prof/ProfileInfo.cpp:1.2 llvm/tools/llvm-prof/ProfileInfo.cpp:1.3
--- llvm/tools/llvm-prof/ProfileInfo.cpp:1.2	Tue Oct 28 15:08:18 2003
+++ llvm/tools/llvm-prof/ProfileInfo.cpp	Tue Oct 28 15:25:23 2003
@@ -148,7 +148,28 @@
   
   unsigned Counter = 0;
   for (Module::iterator I = M.begin(), E = M.end();
-       I != E && Counter != FunctionCounts.size(); ++I, ++Counter)
+       I != E && Counter != FunctionCounts.size(); ++I)
     if (!I->isExternal())
-      Counts.push_back(std::make_pair(I, FunctionCounts[Counter]));
+      Counts.push_back(std::make_pair(I, FunctionCounts[Counter++]));
+}
+
+// getBlockCounts - This method is used by consumers of block counting
+// information.  If we do not directly have block count information, we
+// compute it from other, more refined, types of profile information.
+//
+void ProfileInfo::getBlockCounts(std::vector<std::pair<BasicBlock*,
+                                                       unsigned> > &Counts) {
+  if (BlockCounts.empty()) {
+    std::cerr << "Block counts not available, and no synthesis "
+              << "is implemented yet!\n";
+    return;
+  }
+
+  unsigned Counter = 0;
+  for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
+    for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
+      Counts.push_back(std::make_pair(BB, BlockCounts[Counter++]));
+      if (Counter == BlockCounts.size())
+        return;
+    }
 }


Index: llvm/tools/llvm-prof/ProfileInfo.h
diff -u llvm/tools/llvm-prof/ProfileInfo.h:1.2 llvm/tools/llvm-prof/ProfileInfo.h:1.3
--- llvm/tools/llvm-prof/ProfileInfo.h:1.2	Tue Oct 28 15:08:18 2003
+++ llvm/tools/llvm-prof/ProfileInfo.h	Tue Oct 28 15:25:23 2003
@@ -20,6 +20,7 @@
 #include <utility>
 class Module;
 class Function;
+class BasicBlock;
 
 class ProfileInfo {
   Module &M;
@@ -37,6 +38,18 @@
   //
   void getFunctionCounts(std::vector<std::pair<Function*, unsigned> > &Counts);
 
+  // hasAccurateBlockCounts - Return true if we can synthesize accurate block
+  // frequency information from whatever we have.
+  //
+  bool hasAccurateBlockCounts() const {
+    return !BlockCounts.empty();
+  }
+
+  // getBlockCounts - This method is used by consumers of block counting
+  // information.  If we do not directly have block count information, we
+  // compute it from other, more refined, types of profile information.
+  //
+  void getBlockCounts(std::vector<std::pair<BasicBlock*, unsigned> > &Counts);
 };
 
 #endif


Index: llvm/tools/llvm-prof/llvm-prof.cpp
diff -u llvm/tools/llvm-prof/llvm-prof.cpp:1.3 llvm/tools/llvm-prof/llvm-prof.cpp:1.4
--- llvm/tools/llvm-prof/llvm-prof.cpp:1.3	Tue Oct 28 15:08:18 2003
+++ llvm/tools/llvm-prof/llvm-prof.cpp	Tue Oct 28 15:25:23 2003
@@ -19,6 +19,7 @@
 #include "Support/CommandLine.h"
 #include <iostream>
 #include <cstdio>
+#include <map>
 
 namespace {
   cl::opt<std::string> 
@@ -77,5 +78,16 @@
   for (unsigned i = 0, e = FunctionCounts.size(); i != e; ++i)
     printf("%3d. %5d/%d %s\n", i, FunctionCounts[i].second, TotalExecutions,
            FunctionCounts[i].first->getName().c_str());
+
+
+  // If we have block count information, print out the LLVM module with
+  // frequency annotations.
+  if (PI.hasAccurateBlockCounts()) {
+    std::vector<std::pair<BasicBlock*, unsigned> > Counts;
+    PI.getBlockCounts(Counts);
+    std::map<BasicBlock*, unsigned> BlockFreqs(Counts.begin(), Counts.end());
+                   
+  }
+
   return 0;
 }





More information about the llvm-commits mailing list