//
//===----------------------------------------------------------------------===//
-#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/ScalarEvolutionExpander.h"
+#include "llvm/Analysis/LoopInfo.h"
using namespace llvm;
/// InsertCastOfTo - Insert a cast of V to the specified type, doing what
/// we can to share the casts.
-Value *SCEVExpander::InsertCastOfTo(Value *V, const Type *Ty) {
+Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
+ const Type *Ty) {
// FIXME: keep track of the cast instruction.
if (Constant *C = dyn_cast<Constant>(V))
- return ConstantExpr::getCast(C, Ty);
+ return ConstantExpr::getCast(opcode, C, Ty);
if (Argument *A = dyn_cast<Argument>(V)) {
// Check to see if there is already a cast!
UI != E; ++UI) {
if ((*UI)->getType() == Ty)
if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI))) {
- // If the cast isn't in the first instruction of the function,
- // move it.
+ // If the cast isn't the first instruction of the function, move it.
if (BasicBlock::iterator(CI) !=
A->getParent()->getEntryBlock().begin()) {
CI->moveBefore(A->getParent()->getEntryBlock().begin());
return CI;
}
}
- return new CastInst(V, Ty, V->getName(),
- A->getParent()->getEntryBlock().begin());
+ return CastInst::create(opcode, V, Ty, V->getName(),
+ A->getParent()->getEntryBlock().begin());
}
Instruction *I = cast<Instruction>(V);
if (InvokeInst *II = dyn_cast<InvokeInst>(I))
IP = II->getNormalDest()->begin();
while (isa<PHINode>(IP)) ++IP;
- return new CastInst(V, Ty, V->getName(), IP);
+ return CastInst::create(opcode, V, Ty, V->getName(), IP);
}
Value *SCEVExpander::visitMulExpr(SCEVMulExpr *S) {
const Type *Ty = S->getType();
const Loop *L = S->getLoop();
// We cannot yet do fp recurrences, e.g. the xform of {X,+,F} --> X+{0,+,F}
- assert(Ty->isIntegral() && "Cannot expand fp recurrences yet!");
+ assert(Ty->isInteger() && "Cannot expand fp recurrences yet!");
// {X,+,F} --> X + {0,+,F}
if (!isa<SCEVConstant>(S->getStart()) ||
// Insert a unit add instruction right before the terminator corresponding
// to the back-edge.
- Constant *One = Ty->isFloatingPoint() ? (Constant*)ConstantFP::get(Ty, 1.0)
- : ConstantInt::get(Ty, 1);
+ Constant *One = ConstantInt::get(Ty, 1);
Instruction *Add = BinaryOperator::createAdd(PN, One, "indvar.next",
(*HPI)->getTerminator());
Value *F = expandInTy(S->getOperand(1), Ty);
// IF the step is by one, just return the inserted IV.
- if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(F))
- if (CI->getRawValue() == 1)
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(F))
+ if (CI->getZExtValue() == 1)
return I;
// If the insert point is directly inside of the loop, emit the multiply at
SCEVHandle IH = SCEVUnknown::get(I); // Get I as a "symbolic" SCEV.
SCEVHandle V = S->evaluateAtIteration(IH);
- //std::cerr << "Evaluated: " << *this << "\n to: " << *V << "\n";
+ //cerr << "Evaluated: " << *this << "\n to: " << *V << "\n";
return expandInTy(V, Ty);
}