/// an analyzable loop-invariant iteration count.
bool hasLoopInvariantIterationCount(const Loop *L) const;
+ /// forgetLoopIterationCount - This method should be called by the
+ /// client when it has changed a loop in a way that may effect
+ /// ScalarEvolution's ability to compute a trip count.
+ void forgetLoopIterationCount(const Loop *L);
+
/// deleteValueFromRecords - This method should be called by the
/// client before it removes a Value from the program, to make sure
/// that no dangling references are left around.
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/LoopPass.h"
-#include "llvm/Analysis/ScalarEvolution.h"
using namespace llvm;
//===----------------------------------------------------------------------===//
// LPPassManager needs LoopInfo. In the long term LoopInfo class will
// become part of LPPassManager.
Info.addRequired<LoopInfo>();
- // Used by IndVar doInitialization.
- Info.addRequired<ScalarEvolution>();
Info.setPreservesAll();
}
/// an analyzable loop-invariant iteration count.
bool hasLoopInvariantIterationCount(const Loop *L);
+ /// forgetLoopIterationCount - This method should be called by the
+ /// client when it has changed a loop in a way that may effect
+ /// ScalarEvolution's ability to compute a trip count.
+ void forgetLoopIterationCount(const Loop *L);
+
/// getIterationCount - If the specified loop has a predictable iteration
/// count, return it. Note that it is not valid to call this method on a
/// loop without a loop-invariant iteration count.
return I->second;
}
+/// forgetLoopIterationCount - This method should be called by the
+/// client when it has changed a loop in a way that may effect
+/// ScalarEvolution's ability to compute a trip count.
+void ScalarEvolutionsImpl::forgetLoopIterationCount(const Loop *L) {
+ IterationCounts.erase(L);
+}
+
/// ComputeIterationCount - Compute the number of times the specified loop
/// will iterate.
SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) {
return !isa<SCEVCouldNotCompute>(getIterationCount(L));
}
+void ScalarEvolution::forgetLoopIterationCount(const Loop *L) {
+ return ((ScalarEvolutionsImpl*)Impl)->forgetLoopIterationCount(L);
+}
+
SCEVHandle ScalarEvolution::getSCEVAtScope(Value *V, const Loop *L) const {
return ((ScalarEvolutionsImpl*)Impl)->getSCEVAtScope(getSCEV(V), L);
}
static char ID; // Pass identification, replacement for typeid
IndVarSimplify() : LoopPass(&ID) {}
- bool runOnLoop(Loop *L, LPPassManager &LPM);
- bool doInitialization(Loop *L, LPPassManager &LPM);
+ virtual bool runOnLoop(Loop *L, LPPassManager &LPM);
+
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<ScalarEvolution>();
AU.addRequiredID(LCSSAID);
private:
+ void RewriteNonIntegerIVs(Loop *L);
+
void EliminatePointerRecurrence(PHINode *PN, BasicBlock *Preheader,
SmallPtrSet<Instruction*, 16> &DeadInsts);
void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount,
DeleteTriviallyDeadInstructions(InstructionsToDelete);
}
-bool IndVarSimplify::doInitialization(Loop *L, LPPassManager &LPM) {
-
- Changed = false;
+void IndVarSimplify::RewriteNonIntegerIVs(Loop *L) {
// First step. Check to see if there are any trivial GEP pointer recurrences.
// If there are, change them into integer recurrences, permitting analysis by
// the SCEV routines.
//
BasicBlock *Header = L->getHeader();
BasicBlock *Preheader = L->getLoopPreheader();
- SE = &LPM.getAnalysis<ScalarEvolution>();
SmallPtrSet<Instruction*, 16> DeadInsts;
for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
HandleFloatingPointIV(L, PN, DeadInsts);
}
+ // If the loop previously had a pointer or floating-point IV, ScalarEvolution
+ // may not have been able to compute a trip count. Now that we've done some
+ // re-writing, the trip count may be computable.
+ if (Changed)
+ SE->forgetLoopIterationCount(L);
+
if (!DeadInsts.empty())
DeleteTriviallyDeadInstructions(DeadInsts);
-
- return Changed;
}
/// getEffectiveIndvarType - Determine the widest type that the
bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
LI = &getAnalysis<LoopInfo>();
SE = &getAnalysis<ScalarEvolution>();
-
Changed = false;
+
+ // If there are any floating-point or pointer recurrences, attempt to
+ // transform them to use integer recurrences.
+ RewriteNonIntegerIVs(L);
+
BasicBlock *Header = L->getHeader();
BasicBlock *ExitingBlock = L->getExitingBlock();
SmallPtrSet<Instruction*, 16> DeadInsts;