1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

add ScevApplyRewriter

llvm-svn: 175294
This commit is contained in:
Sebastian Pop 2013-02-15 20:55:36 +00:00
parent de5fdbd414
commit dcd2e49372

View File

@ -652,6 +652,45 @@ namespace llvm {
ValueToValueMap ⤅
};
typedef DenseMap<const Loop*, const SCEV*> LoopToScevMapT;
/// The ScevApplyRewriter takes a scalar evolution expression and applies
/// the Map (Loop -> SCEV) to all AddRecExprs.
struct ScevApplyRewriter: public ScevRewriter {
public:
static const SCEV *rewrite(const SCEV *Scev, LoopToScevMapT &Map,
ScalarEvolution &SE) {
ScevApplyRewriter Rewriter(SE, Map);
return Rewriter.visit(Scev);
}
ScevApplyRewriter(ScalarEvolution &S, LoopToScevMapT &M)
: ScevRewriter(S), Map(M) {}
virtual const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
SmallVector<const SCEV *, 2> Operands;
for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
Operands.push_back(visit(Expr->getOperand(i)));
const Loop *L = Expr->getLoop();
const SCEV *Res = SE.getAddRecExpr(Operands, L, Expr->getNoWrapFlags());
if (0 == Map.count(L))
return Res;
const SCEVAddRecExpr *Rec = (const SCEVAddRecExpr *) Res;
return Rec->evaluateAtIteration(Map[L], SE);
}
private:
LoopToScevMapT &Map;
};
/// Applies the Map (Loop -> SCEV) to the given Scev.
static inline const SCEV *apply(const SCEV *Scev, LoopToScevMapT &Map,
ScalarEvolution &SE) {
return ScevApplyRewriter::rewrite(Scev, Map, SE);
}
}
#endif