changes for 64bit gcc
[oota-llvm.git] / lib / VMCore / Dominators.cpp
index 59a61cbdd27d85f1a73a546427273ea13e7c1ce4..caff1f1db3048f5b7b04d678a3b6fe0210585e94 100644 (file)
@@ -6,7 +6,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/Dominators.h"
-#include "llvm/Transforms/Scalar/UnifyFunctionExitNodes.h"
+#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
 #include "llvm/Support/CFG.h"
 #include "Support/DepthFirstIterator.h"
 #include "Support/STLExtras.h"
@@ -21,7 +21,7 @@ using std::set;
 AnalysisID DominatorSet::ID(AnalysisID::create<DominatorSet>(), true);
 AnalysisID DominatorSet::PostDomID(AnalysisID::create<DominatorSet>(), true);
 
-bool DominatorSet::runOnFunction(Function *F) {
+bool DominatorSet::runOnFunction(Function &F) {
   Doms.clear();   // Reset from the last time we were run...
 
   if (isPostDominator())
@@ -31,12 +31,26 @@ bool DominatorSet::runOnFunction(Function *F) {
   return false;
 }
 
+// dominates - Return true if A dominates B.  This performs the special checks
+// neccesary if A and B are in the same basic block.
+//
+bool DominatorSet::dominates(Instruction *A, Instruction *B) const {
+  BasicBlock *BBA = A->getParent(), *BBB = B->getParent();
+  if (BBA != BBB) return dominates(BBA, BBB);
+  
+  // Loop through the basic block until we find A or B.
+  BasicBlock::iterator I = BBA->begin();
+  for (; &*I != A && &*I != B; ++I) /*empty*/;
+  
+  // A dominates B if it is found first in the basic block...
+  return &*I == A;
+}
 
 // calcForwardDominatorSet - This method calculates the forward dominator sets
 // for the specified function.
 //
-void DominatorSet::calcForwardDominatorSet(Function *M) {
-  Root = M->getEntryNode();
+void DominatorSet::calcForwardDominatorSet(Function &F) {
+  Root = &F.getEntryNode();
   assert(pred_begin(Root) == pred_end(Root) &&
         "Root node has predecessors in function!");
 
@@ -45,7 +59,7 @@ void DominatorSet::calcForwardDominatorSet(Function *M) {
     Changed = false;
 
     DomSetType WorkingSet;
-    df_iterator<Function*> It = df_begin(M), End = df_end(M);
+    df_iterator<Function*> It = df_begin(&F), End = df_end(&F);
     for ( ; It != End; ++It) {
       BasicBlock *BB = *It;
       pred_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
@@ -79,7 +93,7 @@ void DominatorSet::calcForwardDominatorSet(Function *M) {
 // only have a single exit node (return stmt), then calculates the post
 // dominance sets for the function.
 //
-void DominatorSet::calcPostDominatorSet(Function *F) {
+void DominatorSet::calcPostDominatorSet(Function &F) {
   // Since we require that the unify all exit nodes pass has been run, we know
   // that there can be at most one return instruction in the function left.
   // Get it.
@@ -87,8 +101,8 @@ void DominatorSet::calcPostDominatorSet(Function *F) {
   Root = getAnalysis<UnifyFunctionExitNodes>().getExitNode();
 
   if (Root == 0) {  // No exit node for the function?  Postdomsets are all empty
-    for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
-      Doms[*FI] = DomSetType();
+    for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
+      Doms[FI] = DomSetType();
     return;
   }