summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-05-14 00:24:14 +0000
committerDan Gohman <gohman@apple.com>2008-05-14 00:24:14 +0000
commit45b3197090afedf2d19eb0b73115207343cbb2ae (patch)
tree010e14945dda915e0489d7ddef9e4eeb7a82a4a1 /include
parentc4f406e736d2cb5f313eef50abe1c0c935c4090e (diff)
downloadllvm-45b3197090afedf2d19eb0b73115207343cbb2ae.tar.gz
llvm-45b3197090afedf2d19eb0b73115207343cbb2ae.tar.bz2
llvm-45b3197090afedf2d19eb0b73115207343cbb2ae.tar.xz
Split the loop unroll mechanism logic out into a utility function.
Patch by Matthijs Kooijman! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51083 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Analysis/LoopInfo.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h
index 28748b0e54..e3e2cdd32d 100644
--- a/include/llvm/Analysis/LoopInfo.h
+++ b/include/llvm/Analysis/LoopInfo.h
@@ -418,6 +418,59 @@ public:
return 0;
}
+ /// getSmallConstantTripCount - Returns the trip count of this loop as a
+ /// normal unsigned value, if possible. Returns 0 if the trip count is unknown
+ /// of not constant. Will also return 0 if the trip count is very large
+ /// (>= 2^32)
+ inline unsigned getSmallConstantTripCount() const {
+ Value* TripCount = this->getTripCount();
+ if (TripCount) {
+ if (ConstantInt *TripCountC = dyn_cast<ConstantInt>(TripCount)) {
+ // Guard against huge trip counts.
+ if (TripCountC->getValue().getActiveBits() <= 32) {
+ return (unsigned)TripCountC->getZExtValue();
+ }
+ }
+ }
+ return 0;
+ }
+
+ /// getSmallConstantTripMultiple - Returns the largest constant divisor of the
+ /// trip count of this loop as a normal unsigned value, if possible. This
+ /// means that the actual trip count is always a multiple of the returned
+ /// value (don't forget the trip count could very well be zero as well!).
+ ///
+ /// Returns 1 if the trip count is unknown or not guaranteed to be the
+ /// multiple of a constant (which is also the case if the trip count is simply
+ /// constant, use getSmallConstantTripCount for that case), Will also return 1
+ /// if the trip count is very large (>= 2^32).
+ inline unsigned getSmallConstantTripMultiple() const {
+ Value* TripCount = this->getTripCount();
+ // This will hold the ConstantInt result, if any
+ ConstantInt *Result = NULL;
+ if (TripCount) {
+ // See if the trip count is constant itself
+ Result = dyn_cast<ConstantInt>(TripCount);
+ // if not, see if it is a multiplication
+ if (!Result)
+ if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TripCount)) {
+ switch (BO->getOpcode()) {
+ case BinaryOperator::Mul:
+ Result = dyn_cast<ConstantInt>(BO->getOperand(1));
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ // Guard against huge trip counts.
+ if (Result && Result->getValue().getActiveBits() <= 32) {
+ return (unsigned)Result->getZExtValue();
+ } else {
+ return 1;
+ }
+ }
+
/// isLCSSAForm - Return true if the Loop is in LCSSA form
inline bool isLCSSAForm() const {
// Sort the blocks vector so that we can use binary search to do quick