diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2006-12-04 02:43:42 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2006-12-04 02:43:42 +0000 |
commit | 56667123b7f6d6dda8b4dc178c8be4192299ae6e (patch) | |
tree | 386731b0cf2ae8a98fe44112a9d0d7f438536664 /lib/VMCore/Instructions.cpp | |
parent | 75575fcfe453fb1c8352e085f17ebba32bc809ba (diff) | |
download | external_llvm-56667123b7f6d6dda8b4dc178c8be4192299ae6e.zip external_llvm-56667123b7f6d6dda8b4dc178c8be4192299ae6e.tar.gz external_llvm-56667123b7f6d6dda8b4dc178c8be4192299ae6e.tar.bz2 |
Take a baby step towards getting rid of inferred casts. Provide methods on
CastInst and ConstantExpr that allow the signedness to be explicitly passed
in and reliance on signedness removed from getCastOpcode. These are
temporary measures useful during the conversion of inferred casts.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32164 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Instructions.cpp')
-rw-r--r-- | lib/VMCore/Instructions.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index f486642..de1ebce 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1507,7 +1507,8 @@ CastInst *CastInst::create(Instruction::CastOps op, Value *S, const Type *Ty, // should not assert in checkCast. In other words, this produces a "correct" // casting opcode for the arguments passed to it. Instruction::CastOps -CastInst::getCastOpcode(const Value *Src, const Type *DestTy) { +CastInst::getCastOpcode( + const Value *Src, bool SrcIsSigned, const Type *DestTy, bool DestIsSigned) { // Get the bit sizes, we'll need these const Type *SrcTy = Src->getType(); unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr/packed @@ -1519,7 +1520,7 @@ CastInst::getCastOpcode(const Value *Src, const Type *DestTy) { if (DestBits < SrcBits) return Trunc; // int -> smaller int else if (DestBits > SrcBits) { // its an extension - if (SrcTy->isSigned()) + if (SrcIsSigned) return SExt; // signed -> SEXT else return ZExt; // unsigned -> ZEXT @@ -1527,7 +1528,7 @@ CastInst::getCastOpcode(const Value *Src, const Type *DestTy) { return BitCast; // Same size, No-op cast } } else if (SrcTy->isFloatingPoint()) { // Casting from floating pt - if (DestTy->isSigned()) + if (DestIsSigned) return FPToSI; // FP -> sint else return FPToUI; // FP -> uint @@ -1542,7 +1543,7 @@ CastInst::getCastOpcode(const Value *Src, const Type *DestTy) { } } else if (DestTy->isFloatingPoint()) { // Casting to floating pt if (SrcTy->isIntegral()) { // Casting from integral - if (SrcTy->isSigned()) + if (SrcIsSigned) return SIToFP; // sint -> FP else return UIToFP; // uint -> FP @@ -1649,6 +1650,20 @@ checkCast(Instruction::CastOps op, Value *S, const Type *DstTy) { } } +CastInst *CastInst::createInferredCast( + Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore) +{ + return createInferredCast(S, S->getType()->isSigned(), Ty, Ty->isSigned(), + Name, InsertBefore); +} + +CastInst *CastInst::createInferredCast( + Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) +{ + return createInferredCast(S, S->getType()->isSigned(), Ty, Ty->isSigned(), + Name, InsertAtEnd); +} + TruncInst::TruncInst( Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore ) : CastInst(Ty, Trunc, S, Name, InsertBefore) { |