[llvm-commits] CVS: llvm/lib/Transforms/IPO/IndMemRemoval.cpp RaiseAllocations.cpp SimplifyLibCalls.cpp
Reid Spencer
reid at x10sys.com
Tue Dec 12 16:50:42 PST 2006
Changes in directory llvm/lib/Transforms/IPO:
IndMemRemoval.cpp updated: 1.7 -> 1.8
RaiseAllocations.cpp updated: 1.32 -> 1.33
SimplifyLibCalls.cpp updated: 1.74 -> 1.75
---
Log message:
Replace CastInst::createInferredCast calls with more accurate cast
creation calls.
---
Diffs of the changes: (+35 -32)
IndMemRemoval.cpp | 4 +--
RaiseAllocations.cpp | 8 +++----
SimplifyLibCalls.cpp | 55 ++++++++++++++++++++++++++-------------------------
3 files changed, 35 insertions(+), 32 deletions(-)
Index: llvm/lib/Transforms/IPO/IndMemRemoval.cpp
diff -u llvm/lib/Transforms/IPO/IndMemRemoval.cpp:1.7 llvm/lib/Transforms/IPO/IndMemRemoval.cpp:1.8
--- llvm/lib/Transforms/IPO/IndMemRemoval.cpp:1.7 Wed Dec 6 11:46:32 2006
+++ llvm/lib/Transforms/IPO/IndMemRemoval.cpp Tue Dec 12 18:50:17 2006
@@ -74,8 +74,8 @@
GlobalValue::LinkOnceLinkage,
"malloc_llvm_bounce", &M);
BasicBlock* bb = new BasicBlock("entry",FN);
- Instruction* c =
- CastInst::createInferredCast(FN->arg_begin(), Type::UIntTy, "c", bb);
+ Instruction* c = CastInst::createIntegerCast(
+ FN->arg_begin(), Type::UIntTy, false, "c", bb);
Instruction* a = new MallocInst(Type::SByteTy, c, "m", bb);
new ReturnInst(a, bb);
++NumBounce;
Index: llvm/lib/Transforms/IPO/RaiseAllocations.cpp
diff -u llvm/lib/Transforms/IPO/RaiseAllocations.cpp:1.32 llvm/lib/Transforms/IPO/RaiseAllocations.cpp:1.33
--- llvm/lib/Transforms/IPO/RaiseAllocations.cpp:1.32 Wed Dec 6 11:46:32 2006
+++ llvm/lib/Transforms/IPO/RaiseAllocations.cpp Tue Dec 12 18:50:17 2006
@@ -141,8 +141,8 @@
// source size.
if (Source->getType() != Type::UIntTy)
Source =
- CastInst::createInferredCast(Source, Type::UIntTy,
- "MallocAmtCast", I);
+ CastInst::createIntegerCast(Source, Type::UIntTy, false/*ZExt*/,
+ "MallocAmtCast", I);
std::string Name(I->getName()); I->setName("");
MallocInst *MI = new MallocInst(Type::SByteTy, Source, Name, I);
@@ -193,8 +193,8 @@
//
Value *Source = *CS.arg_begin();
if (!isa<PointerType>(Source->getType()))
- Source = CastInst::createInferredCast(
- Source, PointerType::get(Type::SByteTy), "FreePtrCast", I);
+ Source = new IntToPtrInst(Source, PointerType::get(Type::SByteTy),
+ "FreePtrCast", I);
new FreeInst(Source, I);
// If the old instruction was an invoke, add an unconditional branch
Index: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
diff -u llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.74 llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.75
--- llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.74 Wed Dec 6 11:46:32 2006
+++ llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp Tue Dec 12 18:50:17 2006
@@ -1009,7 +1009,8 @@
Value *S2V = new LoadInst(Op2Cast, RHS->getName()+".val", CI);
Value *RV = BinaryOperator::createSub(S1V, S2V, CI->getName()+".diff",CI);
if (RV->getType() != CI->getType())
- RV = CastInst::createInferredCast(RV, CI->getType(), RV->getName(), CI);
+ RV = CastInst::createIntegerCast(RV, CI->getType(), false,
+ RV->getName(), CI);
CI->replaceAllUsesWith(RV);
CI->eraseFromParent();
return true;
@@ -1037,8 +1038,8 @@
CI->getName()+".d1", CI);
Value *Or = BinaryOperator::createOr(D1, D2, CI->getName()+".res", CI);
if (Or->getType() != CI->getType())
- Or = CastInst::createInferredCast(Or, CI->getType(), Or->getName(),
- CI);
+ Or = CastInst::createIntegerCast(Or, CI->getType(), false /*ZExt*/,
+ Or->getName(), CI);
CI->replaceAllUsesWith(Or);
CI->eraseFromParent();
return true;
@@ -1222,8 +1223,8 @@
}
// Cast dest to the right sized primitive and then load/store
- CastInst* DestCast = CastInst::createInferredCast(
- dest, PointerType::get(castType), dest->getName()+".cast", ci);
+ CastInst* DestCast = new BitCastInst(dest, PointerType::get(castType),
+ dest->getName()+".cast", ci);
new StoreInst(ConstantInt::get(castType,fill_value),DestCast, ci);
ci->eraseFromParent();
return true;
@@ -1365,7 +1366,7 @@
Function* putchar_func = SLC.get_putchar();
if (!putchar_func)
return false;
- CastInst* cast = CastInst::createInferredCast(
+ CastInst* cast = CastInst::createSExtOrBitCast(
ci->getOperand(2), Type::IntTy, CI->getName()+".int", ci);
new CallInst(putchar_func, cast, "", ci);
ci->replaceAllUsesWith(ConstantInt::get(Type::IntTy, 1));
@@ -1499,7 +1500,7 @@
Function* fputc_func = SLC.get_fputc(FILEptr_type);
if (!fputc_func)
return false;
- CastInst* cast = CastInst::createInferredCast(
+ CastInst* cast = CastInst::createSExtOrBitCast(
ci->getOperand(3), Type::IntTy, CI->getName()+".int", ci);
new CallInst(fputc_func,cast,ci->getOperand(1),"",ci);
ci->replaceAllUsesWith(ConstantInt::get(Type::IntTy,1));
@@ -1606,8 +1607,8 @@
ConstantInt::get(Len->getType(), 1),
Len->getName()+"1", ci);
if (Len1->getType() != SLC.getIntPtrType())
- Len1 = CastInst::createInferredCast(
- Len1, SLC.getIntPtrType(), Len1->getName(), ci);
+ Len1 = CastInst::createIntegerCast(Len1, SLC.getIntPtrType(), false,
+ Len1->getName(), ci);
std::vector<Value*> args;
args.push_back(CastToCStr(ci->getOperand(1), *ci));
args.push_back(CastToCStr(ci->getOperand(3), *ci));
@@ -1618,8 +1619,8 @@
// The strlen result is the unincremented number of bytes in the string.
if (!ci->use_empty()) {
if (Len->getType() != ci->getType())
- Len = CastInst::createInferredCast(
- Len, ci->getType(), Len->getName(), ci);
+ Len = CastInst::createIntegerCast(Len, ci->getType(), false,
+ Len->getName(), ci);
ci->replaceAllUsesWith(Len);
}
ci->eraseFromParent();
@@ -1627,7 +1628,7 @@
}
case 'c': {
// sprintf(dest,"%c",chr) -> store chr, dest
- CastInst* cast = CastInst::createInferredCast(
+ CastInst* cast = CastInst::createTruncOrBitCast(
ci->getOperand(3), Type::SByteTy, "char", ci);
new StoreInst(cast, ci->getOperand(1), ci);
GetElementPtrInst* gep = new GetElementPtrInst(ci->getOperand(1),
@@ -1684,8 +1685,8 @@
return false;
LoadInst* loadi = new LoadInst(ci->getOperand(1),
ci->getOperand(1)->getName()+".byte",ci);
- CastInst* casti = CastInst::createInferredCast(
- loadi, Type::IntTy, loadi->getName()+".int", ci);
+ CastInst* casti = new SExtInst(loadi, Type::IntTy,
+ loadi->getName()+".int", ci);
new CallInst(fputc_func,casti,ci->getOperand(2),"",ci);
break;
}
@@ -1738,16 +1739,16 @@
}
// isdigit(c) -> (unsigned)c - '0' <= 9
- CastInst* cast = CastInst::createInferredCast(ci->getOperand(1),
- Type::UIntTy, ci->getOperand(1)->getName()+".uint", ci);
+ CastInst* cast = CastInst::createIntegerCast(ci->getOperand(1),
+ Type::UIntTy, false/*ZExt*/, ci->getOperand(1)->getName()+".uint", ci);
BinaryOperator* sub_inst = BinaryOperator::createSub(cast,
ConstantInt::get(Type::UIntTy,0x30),
ci->getOperand(1)->getName()+".sub",ci);
SetCondInst* setcond_inst = new SetCondInst(Instruction::SetLE,sub_inst,
ConstantInt::get(Type::UIntTy,9),
ci->getOperand(1)->getName()+".cmp",ci);
- CastInst* c2 = CastInst::createInferredCast(
- setcond_inst, Type::IntTy, ci->getOperand(1)->getName()+".isdigit", ci);
+ CastInst* c2 = new SExtInst(setcond_inst, Type::IntTy,
+ ci->getOperand(1)->getName()+".isdigit", ci);
ci->replaceAllUsesWith(c2);
ci->eraseFromParent();
return true;
@@ -1769,14 +1770,13 @@
// isascii(c) -> (unsigned)c < 128
Value *V = CI->getOperand(1);
if (V->getType()->isSigned())
- V = CastInst::createInferredCast(V, V->getType()->getUnsignedVersion(),
- V->getName(), CI);
+ V = new BitCastInst(V, V->getType()->getUnsignedVersion(), V->getName(),
+ CI);
Value *Cmp = BinaryOperator::createSetLT(V, ConstantInt::get(V->getType(),
128),
V->getName()+".isascii", CI);
if (Cmp->getType() != CI->getType())
- Cmp = CastInst::createInferredCast(
- Cmp, CI->getType(), Cmp->getName(), CI);
+ Cmp = new BitCastInst(Cmp, CI->getType(), Cmp->getName(), CI);
CI->replaceAllUsesWith(Cmp);
CI->eraseFromParent();
return true;
@@ -1870,10 +1870,11 @@
Function *F = SLC.getModule()->getOrInsertFunction(CTTZName, ArgType,
ArgType, NULL);
- Value *V = CastInst::createInferredCast(
- TheCall->getOperand(1), ArgType, "tmp", TheCall);
+ Value *V = CastInst::createIntegerCast(TheCall->getOperand(1), ArgType,
+ false/*ZExt*/, "tmp", TheCall);
Value *V2 = new CallInst(F, V, "tmp", TheCall);
- V2 = CastInst::createInferredCast(V2, Type::IntTy, "tmp", TheCall);
+ V2 = CastInst::createIntegerCast(V2, Type::IntTy, true/*SExt*/,
+ "tmp", TheCall);
V2 = BinaryOperator::createAdd(V2, ConstantInt::get(Type::IntTy, 1),
"tmp", TheCall);
Value *Cond =
@@ -2116,9 +2117,11 @@
/// inserting the cast before IP, and return the cast.
/// @brief Cast a value to a "C" string.
Value *CastToCStr(Value *V, Instruction &IP) {
+ assert(V->getType()->getTypeID() == Type::PointerTyID &&
+ "Can't cast non-pointer type to C string type");
const Type *SBPTy = PointerType::get(Type::SByteTy);
if (V->getType() != SBPTy)
- return CastInst::createInferredCast(V, SBPTy, V->getName(), &IP);
+ return new BitCastInst(V, SBPTy, V->getName(), &IP);
return V;
}
More information about the llvm-commits
mailing list