/// expandCodeFor - Insert code to directly compute the specified SCEV
/// expression into the program. The inserted code is inserted into the
/// specified block.
- Value *expandCodeFor(SCEVHandle SH, Instruction *IP) {
- // Expand the code for this SCEV.
- this->InsertPt = IP;
- return expand(SH);
- }
+ Value *expandCodeFor(SCEVHandle SH, Instruction *IP);
/// InsertCastOfTo - Insert a cast of V to the specified type, doing what
/// we can to share the casts.
/// InsertBinop - Insert the specified binary operator, doing a small amount
/// of work to avoid inserting an obviously redundant operation.
static Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,
- Value *RHS, Instruction *&InsertPt);
+ Value *RHS, Instruction *InsertPt);
protected:
Value *expand(SCEV *S);
return S->getValue();
}
- Value *visitTruncateExpr(SCEVTruncateExpr *S) {
- Value *V = expand(S->getOperand());
- return CastInst::CreateTruncOrBitCast(V, S->getType(), "tmp.", InsertPt);
- }
-
- Value *visitZeroExtendExpr(SCEVZeroExtendExpr *S) {
- Value *V = expand(S->getOperand());
- return CastInst::CreateZExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
- }
+ Value *visitTruncateExpr(SCEVTruncateExpr *S);
- Value *visitSignExtendExpr(SCEVSignExtendExpr *S) {
- Value *V = expand(S->getOperand());
- return CastInst::CreateSExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
- }
+ Value *visitZeroExtendExpr(SCEVZeroExtendExpr *S);
- Value *visitAddExpr(SCEVAddExpr *S) {
- Value *V = expand(S->getOperand(S->getNumOperands()-1));
+ Value *visitSignExtendExpr(SCEVSignExtendExpr *S);
- // Emit a bunch of add instructions
- for (int i = S->getNumOperands()-2; i >= 0; --i)
- V = InsertBinop(Instruction::Add, V, expand(S->getOperand(i)),
- InsertPt);
- return V;
- }
+ Value *visitAddExpr(SCEVAddExpr *S);
Value *visitMulExpr(SCEVMulExpr *S);
- Value *visitUDivExpr(SCEVUDivExpr *S) {
- Value *LHS = expand(S->getLHS());
- Value *RHS = expand(S->getRHS());
- return InsertBinop(Instruction::UDiv, LHS, RHS, InsertPt);
- }
+ Value *visitUDivExpr(SCEVUDivExpr *S);
+
+ Value *visitSDivExpr(SCEVSDivExpr *S);
Value *visitAddRecExpr(SCEVAddRecExpr *S);