- Value *expandInTy(SCEV *S, const Type *Ty) {
- Value *V = expand(S);
- if (Ty && V->getType() != Ty) {
- // FIXME: keep track of the cast instruction.
- if (Constant *C = dyn_cast<Constant>(V))
- return ConstantExpr::getCast(C, Ty);
- else if (Instruction *I = dyn_cast<Instruction>(V)) {
- // Check to see if there is already a cast. If there is, use it.
- for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
- UI != E; ++UI) {
- if ((*UI)->getType() == Ty)
- if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI))) {
- BasicBlock::iterator It = I; ++It;
- if (isa<InvokeInst>(I))
- It = cast<InvokeInst>(I)->getNormalDest()->begin();
- while (isa<PHINode>(It)) ++It;
- if (It != BasicBlock::iterator(CI)) {
- // Splice the cast immediately after the operand in question.
- BasicBlock::InstListType &InstList =
- It->getParent()->getInstList();
- InstList.splice(It, CI->getParent()->getInstList(), CI);
- }
- return CI;
- }
- }
- BasicBlock::iterator IP = I; ++IP;
- if (InvokeInst *II = dyn_cast<InvokeInst>(I))
- IP = II->getNormalDest()->begin();
- while (isa<PHINode>(IP)) ++IP;
- return new CastInst(V, Ty, V->getName(), IP);
- } else {
- // FIXME: check to see if there is already a cast!
- return new CastInst(V, Ty, V->getName(), InsertPt);
- }
- }
- return V;
- }
+ /// InsertBinop - Insert the specified binary operator, doing a small amount
+ /// of work to avoid inserting an obviously redundant operation.
+ Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,
+ Value *RHS, BasicBlock::iterator InsertPt);
+
+ private:
+ /// expandAddToGEP - Expand a SCEVAddExpr with a pointer type into a GEP
+ /// instead of using ptrtoint+arithmetic+inttoptr.
+ Value *expandAddToGEP(const SCEV* const *op_begin,
+ const SCEV* const *op_end,
+ const PointerType *PTy, const Type *Ty, Value *V);