Enhance the TD pass to build composite graphs when we have indirect call
[oota-llvm.git] / lib / Analysis / LoopInfo.cpp
index c4b2bf681461b4264a6bd2db8f6ae66f545ea444..156d8b1bace4092a71cc64a2b83bcb797d889911 100644 (file)
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Assembly/Writer.h"
 #include "llvm/Support/CFG.h"
-#include "Support/DepthFirstIterator.h"
+#include "llvm/ADT/DepthFirstIterator.h"
 #include <algorithm>
+#include <iostream>
+
 using namespace llvm;
 
 static RegisterAnalysis<LoopInfo>
@@ -31,7 +33,7 @@ X("loops", "Natural Loop Construction", true);
 // Loop implementation
 //
 bool Loop::contains(const BasicBlock *BB) const {
-  return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
+  return std::find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
 }
 
 bool Loop::isLoopExit(const BasicBlock *BB) const {
@@ -117,7 +119,7 @@ void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<DominatorSet>();
 }
 
-void LoopInfo::print(std::ostream &OS) const {
+void LoopInfo::print(std::ostream &OS, const Module* ) const {
   for (unsigned i = 0; i < TopLevelLoops.size(); ++i)
     TopLevelLoops[i]->print(OS);
 #if 0
@@ -402,15 +404,15 @@ PHINode *Loop::getCanonicalInductionVariable() const {
     return 0;
 
   // Loop over all of the PHI nodes, looking for a canonical indvar.
-  for (BasicBlock::iterator I = H->begin();
-       PHINode *PN = dyn_cast<PHINode>(I); ++I)
+  for (BasicBlock::iterator I = H->begin(); isa<PHINode>(I); ++I) {
+    PHINode *PN = cast<PHINode>(I);
     if (Instruction *Inc =
         dyn_cast<Instruction>(PN->getIncomingValueForBlock(Backedge)))
       if (Inc->getOpcode() == Instruction::Add && Inc->getOperand(0) == PN)
         if (ConstantInt *CI = dyn_cast<ConstantInt>(Inc->getOperand(1)))
           if (CI->equalsInt(1))
             return PN;
-
+  }
   return 0;
 }
 
@@ -442,14 +444,15 @@ Value *Loop::getTripCount() const {
     IV->getIncomingBlock(contains(IV->getIncomingBlock(1)));
 
   if (BranchInst *BI = dyn_cast<BranchInst>(BackedgeBlock->getTerminator()))
-    if (SetCondInst *SCI = dyn_cast<SetCondInst>(BI->getCondition()))
-      if (SCI->getOperand(0) == Inc)
-        if (BI->getSuccessor(0) == getHeader()) {
-          if (SCI->getOpcode() == Instruction::SetNE)
+    if (BI->isConditional())
+      if (SetCondInst *SCI = dyn_cast<SetCondInst>(BI->getCondition()))
+        if (SCI->getOperand(0) == Inc)
+          if (BI->getSuccessor(0) == getHeader()) {
+            if (SCI->getOpcode() == Instruction::SetNE)
+              return SCI->getOperand(1);
+          } else if (SCI->getOpcode() == Instruction::SetEQ) {
             return SCI->getOperand(1);
-        } else if (SCI->getOpcode() == Instruction::SetEQ) {
-          return SCI->getOperand(1);
-        }
+          }
   
   return 0;
 }