// If we have a scale, apply it first...
if (Expr.Var) {
// Expr.Var is not neccesarily unsigned right now, insert a cast now.
- if (Expr.Var->getType() != Type::UIntTy) {
- Instruction *CI = new CastInst(Expr.Var, Type::UIntTy);
- if (Expr.Var->hasName()) CI->setName(Expr.Var->getName()+"-uint");
- It = ++BB->getInstList().insert(It, CI);
- Expr.Var = CI;
- }
+ if (Expr.Var->getType() != Type::UIntTy)
+ Expr.Var = new CastInst(Expr.Var, Type::UIntTy,
+ Expr.Var->getName()+"-uint", It);
- if (Scale != 1) {
- Instruction *ScI =
- BinaryOperator::create(Instruction::Mul, Expr.Var,
- ConstantUInt::get(Type::UIntTy, Scale));
- if (Expr.Var->hasName()) ScI->setName(Expr.Var->getName()+"-scl");
- It = ++BB->getInstList().insert(It, ScI);
- Expr.Var = ScI;
- }
+ if (Scale != 1)
+ Expr.Var = BinaryOperator::create(Instruction::Mul, Expr.Var,
+ ConstantUInt::get(Type::UIntTy, Scale),
+ Expr.Var->getName()+"-scl", It);
} else {
// If we are not scaling anything, just make the offset be the "var"...
// If we have an offset now, add it in...
if (Offset != 0) {
assert(Expr.Var && "Var must be nonnull by now!");
-
- Instruction *AddI =
- BinaryOperator::create(Instruction::Add, Expr.Var,
- ConstantUInt::get(Type::UIntTy, Offset));
- if (Expr.Var->hasName()) AddI->setName(Expr.Var->getName()+"-off");
- It = ++BB->getInstList().insert(It, AddI);
- Expr.Var = AddI;
+ Expr.Var = BinaryOperator::create(Instruction::Add, Expr.Var,
+ ConstantUInt::get(Type::UIntTy, Offset),
+ Expr.Var->getName()+"-off", It);
}
- Instruction *NewI = new MallocInst(AllocTy, Expr.Var, Name);
-
assert(AllocTy == Ty);
- return NewI;
+ return = new MallocInst(AllocTy, Expr.Var, Name);
}
case Instruction::Add:
case Instruction::Sub:
+ if (!Ty->isInteger() && !Ty->isFloatingPoint()) return false;
if (!ExpressionConvertableToType(I->getOperand(0), Ty, CTMap) ||
!ExpressionConvertableToType(I->getOperand(1), Ty, CTMap))
return false;
BasicBlock *BB = I->getParent();
- BasicBlock::InstListType &BIL = BB->getInstList();
std::string Name = I->getName(); if (!Name.empty()) I->setName("");
Instruction *Res; // Result of conversion
assert(Res->getType() == Ty && "Didn't convert expr to correct type!");
- BIL.insert(I, Res);
+ BB->getInstList().insert(I, Res);
// Add the instruction to the expression map
VMC.ExprMap[I] = Res;
}
// FALLTHROUGH
case Instruction::Sub: {
+ if (!Ty->isInteger() && !Ty->isFloatingPoint()) return false;
+
Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0);
return ValueConvertableToType(I, Ty, CTMap) &&
ExpressionConvertableToType(OtherOp, Ty, CTMap);
BasicBlock *BB = I->getParent();
assert(BB != 0 && "Instruction not embedded in basic block!");
- BasicBlock::InstListType &BIL = BB->getInstList();
std::string Name = I->getName();
I->setName("");
Instruction *Res; // Result of conversion
assert(LoadedTy->isFirstClassType());
if (Indices.size() != 1) { // Do not generate load X, 0
- Src = new GetElementPtrInst(Src, Indices, Name+".idx");
// Insert the GEP instruction before this load.
- BIL.insert(I, cast<Instruction>(Src));
+ Src = new GetElementPtrInst(Src, Indices, Name+".idx", I);
}
}
assert(Offset == 0 && "Offset changed!");
assert(NewTy == Ty && "Did not convert to correct type!");
+ // Insert the GEP instruction before this store.
SrcPtr = new GetElementPtrInst(SrcPtr, Indices,
- SrcPtr->getName()+".idx");
- // Insert the GEP instruction before this load.
- BIL.insert(I, cast<Instruction>(SrcPtr));
+ SrcPtr->getName()+".idx", I);
}
Res = new StoreInst(NewVal, SrcPtr);
assert(Offset == 0 && ValTy);
+ // Insert the GEP instruction before this store.
SrcPtr = new GetElementPtrInst(SrcPtr, Indices,
- SrcPtr->getName()+".idx");
- // Insert the GEP instruction before this load.
- BIL.insert(I, cast<Instruction>(SrcPtr));
+ SrcPtr->getName()+".idx", I);
}
Res = new StoreInst(Constant::getNullValue(ValTy), SrcPtr);
if (DataSize != 1) {
// Insert a multiply of the old element type is not a unit size...
Index = BinaryOperator::create(Instruction::Mul, Index,
- ConstantUInt::get(Type::UIntTy, DataSize));
- It = ++BIL.insert(It, cast<Instruction>(Index));
+ ConstantUInt::get(Type::UIntTy, DataSize),
+ "scale", It);
}
// Perform the conversion now...
// Create a cast to convert it to the right type, we know that this
// is a lossless cast...
//
- Params[i] = new CastInst(Params[i], PTs[i], "call.resolve.cast");
- It = ++BIL.insert(It, cast<Instruction>(Params[i]));
+ Params[i] = new CastInst(Params[i], PTs[i], "call.resolve.cast", It);
}
Meth = NewVal; // Update call destination to new value
// stream.
//
BasicBlock::iterator It = I;
- assert(It != BIL.end() && "Instruction not in own basic block??");
- BIL.insert(It, Res); // Keep It pointing to old instruction
+ assert(It != BB->end() && "Instruction not in own basic block??");
+ BB->getInstList().insert(It, Res); // Keep It pointing to old instruction
DEBUG(cerr << "COT CREATED: " << (void*)Res << " " << Res
<< "In: " << (void*)I << " " << I << "Out: " << (void*)Res