mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 21:32:39 +00:00
Add a method to ScalarEvolution for telling it when a loop has been
modified in a way that may effect the trip count calculation. Change IndVars to use this method when it rewrites pointer or floating-point induction variables instead of using a doInitialization method to sneak these changes in before ScalarEvolution has a chance to see the loop. This eliminates the need for LoopPass to depend on ScalarEvolution. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@64810 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a84f47c3e7
commit
60f8a63e25
@ -301,6 +301,11 @@ namespace llvm {
|
|||||||
/// an analyzable loop-invariant iteration count.
|
/// an analyzable loop-invariant iteration count.
|
||||||
bool hasLoopInvariantIterationCount(const Loop *L) const;
|
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
|
/// deleteValueFromRecords - This method should be called by the
|
||||||
/// client before it removes a Value from the program, to make sure
|
/// client before it removes a Value from the program, to make sure
|
||||||
/// that no dangling references are left around.
|
/// that no dangling references are left around.
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Analysis/LoopPass.h"
|
#include "llvm/Analysis/LoopPass.h"
|
||||||
#include "llvm/Analysis/ScalarEvolution.h"
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -173,8 +172,6 @@ void LPPassManager::getAnalysisUsage(AnalysisUsage &Info) const {
|
|||||||
// LPPassManager needs LoopInfo. In the long term LoopInfo class will
|
// LPPassManager needs LoopInfo. In the long term LoopInfo class will
|
||||||
// become part of LPPassManager.
|
// become part of LPPassManager.
|
||||||
Info.addRequired<LoopInfo>();
|
Info.addRequired<LoopInfo>();
|
||||||
// Used by IndVar doInitialization.
|
|
||||||
Info.addRequired<ScalarEvolution>();
|
|
||||||
Info.setPreservesAll();
|
Info.setPreservesAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1453,6 +1453,11 @@ namespace {
|
|||||||
/// an analyzable loop-invariant iteration count.
|
/// an analyzable loop-invariant iteration count.
|
||||||
bool hasLoopInvariantIterationCount(const Loop *L);
|
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
|
/// getIterationCount - If the specified loop has a predictable iteration
|
||||||
/// count, return it. Note that it is not valid to call this method on a
|
/// count, return it. Note that it is not valid to call this method on a
|
||||||
/// loop without a loop-invariant iteration count.
|
/// loop without a loop-invariant iteration count.
|
||||||
@ -1931,6 +1936,13 @@ SCEVHandle ScalarEvolutionsImpl::getIterationCount(const Loop *L) {
|
|||||||
return I->second;
|
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
|
/// ComputeIterationCount - Compute the number of times the specified loop
|
||||||
/// will iterate.
|
/// will iterate.
|
||||||
SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) {
|
SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) {
|
||||||
@ -3091,6 +3103,10 @@ bool ScalarEvolution::hasLoopInvariantIterationCount(const Loop *L) const {
|
|||||||
return !isa<SCEVCouldNotCompute>(getIterationCount(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 {
|
SCEVHandle ScalarEvolution::getSCEVAtScope(Value *V, const Loop *L) const {
|
||||||
return ((ScalarEvolutionsImpl*)Impl)->getSCEVAtScope(getSCEV(V), L);
|
return ((ScalarEvolutionsImpl*)Impl)->getSCEVAtScope(getSCEV(V), L);
|
||||||
}
|
}
|
||||||
|
@ -74,8 +74,8 @@ namespace {
|
|||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
IndVarSimplify() : LoopPass(&ID) {}
|
IndVarSimplify() : LoopPass(&ID) {}
|
||||||
|
|
||||||
bool runOnLoop(Loop *L, LPPassManager &LPM);
|
virtual bool runOnLoop(Loop *L, LPPassManager &LPM);
|
||||||
bool doInitialization(Loop *L, LPPassManager &LPM);
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.addRequired<ScalarEvolution>();
|
AU.addRequired<ScalarEvolution>();
|
||||||
AU.addRequiredID(LCSSAID);
|
AU.addRequiredID(LCSSAID);
|
||||||
@ -88,6 +88,8 @@ namespace {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void RewriteNonIntegerIVs(Loop *L);
|
||||||
|
|
||||||
void EliminatePointerRecurrence(PHINode *PN, BasicBlock *Preheader,
|
void EliminatePointerRecurrence(PHINode *PN, BasicBlock *Preheader,
|
||||||
SmallPtrSet<Instruction*, 16> &DeadInsts);
|
SmallPtrSet<Instruction*, 16> &DeadInsts);
|
||||||
void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount,
|
void LinearFunctionTestReplace(Loop *L, SCEVHandle IterationCount,
|
||||||
@ -411,16 +413,13 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L, SCEV *IterationCount) {
|
|||||||
DeleteTriviallyDeadInstructions(InstructionsToDelete);
|
DeleteTriviallyDeadInstructions(InstructionsToDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IndVarSimplify::doInitialization(Loop *L, LPPassManager &LPM) {
|
void IndVarSimplify::RewriteNonIntegerIVs(Loop *L) {
|
||||||
|
|
||||||
Changed = false;
|
|
||||||
// First step. Check to see if there are any trivial GEP pointer recurrences.
|
// First step. Check to see if there are any trivial GEP pointer recurrences.
|
||||||
// If there are, change them into integer recurrences, permitting analysis by
|
// If there are, change them into integer recurrences, permitting analysis by
|
||||||
// the SCEV routines.
|
// the SCEV routines.
|
||||||
//
|
//
|
||||||
BasicBlock *Header = L->getHeader();
|
BasicBlock *Header = L->getHeader();
|
||||||
BasicBlock *Preheader = L->getLoopPreheader();
|
BasicBlock *Preheader = L->getLoopPreheader();
|
||||||
SE = &LPM.getAnalysis<ScalarEvolution>();
|
|
||||||
|
|
||||||
SmallPtrSet<Instruction*, 16> DeadInsts;
|
SmallPtrSet<Instruction*, 16> DeadInsts;
|
||||||
for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
|
for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
|
||||||
@ -431,10 +430,14 @@ bool IndVarSimplify::doInitialization(Loop *L, LPPassManager &LPM) {
|
|||||||
HandleFloatingPointIV(L, PN, DeadInsts);
|
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())
|
if (!DeadInsts.empty())
|
||||||
DeleteTriviallyDeadInstructions(DeadInsts);
|
DeleteTriviallyDeadInstructions(DeadInsts);
|
||||||
|
|
||||||
return Changed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// getEffectiveIndvarType - Determine the widest type that the
|
/// getEffectiveIndvarType - Determine the widest type that the
|
||||||
@ -594,8 +597,12 @@ static void TestOrigIVForWrap(const Loop *L,
|
|||||||
bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
|
bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
|
||||||
LI = &getAnalysis<LoopInfo>();
|
LI = &getAnalysis<LoopInfo>();
|
||||||
SE = &getAnalysis<ScalarEvolution>();
|
SE = &getAnalysis<ScalarEvolution>();
|
||||||
|
|
||||||
Changed = false;
|
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 *Header = L->getHeader();
|
||||||
BasicBlock *ExitingBlock = L->getExitingBlock();
|
BasicBlock *ExitingBlock = L->getExitingBlock();
|
||||||
SmallPtrSet<Instruction*, 16> DeadInsts;
|
SmallPtrSet<Instruction*, 16> DeadInsts;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user