mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-28 23:43:50 +00:00
Remove the SCEV::expandCodeFor method, add a new SCEVVisitor class.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13133 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f4789e6d04
commit
2cdf0a7a32
@ -31,7 +31,6 @@ namespace llvm {
|
||||
class Loop;
|
||||
class LoopInfo;
|
||||
class SCEVHandle;
|
||||
class ScalarEvolutionRewriter;
|
||||
|
||||
/// SCEV - This class represent an analyzed expression in the program. These
|
||||
/// are reference counted opaque objects that the client is not allowed to
|
||||
@ -75,13 +74,6 @@ namespace llvm {
|
||||
///
|
||||
virtual const Type *getType() const = 0;
|
||||
|
||||
/// expandCodeFor - Given a rewriter object, expand this SCEV into a closed
|
||||
/// form expression and return a Value corresponding to the expression in
|
||||
/// question.
|
||||
virtual Value *expandCodeFor(ScalarEvolutionRewriter &SER,
|
||||
Instruction *InsertPt) = 0;
|
||||
|
||||
|
||||
/// print - Print out the internal representation of this scalar to the
|
||||
/// specified stream. This should really only be used for debugging
|
||||
/// purposes.
|
||||
@ -109,7 +101,6 @@ namespace llvm {
|
||||
virtual bool isLoopInvariant(const Loop *L) const;
|
||||
virtual const Type *getType() const;
|
||||
virtual bool hasComputableLoopEvolution(const Loop *L) const;
|
||||
virtual Value *expandCodeFor(ScalarEvolutionRewriter &, Instruction *);
|
||||
virtual void print(std::ostream &OS) const;
|
||||
|
||||
|
||||
@ -219,54 +210,6 @@ namespace llvm {
|
||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
||||
virtual void print(std::ostream &OS) const;
|
||||
};
|
||||
|
||||
/// ScalarEvolutionRewriter - This class uses information about analyze
|
||||
/// scalars to rewrite expressions in canonical form. This can be used for
|
||||
/// induction variable substitution, strength reduction, or loop exit value
|
||||
/// replacement.
|
||||
///
|
||||
/// Clients should create an instance of this class when rewriting is needed,
|
||||
/// and destroying it when finished to allow the release of the associated
|
||||
/// memory.
|
||||
class ScalarEvolutionRewriter {
|
||||
ScalarEvolution &SE;
|
||||
LoopInfo &LI;
|
||||
std::map<SCEVHandle, Value*> InsertedExpressions;
|
||||
std::set<Instruction*> InsertedInstructions;
|
||||
public:
|
||||
ScalarEvolutionRewriter(ScalarEvolution &se, LoopInfo &li)
|
||||
: SE(se), LI(li) {}
|
||||
|
||||
/// isInsertedInstruction - Return true if the specified instruction was
|
||||
/// inserted by the code rewriter. If so, the client should not modify the
|
||||
/// instruction.
|
||||
bool isInsertedInstruction(Instruction *I) const {
|
||||
return InsertedInstructions.count(I);
|
||||
}
|
||||
|
||||
/// GetOrInsertCanonicalInductionVariable - This method returns the
|
||||
/// canonical induction variable of the specified type for the specified
|
||||
/// loop (inserts one if there is none). A canonical induction variable
|
||||
/// starts at zero and steps by one on each iteration.
|
||||
Value *GetOrInsertCanonicalInductionVariable(const Loop *L, const Type *Ty);
|
||||
|
||||
|
||||
/// addInsertedValue - Remember the specified instruction as being the
|
||||
/// canonical form for the specified SCEV.
|
||||
void addInsertedValue(Instruction *I, SCEV *S) {
|
||||
InsertedExpressions[S] = (Value*)I;
|
||||
InsertedInstructions.insert(I);
|
||||
}
|
||||
|
||||
/// ExpandCodeFor - Insert code to directly compute the specified SCEV
|
||||
/// expression into the program. The inserted code is inserted into the
|
||||
/// specified block.
|
||||
///
|
||||
/// If a particular value sign is required, a type may be specified for the
|
||||
/// result.
|
||||
Value *ExpandCodeFor(SCEVHandle SH, Instruction *InsertPt,
|
||||
const Type *Ty = 0);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -56,11 +56,6 @@ namespace llvm {
|
||||
|
||||
virtual const Type *getType() const;
|
||||
|
||||
Value *expandCodeFor(ScalarEvolutionRewriter &SER,
|
||||
Instruction *InsertPt) {
|
||||
return (Value*)getValue();
|
||||
}
|
||||
|
||||
virtual void print(std::ostream &OS) const;
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
@ -99,9 +94,6 @@ namespace llvm {
|
||||
/// known to have. This method is only valid on integer SCEV objects.
|
||||
virtual ConstantRange getValueRange() const;
|
||||
|
||||
Value *expandCodeFor(ScalarEvolutionRewriter &SER,
|
||||
Instruction *InsertPt);
|
||||
|
||||
virtual void print(std::ostream &OS) const;
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
@ -140,9 +132,6 @@ namespace llvm {
|
||||
/// known to have. This method is only valid on integer SCEV objects.
|
||||
virtual ConstantRange getValueRange() const;
|
||||
|
||||
Value *expandCodeFor(ScalarEvolutionRewriter &SER,
|
||||
Instruction *InsertPt);
|
||||
|
||||
virtual void print(std::ostream &OS) const;
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
@ -236,9 +225,6 @@ namespace llvm {
|
||||
|
||||
virtual const char *getOperationStr() const { return " + "; }
|
||||
|
||||
Value *expandCodeFor(ScalarEvolutionRewriter &SER,
|
||||
Instruction *InsertPt);
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
static inline bool classof(const SCEVAddExpr *S) { return true; }
|
||||
static inline bool classof(const SCEV *S) {
|
||||
@ -266,9 +252,6 @@ namespace llvm {
|
||||
|
||||
virtual const char *getOperationStr() const { return " * "; }
|
||||
|
||||
Value *expandCodeFor(ScalarEvolutionRewriter &SER,
|
||||
Instruction *InsertPt);
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
static inline bool classof(const SCEVMulExpr *S) { return true; }
|
||||
static inline bool classof(const SCEV *S) {
|
||||
@ -305,9 +288,6 @@ namespace llvm {
|
||||
|
||||
virtual const Type *getType() const;
|
||||
|
||||
Value *expandCodeFor(ScalarEvolutionRewriter &SER,
|
||||
Instruction *InsertPt);
|
||||
|
||||
void print(std::ostream &OS) const;
|
||||
|
||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||
@ -376,10 +356,6 @@ namespace llvm {
|
||||
|
||||
virtual const Type *getType() const { return Operands[0]->getType(); }
|
||||
|
||||
Value *expandCodeFor(ScalarEvolutionRewriter &SER,
|
||||
Instruction *InsertPt);
|
||||
|
||||
|
||||
/// isAffine - Return true if this is an affine AddRec (i.e., it represents
|
||||
/// an expressions A+B*x where A and B are loop invariant values.
|
||||
bool isAffine() const {
|
||||
@ -433,12 +409,11 @@ namespace llvm {
|
||||
/// SCEVUnknown.
|
||||
static SCEVHandle get(Value *V);
|
||||
|
||||
Value *getValue() const { return V; }
|
||||
/// getIntegerSCEV - Given an integer or FP type, create a constant for the
|
||||
/// specified signed integer value and return a SCEV for the constant.
|
||||
static SCEVHandle getIntegerSCEV(int Val, const Type *Ty);
|
||||
|
||||
Value *expandCodeFor(ScalarEvolutionRewriter &SER,
|
||||
Instruction *InsertPt) {
|
||||
return V;
|
||||
}
|
||||
Value *getValue() const { return V; }
|
||||
|
||||
virtual bool isLoopInvariant(const Loop *L) const;
|
||||
virtual bool hasComputableLoopEvolution(const Loop *QL) const {
|
||||
@ -455,6 +430,42 @@ namespace llvm {
|
||||
return S->getSCEVType() == scUnknown;
|
||||
}
|
||||
};
|
||||
|
||||
/// SCEVVisitor - This class defines a simple visitor class that may be used
|
||||
/// for various SCEV analysis purposes.
|
||||
template<typename SC, typename RetVal=void>
|
||||
struct SCEVVisitor {
|
||||
RetVal visit(SCEV *S) {
|
||||
switch (S->getSCEVType()) {
|
||||
case scConstant:
|
||||
return ((SC*)this)->visitConstant((SCEVConstant*)S);
|
||||
case scTruncate:
|
||||
return ((SC*)this)->visitTruncateExpr((SCEVTruncateExpr*)S);
|
||||
case scZeroExtend:
|
||||
return ((SC*)this)->visitZeroExtendExpr((SCEVZeroExtendExpr*)S);
|
||||
case scAddExpr:
|
||||
return ((SC*)this)->visitAddExpr((SCEVAddExpr*)S);
|
||||
case scMulExpr:
|
||||
return ((SC*)this)->visitMulExpr((SCEVMulExpr*)S);
|
||||
case scUDivExpr:
|
||||
return ((SC*)this)->visitUDivExpr((SCEVUDivExpr*)S);
|
||||
case scAddRecExpr:
|
||||
return ((SC*)this)->visitAddRecExpr((SCEVAddRecExpr*)S);
|
||||
case scUnknown:
|
||||
return ((SC*)this)->visitUnknown((SCEVUnknown*)S);
|
||||
case scCouldNotCompute:
|
||||
return ((SC*)this)->visitCouldNotCompute((SCEVCouldNotCompute*)S);
|
||||
default:
|
||||
assert(0 && "Unknown SCEV type!");
|
||||
}
|
||||
}
|
||||
|
||||
RetVal visitCouldNotCompute(SCEVCouldNotCompute *S) {
|
||||
assert(0 && "Invalid use of SCEVCouldNotCompute!");
|
||||
abort();
|
||||
return RetVal();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user