100 AU.setPreservesCFG();
101 AU.addRequiredID(llvm::LoopSimplifyID);
102 AU.addRequiredID(llvm::LCSSAID);
103 AU.addPreservedID(llvm::LCSSAID);
104 AU.addRequired<llvm::LoopInfoWrapperPass>();
105 AU.addRequired<llvm::ScalarEvolutionWrapperPass>();
106 AU.addPreserved<llvm::LoopInfoWrapperPass>();
107 AU.addPreserved<llvm::ScalarEvolutionWrapperPass>();
172 const std::vector<llvm::Loop*>& subLoops = l->getSubLoops();
174 unsigned subLoopCount = subLoops.size();
176 unsigned bbCount = l->getBlocks().size();
180 llvm::SmallVector<llvm::BasicBlock*, 10> exitingBlocks;
192 l->getExitingBlocks(exitingBlocks);
193 unsigned exitingBlockCount = exitingBlocks.size();
196 unsigned callCount = 0;
197 if (subLoopCount == 0) {
198 for (llvm::LoopBase<llvm::BasicBlock, llvm::Loop>::
200 l->block_begin(); bb != l->block_end(); ++bb) {
201 llvm::BasicBlock& basicBlock = **bb;
202 for (llvm::BasicBlock::iterator i = basicBlock.begin();
203 i != basicBlock.end(); ++i) {
204 llvm::Instruction& instruction = *i;
205 if (instruction.getOpcode() == llvm::Instruction::Call)
211 const bool innerLoop =
212 bbCount == 1 && subLoopCount == 0 && callCount == 0;
215 if (
dump && tripCount > 0) {
216 out(l) <<
"found an inner loop with trip count "
217 << tripCount << std::endl;
219 assert(l->getBlocks().size() > 0);
227 <<
"depth: " << l->getLoopDepth() << std::endl;
228 out(l) <<
"sub loops: " << subLoopCount << std::endl;
229 out(l) <<
"trip count: ";
230 if (tripCount != 0) {
231 out(l) <<
"constant: " << tripCount;
233 out(l) <<
"unknown ";
236 out(l) <<
"basic blocks: " << bbCount << std::endl;
238 if (subLoopCount == 0)
239 out(l) <<
"calls: " << callCount << std::endl;
INITIALIZE_PASS_BEGIN(InnerLoopFinder, "find-innerloops", "Finds info of the inner loops in the program.", false, true) INITIALIZE_PASS_END(InnerLoopFinder
static llvm::cl::opt< bool > DumpLoopInfo("dump-loop-info", llvm::cl::init(false), llvm::cl::Hidden, llvm::cl::desc("Dump information about loops to files named [modulename].loopinfo.txt."))
static llvm::RegisterPass< InnerLoopFinder > X("find-innerloops-test", "Finds inner loops test.", false, true)