Make error messages more useful than jsut an abort
[oota-llvm.git] / lib / Analysis / PostDominators.cpp
index 2e49854249216474e345482d791c7b4517a96fcb..f027949793f853e16c07c11d5839ce00f1635ce7 100644 (file)
@@ -4,7 +4,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Analysis/Dominators.h"
+#include "llvm/Analysis/PostDominators.h"
 #include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
 #include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
@@ -17,7 +17,6 @@ using std::set;
 
 static RegisterAnalysis<PostDominatorSet>
 B("postdomset", "Post-Dominator Set Construction", true);
-AnalysisID PostDominatorSet::ID = B;
 
 // Postdominator set construction.  This converts the specified function to only
 // have a single exit node (return stmt), then calculates the post dominance
@@ -60,6 +59,18 @@ bool PostDominatorSet::runOnFunction(Function &F) {
          if (PredSet.size())
            set_intersect(WorkingSet, PredSet);
        }
+      } else if (BB != Root) {
+        // If this isn't the root basic block and it has no successors, it must
+        // be an non-returning block.  Fib a bit by saying that the root node
+        // postdominates this unreachable node.  This isn't exactly true,
+        // because there is no path from this node to the root node, but it is
+        // sorta true because any paths to the exit node would have to go
+        // through this node.
+        //
+        // This allows for postdominator properties to be built for code that
+        // doesn't return in a reasonable manner.
+        //
+        WorkingSet = Doms[Root];
       }
        
       WorkingSet.insert(BB);           // A block always dominates itself
@@ -88,7 +99,6 @@ void PostDominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
 
 static RegisterAnalysis<ImmediatePostDominators>
 D("postidom", "Immediate Post-Dominators Construction", true);
-AnalysisID ImmediatePostDominators::ID = D;
 
 //===----------------------------------------------------------------------===//
 //  PostDominatorTree Implementation
@@ -96,7 +106,6 @@ AnalysisID ImmediatePostDominators::ID = D;
 
 static RegisterAnalysis<PostDominatorTree>
 F("postdomtree", "Post-Dominator Tree Construction", true);
-AnalysisID PostDominatorTree::ID = F;
 
 void PostDominatorTree::calculate(const PostDominatorSet &DS) {
   Nodes[Root] = new Node(Root, 0);   // Add a node for the root...
@@ -152,7 +161,6 @@ void PostDominatorTree::calculate(const PostDominatorSet &DS) {
 
 static RegisterAnalysis<PostDominanceFrontier>
 H("postdomfrontier", "Post-Dominance Frontier Construction", true);
-AnalysisID PostDominanceFrontier::ID = H;
 
 const DominanceFrontier::DomSetType &
 PostDominanceFrontier::calculate(const PostDominatorTree &DT, 
@@ -187,3 +195,7 @@ PostDominanceFrontier::calculate(const PostDominatorTree &DT,
 
   return S;
 }
+
+// stub - a dummy function to make linking work ok.
+void PostDominanceFrontier::stub() {
+}