#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>
// 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 {
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
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;
}
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;
}