aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-12-13 00:50:17 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-12-13 00:50:17 +0000
commit7b06bd532d3324a2f76bbc856ae20ff89d8e0e92 (patch)
treecbd629912f00b8d9d35e320842aca7e1cded803e /lib
parent31b628ba6096d2b0bb5591b1231a8e4df4f6c8b8 (diff)
downloadexternal_llvm-7b06bd532d3324a2f76bbc856ae20ff89d8e0e92.zip
external_llvm-7b06bd532d3324a2f76bbc856ae20ff89d8e0e92.tar.gz
external_llvm-7b06bd532d3324a2f76bbc856ae20ff89d8e0e92.tar.bz2
Replace CastInst::createInferredCast calls with more accurate cast
creation calls. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32521 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp10
-rw-r--r--lib/Transforms/IPO/IndMemRemoval.cpp4
-rw-r--r--lib/Transforms/IPO/RaiseAllocations.cpp8
-rw-r--r--lib/Transforms/IPO/SimplifyLibCalls.cpp55
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.cpp1
-rw-r--r--lib/Transforms/Instrumentation/TraceValues.cpp4
-rw-r--r--lib/Transforms/LevelRaise.cpp4
-rw-r--r--lib/Transforms/Scalar/LowerGC.cpp3
-rw-r--r--lib/Transforms/Utils/LowerAllocations.cpp17
9 files changed, 54 insertions, 52 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index c112b87..f3ae248 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -3519,8 +3519,8 @@ static bool OptimizeNoopCopyExpression(CastInst *CI) {
while (isa<PHINode>(InsertPt)) ++InsertPt;
InsertedCast =
- CastInst::createInferredCast(CI->getOperand(0), CI->getType(), "",
- InsertPt);
+ CastInst::create(CI->getOpcode(), CI->getOperand(0), CI->getType(), "",
+ InsertPt);
MadeChange = true;
}
@@ -3559,8 +3559,8 @@ static Instruction *InsertGEPComputeCode(Instruction *&V, BasicBlock *BB,
// operand).
if (CastInst *CI = dyn_cast<CastInst>(Ptr))
if (CI->getParent() != BB && isa<PointerType>(CI->getOperand(0)->getType()))
- Ptr = CastInst::createInferredCast(CI->getOperand(0), CI->getType(), "",
- InsertPt);
+ Ptr = CastInst::create(CI->getOpcode(), CI->getOperand(0), CI->getType(),
+ "", InsertPt);
// Add the offset, cast it to the right type.
Ptr = BinaryOperator::createAdd(Ptr, PtrOffset, "", InsertPt);
@@ -3702,7 +3702,7 @@ static bool OptimizeGEPExpression(GetElementPtrInst *GEPI,
// Ptr = Ptr + Idx * ElementSize;
// Cast Idx to UIntPtrTy if needed.
- Idx = CastInst::createInferredCast(Idx, UIntPtrTy, "", GEPI);
+ Idx = CastInst::createIntegerCast(Idx, UIntPtrTy, true/*SExt*/, "", GEPI);
uint64_t ElementSize = TD->getTypeSize(Ty);
// Mask off bits that should not be set.
diff --git a/lib/Transforms/IPO/IndMemRemoval.cpp b/lib/Transforms/IPO/IndMemRemoval.cpp
index 9d3c147..9ad25dd 100644
--- a/lib/Transforms/IPO/IndMemRemoval.cpp
+++ b/lib/Transforms/IPO/IndMemRemoval.cpp
@@ -74,8 +74,8 @@ bool IndMemRemPass::runOnModule(Module &M) {
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;
diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp
index 77a9a3d..46c6815 100644
--- a/lib/Transforms/IPO/RaiseAllocations.cpp
+++ b/lib/Transforms/IPO/RaiseAllocations.cpp
@@ -141,8 +141,8 @@ bool RaiseAllocations::runOnModule(Module &M) {
// 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 @@ bool RaiseAllocations::runOnModule(Module &M) {
//
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
diff --git a/lib/Transforms/IPO/SimplifyLibCalls.cpp b/lib/Transforms/IPO/SimplifyLibCalls.cpp
index f989d1d..8f2b94d 100644
--- a/lib/Transforms/IPO/SimplifyLibCalls.cpp
+++ b/lib/Transforms/IPO/SimplifyLibCalls.cpp
@@ -1009,7 +1009,8 @@ struct memcmpOptimization : public LibCallOptimization {
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 @@ struct memcmpOptimization : public LibCallOptimization {
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 @@ struct LLVMMemSetOptimization : public LibCallOptimization {
}
// 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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
// 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 @@ public:
}
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 @@ public:
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 @@ public:
}
// 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 @@ public:
// 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 @@ public:
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 @@ bool getConstantStringLength(Value *V, uint64_t &len, ConstantArray **CA) {
/// 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;
}
diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
index 887de5b..274275a 100644
--- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp
+++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp
@@ -67,6 +67,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
} else {
InitCall->setOperand(2, AI);
}
+ /* FALL THROUGH */
case 1:
AI = MainFn->arg_begin();
diff --git a/lib/Transforms/Instrumentation/TraceValues.cpp b/lib/Transforms/Instrumentation/TraceValues.cpp
index 7451b51..f6048f1 100644
--- a/lib/Transforms/Instrumentation/TraceValues.cpp
+++ b/lib/Transforms/Instrumentation/TraceValues.cpp
@@ -281,7 +281,7 @@ InsertReleaseInst(Value *V, BasicBlock *BB,
const Type *SBP = PointerType::get(Type::SByteTy);
if (V->getType() != SBP) // Cast pointer to be sbyte*
- V = CastInst::createInferredCast(V, SBP, "RPSN_cast", InsertBefore);
+ V = new BitCastInst(V, SBP, "RPSN_cast", InsertBefore);
std::vector<Value*> releaseArgs(1, V);
new CallInst(ReleasePtrFunc, releaseArgs, "", InsertBefore);
@@ -293,7 +293,7 @@ InsertRecordInst(Value *V, BasicBlock *BB,
Function* RecordPtrFunc) {
const Type *SBP = PointerType::get(Type::SByteTy);
if (V->getType() != SBP) // Cast pointer to be sbyte*
- V = CastInst::createInferredCast(V, SBP, "RP_cast", InsertBefore);
+ V = new BitCastInst(V, SBP, "RP_cast", InsertBefore);
std::vector<Value*> releaseArgs(1, V);
new CallInst(RecordPtrFunc, releaseArgs, "", InsertBefore);
diff --git a/lib/Transforms/LevelRaise.cpp b/lib/Transforms/LevelRaise.cpp
index 5662269..c5ac8c9 100644
--- a/lib/Transforms/LevelRaise.cpp
+++ b/lib/Transforms/LevelRaise.cpp
@@ -258,8 +258,8 @@ bool RPR::PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
// The existing and new operand 0 types are different so we must
// replace CI with a new CastInst so that we are assured to
// get the correct cast opcode.
- CastInst *NewCI = CastInst::createInferredCast(
- GEP, CI->getType(), CI->getName(), CI);
+ CastInst *NewCI = new BitCastInst(GEP, CI->getType(),
+ CI->getName(), CI);
CI->replaceAllUsesWith(NewCI);
CI->eraseFromParent();
CI = NewCI;
diff --git a/lib/Transforms/Scalar/LowerGC.cpp b/lib/Transforms/Scalar/LowerGC.cpp
index fdfbf7f..e844213 100644
--- a/lib/Transforms/Scalar/LowerGC.cpp
+++ b/lib/Transforms/Scalar/LowerGC.cpp
@@ -146,8 +146,7 @@ static void Coerce(Instruction *I, unsigned OpNum, Type *Ty) {
if (Constant *C = dyn_cast<Constant>(I->getOperand(OpNum)))
I->setOperand(OpNum, ConstantExpr::getBitCast(C, Ty));
else {
- CastInst *CI =
- CastInst::createInferredCast(I->getOperand(OpNum), Ty, "", I);
+ CastInst *CI = new BitCastInst(I->getOperand(OpNum), Ty, "", I);
I->setOperand(OpNum, CI);
}
}
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp
index d011d75..30b0ab8 100644
--- a/lib/Transforms/Utils/LowerAllocations.cpp
+++ b/lib/Transforms/Utils/LowerAllocations.cpp
@@ -135,7 +135,8 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
} else {
Value *Scale = MI->getOperand(0);
if (Scale->getType() != IntPtrTy)
- Scale = CastInst::createInferredCast(Scale, IntPtrTy, "", I);
+ Scale = CastInst::createIntegerCast(Scale, IntPtrTy, false /*ZExt*/,
+ "", I);
// Multiply it by the array size if necessary...
MallocArg = BinaryOperator::create(Instruction::Mul, Scale,
@@ -149,13 +150,12 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
if (MallocFTy->getNumParams() > 0 || MallocFTy->isVarArg()) {
if (MallocFTy->isVarArg()) {
if (MallocArg->getType() != IntPtrTy)
- MallocArg = CastInst::createInferredCast(MallocArg, IntPtrTy, "",
- I);
+ MallocArg = CastInst::createIntegerCast(MallocArg, IntPtrTy,
+ false /*ZExt*/, "", I);
} else if (MallocFTy->getNumParams() > 0 &&
MallocFTy->getParamType(0) != Type::UIntTy)
- MallocArg =
- CastInst::createInferredCast(MallocArg, MallocFTy->getParamType(0),
- "",I);
+ MallocArg = CastInst::createIntegerCast(
+ MallocArg, MallocFTy->getParamType(0), false/*ZExt*/, "",I);
MallocArgs.push_back(MallocArg);
}
@@ -170,7 +170,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
// Create a cast instruction to convert to the right type...
Value *MCast;
if (MCall->getType() != Type::VoidTy)
- MCast = CastInst::createInferredCast(MCall, MI->getType(), "", I);
+ MCast = new BitCastInst(MCall, MI->getType(), "", I);
else
MCast = Constant::getNullValue(MI->getType());
@@ -187,8 +187,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
Value *MCast = FI->getOperand(0);
if (FreeFTy->getNumParams() > 0 &&
FreeFTy->getParamType(0) != MCast->getType())
- MCast = CastInst::createInferredCast(MCast, FreeFTy->getParamType(0),
- "", I);
+ MCast = new BitCastInst(MCast, FreeFTy->getParamType(0), "", I);
FreeArgs.push_back(MCast);
}