Change the interface to SCEVExpander::InsertCastOfTo to take a cast opcode

so the decision of which opcode to use is pushed upward to the caller.
Adjust the callers to pass the expected opcode.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32535 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer
2006-12-13 08:06:42 +00:00
parent dccd9fe161
commit 3ba68b9eef
3 changed files with 40 additions and 35 deletions

View File

@@ -88,7 +88,8 @@ namespace llvm {
/// InsertCastOfTo - Insert a cast of V to the specified type, doing what
/// we can to share the casts.
static Value *InsertCastOfTo(Value *V, const Type *Ty);
static Value *InsertCastOfTo(Instruction::CastOps opcode, Value *V,
const Type *Ty);
protected:
Value *expand(SCEV *S) {
@@ -104,8 +105,20 @@ namespace llvm {
Value *expandInTy(SCEV *S, const Type *Ty) {
Value *V = expand(S);
if (Ty && V->getType() != Ty)
return InsertCastOfTo(V, Ty);
if (Ty && V->getType() != Ty) {
if (isa<PointerType>(Ty) && V->getType()->isInteger())
return InsertCastOfTo(Instruction::IntToPtr, V, Ty);
else if (Ty->isInteger() && isa<PointerType>(V->getType()))
return InsertCastOfTo(Instruction::PtrToInt, V, Ty);
else if (Ty->getPrimitiveSizeInBits() ==
V->getType()->getPrimitiveSizeInBits())
return InsertCastOfTo(Instruction::BitCast, V, Ty);
else if (Ty->getPrimitiveSizeInBits() >
V->getType()->getPrimitiveSizeInBits())
return InsertCastOfTo(Instruction::ZExt, V, Ty);
else
return InsertCastOfTo(Instruction::Trunc, V, Ty);
}
return V;
}
@@ -119,7 +132,7 @@ namespace llvm {
}
Value *visitZeroExtendExpr(SCEVZeroExtendExpr *S) {
Value *V = expandInTy(S->getOperand(),S->getType()->getUnsignedVersion());
Value *V = expandInTy(S->getOperand(), S->getType());
return CastInst::createZExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
}