ScalarEvolution.cpp (193323) | ScalarEvolution.cpp (193574) |
---|---|
1//===- ScalarEvolution.cpp - Scalar Evolution Analysis ----------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 66 unchanged lines hidden (view full) --- 75#include "llvm/Support/ConstantRange.h" 76#include "llvm/Support/GetElementPtrTypeIterator.h" 77#include "llvm/Support/InstIterator.h" 78#include "llvm/Support/ManagedStatic.h" 79#include "llvm/Support/MathExtras.h" 80#include "llvm/Support/raw_ostream.h" 81#include "llvm/ADT/Statistic.h" 82#include "llvm/ADT/STLExtras.h" | 1//===- ScalarEvolution.cpp - Scalar Evolution Analysis ----------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 66 unchanged lines hidden (view full) --- 75#include "llvm/Support/ConstantRange.h" 76#include "llvm/Support/GetElementPtrTypeIterator.h" 77#include "llvm/Support/InstIterator.h" 78#include "llvm/Support/ManagedStatic.h" 79#include "llvm/Support/MathExtras.h" 80#include "llvm/Support/raw_ostream.h" 81#include "llvm/ADT/Statistic.h" 82#include "llvm/ADT/STLExtras.h" |
83#include <ostream> | |
84#include <algorithm> 85using namespace llvm; 86 87STATISTIC(NumArrayLenItCounts, 88 "Number of trip counts computed with array length"); 89STATISTIC(NumTripCountsComputed, 90 "Number of loops with predictable loop counts"); 91STATISTIC(NumTripCountsNotComputed, --- 2366 unchanged lines hidden (view full) --- 2458 } 2459} 2460 2461/// ComputeBackedgeTakenCount - Compute the number of times the backedge 2462/// of the specified loop will execute. 2463ScalarEvolution::BackedgeTakenInfo 2464ScalarEvolution::ComputeBackedgeTakenCount(const Loop *L) { 2465 // If the loop has a non-one exit block count, we can't analyze it. | 83#include <algorithm> 84using namespace llvm; 85 86STATISTIC(NumArrayLenItCounts, 87 "Number of trip counts computed with array length"); 88STATISTIC(NumTripCountsComputed, 89 "Number of loops with predictable loop counts"); 90STATISTIC(NumTripCountsNotComputed, --- 2366 unchanged lines hidden (view full) --- 2457 } 2458} 2459 2460/// ComputeBackedgeTakenCount - Compute the number of times the backedge 2461/// of the specified loop will execute. 2462ScalarEvolution::BackedgeTakenInfo 2463ScalarEvolution::ComputeBackedgeTakenCount(const Loop *L) { 2464 // If the loop has a non-one exit block count, we can't analyze it. |
2466 SmallVector<BasicBlock*, 8> ExitBlocks; 2467 L->getExitBlocks(ExitBlocks); 2468 if (ExitBlocks.size() != 1) return UnknownValue; | 2465 BasicBlock *ExitBlock = L->getExitBlock(); 2466 if (!ExitBlock) 2467 return UnknownValue; |
2469 2470 // Okay, there is one exit block. Try to find the condition that causes the 2471 // loop to be exited. | 2468 2469 // Okay, there is one exit block. Try to find the condition that causes the 2470 // loop to be exited. |
2472 BasicBlock *ExitBlock = ExitBlocks[0]; | 2471 BasicBlock *ExitingBlock = L->getExitingBlock(); 2472 if (!ExitingBlock) 2473 return UnknownValue; // More than one block exiting! |
2473 | 2474 |
2474 BasicBlock *ExitingBlock = 0; 2475 for (pred_iterator PI = pred_begin(ExitBlock), E = pred_end(ExitBlock); 2476 PI != E; ++PI) 2477 if (L->contains(*PI)) { 2478 if (ExitingBlock == 0) 2479 ExitingBlock = *PI; 2480 else 2481 return UnknownValue; // More than one block exiting! 2482 } 2483 assert(ExitingBlock && "No exits from loop, something is broken!"); 2484 | |
2485 // Okay, we've computed the exiting block. See what condition causes us to 2486 // exit. 2487 // 2488 // FIXME: we should be able to handle switch instructions (with a single exit) 2489 BranchInst *ExitBr = dyn_cast<BranchInst>(ExitingBlock->getTerminator()); 2490 if (ExitBr == 0) return UnknownValue; 2491 assert(ExitBr->isConditional() && "If unconditional, it can't be in loop!"); 2492 --- 1332 unchanged lines hidden --- | 2475 // Okay, we've computed the exiting block. See what condition causes us to 2476 // exit. 2477 // 2478 // FIXME: we should be able to handle switch instructions (with a single exit) 2479 BranchInst *ExitBr = dyn_cast<BranchInst>(ExitingBlock->getTerminator()); 2480 if (ExitBr == 0) return UnknownValue; 2481 assert(ExitBr->isConditional() && "If unconditional, it can't be in loop!"); 2482 --- 1332 unchanged lines hidden --- |