Add the ability to synthesize function counts from block count information
authorChris Lattner <sabre@nondot.org>
Wed, 29 Oct 2003 21:47:44 +0000 (21:47 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 29 Oct 2003 21:47:44 +0000 (21:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9595 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-prof/ProfileInfo.cpp
tools/llvm-prof/llvm-prof.cpp

index 4c31138aa342bc10161ae1bce4edef044de7c795..78de9c16c7ae6098947a2c09caa71243769fc4ac 100644 (file)
@@ -141,8 +141,15 @@ ProfileInfo::ProfileInfo(const char *ToolName, const std::string &Filename,
 void ProfileInfo::getFunctionCounts(std::vector<std::pair<Function*,
                                                          unsigned> > &Counts) {
   if (FunctionCounts.empty()) {
-    std::cerr << "Function counts not available, and no synthesis "
-              << "is implemented yet!\n";
+    // Synthesize function frequency information from the number of times their
+    // entry blocks were executed.
+    std::vector<std::pair<BasicBlock*, unsigned> > BlockCounts;
+    getBlockCounts(BlockCounts);
+
+    for (unsigned i = 0, e = BlockCounts.size(); i != e; ++i)
+      if (&BlockCounts[i].first->getParent()->front() == BlockCounts[i].first)
+        Counts.push_back(std::make_pair(BlockCounts[i].first->getParent(),
+                                        BlockCounts[i].second));
     return;
   }
   
index 083e1ce17008c1ca648505710b6dfb7dd8ecc87b..a459a389373b60aa57722db4947bda0213cca151 100644 (file)
@@ -123,7 +123,7 @@ int main(int argc, char **argv) {
     unsigned BlocksToPrint = Counts.size();
     if (BlocksToPrint > 20) BlocksToPrint = 20;
     for (unsigned i = 0; i != BlocksToPrint; ++i)
-      printf("%3d. %5d/%d %s - %s\n", i+1, Counts[i].second, TotalExecutions,
+      printf("%3d. %5d/%d %s() - %s\n", i+1, Counts[i].second, TotalExecutions,
              Counts[i].first->getParent()->getName().c_str(),
              Counts[i].first->getName().c_str());