Preparation for Optimal Edge Profiling:
Optimal edge profiling is only possible when blocks with no predecessors get an
virtual edge (BB,0) that counts the execution frequencies of this
function-exiting blocks.
This patch makes the necessary changes before actually enabling optimal edge profiling.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80667 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/Analysis/ProfileInfo.h b/include/llvm/Analysis/ProfileInfo.h
index 16bfc13..94a8666 100644
--- a/include/llvm/Analysis/ProfileInfo.h
+++ b/include/llvm/Analysis/ProfileInfo.h
@@ -63,8 +63,13 @@
 
     // getFunction() - Returns the Function for an Edge, checking for validity.
     static const Function* getFunction(Edge e) {
-      assert(e.second && "Invalid ProfileInfo::Edge");
-      return e.second->getParent();
+      if (e.first) {
+        return e.first->getParent();
+      } else if (e.second) {
+        return e.second->getParent();
+      }
+      assert(0 && "Invalid ProfileInfo::Edge");
+      return (const Function*)0;
     }
 
     // getEdge() - Creates an Edge from two BasicBlocks.
diff --git a/lib/Analysis/ProfileEstimatorPass.cpp b/lib/Analysis/ProfileEstimatorPass.cpp
index 8f5313f..3af7eba 100644
--- a/lib/Analysis/ProfileEstimatorPass.cpp
+++ b/lib/Analysis/ProfileEstimatorPass.cpp
@@ -168,7 +168,14 @@
   std::set<BasicBlock*> ProcessedSuccs;
 
   // Otherwise consider weight of outgoing edges and store them for
-  // distribution of remaining weight.
+  // distribution of remaining weight. In case the block has no successors
+  // create a (BB,0) edge.
+  succ_iterator bbi = succ_begin(BB), bbe = succ_end(BB);
+  if (bbi == bbe) {
+    Edge edge = getEdge(BB,0);
+    EdgeInformation[BB->getParent()][edge] = BBWeight;
+    printEdgeWeight(edge);
+  }
   for ( succ_iterator bbi = succ_begin(BB), bbe = succ_end(BB);
         bbi != bbe; ++bbi ) {
     if (ProcessedSuccs.insert(*bbi).second) {