Instead of eagerly creating new SCEVs to replace all SCEVs that are

affected after a PHI node has been analyzed, just remove affected
SCEVs from the Scalars map, so that they'll be (lazily) recreated as
needed. This avoids creating SCEV objects that aren't actually needed.

Also, rewrite the associated def-use walking code to be non-recursive
and to continue traversing past Instructions that don't have an
entry in the Scalars map.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77032 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2009-07-25 01:13:03 +00:00
parent b140f4907c
commit fef8bb24de
3 changed files with 84 additions and 178 deletions

View File

@@ -96,15 +96,9 @@ namespace llvm {
///
bool isAllOnesValue() const;
/// replaceSymbolicValuesWithConcrete - If this SCEV internally references
/// the symbolic value "Sym", construct and return a new SCEV that produces
/// the same value, but which uses the concrete value Conc instead of the
/// symbolic value. If this SCEV does not use the symbolic value, it
/// returns itself.
virtual const SCEV *
replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const = 0;
/// hasOperand - Test whether this SCEV has Op as a direct or
/// indirect operand.
virtual bool hasOperand(const SCEV *Op) const = 0;
/// dominates - Return true if elements that makes up this SCEV dominates
/// the specified basic block.
@@ -145,10 +139,7 @@ namespace llvm {
virtual const Type *getType() const;
virtual bool hasComputableLoopEvolution(const Loop *L) const;
virtual void print(raw_ostream &OS) const;
virtual const SCEV *
replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const;
virtual bool hasOperand(const SCEV *Op) const;
virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const {
return true;
@@ -252,13 +243,11 @@ namespace llvm {
/// SCEVs.
const SCEV *createNodeForGEP(Operator *GEP);
/// ReplaceSymbolicValueWithConcrete - This looks up the computed SCEV value
/// for the specified instruction and replaces any references to the
/// symbolic value SymName with the specified value. This is used during
/// PHI resolution.
void ReplaceSymbolicValueWithConcrete(Instruction *I,
const SCEV *SymName,
const SCEV *NewVal);
/// ForgetSymbolicValue - This looks up computed SCEV values for all
/// instructions that depend on the given instruction and removes them from
/// the Scalars map if they reference SymName. This is used during PHI
/// resolution.
void ForgetSymbolicName(Instruction *I, const SCEV *SymName);
/// getBECount - Subtract the end and start values and divide by the step,
/// rounding up, to get the number of times the backedge is executed. Return

View File

@@ -52,10 +52,8 @@ namespace llvm {
virtual const Type *getType() const;
const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const {
return this;
virtual bool hasOperand(const SCEV *) const {
return false;
}
bool dominates(BasicBlock *BB, DominatorTree *DT) const {
@@ -94,6 +92,10 @@ namespace llvm {
return Op->hasComputableLoopEvolution(L);
}
virtual bool hasOperand(const SCEV *O) const {
return Op == O || Op->hasOperand(O);
}
virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -116,15 +118,6 @@ namespace llvm {
const SCEV *op, const Type *ty);
public:
const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const {
const SCEV *H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
if (H == Op)
return this;
return SE.getTruncateExpr(H, Ty);
}
virtual void print(raw_ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -145,15 +138,6 @@ namespace llvm {
const SCEV *op, const Type *ty);
public:
const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const {
const SCEV *H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
if (H == Op)
return this;
return SE.getZeroExtendExpr(H, Ty);
}
virtual void print(raw_ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -174,15 +158,6 @@ namespace llvm {
const SCEV *op, const Type *ty);
public:
const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const {
const SCEV *H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
if (H == Op)
return this;
return SE.getSignExtendExpr(H, Ty);
}
virtual void print(raw_ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -240,6 +215,13 @@ namespace llvm {
return HasVarying;
}
virtual bool hasOperand(const SCEV *O) const {
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
if (O == getOperand(i) || getOperand(i)->hasOperand(O))
return true;
return false;
}
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
virtual const Type *getType() const { return getOperand(0)->getType(); }
@@ -267,10 +249,6 @@ namespace llvm {
: SCEVNAryExpr(ID, T, ops) {}
public:
const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const;
virtual const char *getOperationStr() const = 0;
virtual void print(raw_ostream &OS) const;
@@ -353,15 +331,8 @@ namespace llvm {
RHS->hasComputableLoopEvolution(L);
}
const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const {
const SCEV *L = LHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
const SCEV *R = RHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
if (L == LHS && R == RHS)
return this;
else
return SE.getUDivExpr(L, R);
virtual bool hasOperand(const SCEV *O) const {
return O == LHS || O == RHS || LHS->hasOperand(O) || RHS->hasOperand(O);
}
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
@@ -449,14 +420,10 @@ namespace llvm {
const SCEV *getNumIterationsInRange(ConstantRange Range,
ScalarEvolution &SE) const;
const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const;
/// getPostIncExpr - Return an expression representing the value of
/// this expression one iteration of the loop ahead.
const SCEV *getPostIncExpr(ScalarEvolution &SE) const {
return SE.getAddExpr(this, getStepRecurrence(SE));
const SCEVAddRecExpr *getPostIncExpr(ScalarEvolution &SE) const {
return cast<SCEVAddRecExpr>(SE.getAddExpr(this, getStepRecurrence(SE)));
}
bool hasNoUnsignedOverflow() const { return SubclassData & (1 << 0); }
@@ -542,11 +509,8 @@ namespace llvm {
return false; // not computable
}
const SCEV *replaceSymbolicValuesWithConcrete(const SCEV *Sym,
const SCEV *Conc,
ScalarEvolution &SE) const {
if (&*Sym == this) return Conc;
return this;
virtual bool hasOperand(const SCEV *) const {
return false;
}
bool dominates(BasicBlock *BB, DominatorTree *DT) const;