mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[SCEV] Add a utility for converting from "exit count" to "trip count"
(Mostly as a logical place to put a comment since this is a reoccuring confusion.)
This commit is contained in:
parent
6982e1d1c2
commit
98697f161f
@ -705,6 +705,13 @@ public:
|
||||
bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
|
||||
const SCEV *LHS, const SCEV *RHS);
|
||||
|
||||
/// Convert from an "exit count" (i.e. "backedge taken count") to a "trip
|
||||
/// count". A "trip count" is the number of times the header of the loop
|
||||
/// will execute if an exit is taken after the specified number of backedges
|
||||
/// have been taken. (e.g. TripCount = ExitCount + 1) A zero result
|
||||
/// must be interpreted as a loop having an unknown trip count.
|
||||
const SCEV *getTripCountFromExitCount(const SCEV *ExitCount);
|
||||
|
||||
/// Returns the maximum trip count of the loop if it is a single-exit
|
||||
/// loop and we can compute a small maximum for that loop.
|
||||
///
|
||||
|
@ -109,9 +109,7 @@ static const SCEV *computeTripCount(const Loop &L, ScalarEvolution &SE) {
|
||||
if (isa<SCEVCouldNotCompute>(BackedgeTakenCount) ||
|
||||
!isa<SCEVConstant>(BackedgeTakenCount))
|
||||
return nullptr;
|
||||
|
||||
return SE.getAddExpr(BackedgeTakenCount,
|
||||
SE.getOne(BackedgeTakenCount->getType()));
|
||||
return SE.getTripCountFromExitCount(BackedgeTakenCount);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -6927,6 +6927,12 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
|
||||
// Iteration Count Computation Code
|
||||
//
|
||||
|
||||
const SCEV *ScalarEvolution::getTripCountFromExitCount(const SCEV *ExitCount) {
|
||||
// Get the trip count from the BE count by adding 1. Overflow, results
|
||||
// in zero which means "unknown".
|
||||
return getAddExpr(ExitCount, getOne(ExitCount->getType()));
|
||||
}
|
||||
|
||||
static unsigned getConstantTripCount(const SCEVConstant *ExitCount) {
|
||||
if (!ExitCount)
|
||||
return 0;
|
||||
@ -6979,8 +6985,8 @@ unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L,
|
||||
if (ExitCount == getCouldNotCompute())
|
||||
return 1;
|
||||
|
||||
// Get the trip count from the BE count by adding 1.
|
||||
const SCEV *TCExpr = getAddExpr(ExitCount, getOne(ExitCount->getType()));
|
||||
// Get the trip count
|
||||
const SCEV *TCExpr = getTripCountFromExitCount(ExitCount);
|
||||
|
||||
const SCEVConstant *TC = dyn_cast<SCEVConstant>(TCExpr);
|
||||
if (!TC)
|
||||
|
Loading…
Reference in New Issue
Block a user