diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-12-13 08:06:42 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-12-13 08:06:42 +0000 |
commit | 3ba68b9eef2851dae8a9d1b18928c6fa2e3c5f87 (patch) | |
tree | 8b8521028d0a0ea0de252022ee0350c3c843ea1d /include/llvm | |
parent | dccd9fe161135bffd3fddf0091f8e8efd4fd259b (diff) | |
download | external_llvm-3ba68b9eef2851dae8a9d1b18928c6fa2e3c5f87.zip external_llvm-3ba68b9eef2851dae8a9d1b18928c6fa2e3c5f87.tar.gz external_llvm-3ba68b9eef2851dae8a9d1b18928c6fa2e3c5f87.tar.bz2 |
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
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/Analysis/ScalarEvolutionExpander.h | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/include/llvm/Analysis/ScalarEvolutionExpander.h b/include/llvm/Analysis/ScalarEvolutionExpander.h index c3ea383..80e0a9d 100644 --- a/include/llvm/Analysis/ScalarEvolutionExpander.h +++ b/include/llvm/Analysis/ScalarEvolutionExpander.h @@ -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); } |