diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2006-12-12 00:51:07 +0000 |
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2006-12-12 00:51:07 +0000 |
| commit | 56521c48febecc896f3150ff55589ca717603743 (patch) | |
| tree | fa9708521cd9932d6d5d977a1c46a0da6e090e52 /llvm/lib | |
| parent | 7e93347b579b7f58668f0dfe078cdf4cc14fc272 (diff) | |
| download | bcm5719-llvm-56521c48febecc896f3150ff55589ca717603743.tar.gz bcm5719-llvm-56521c48febecc896f3150ff55589ca717603743.zip | |
Implement getIntegerCast and getFPCast for ConstantExpr. These are similar
to the createIntegerCast and createFPCast for CastInst instructions.
llvm-svn: 32457
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index b59341d9272..2aa0524dfd0 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -1514,6 +1514,29 @@ Constant *ConstantExpr::getPointerCast(Constant *S, const Type *Ty) { return getCast(Instruction::BitCast, S, Ty); } +Constant *ConstantExpr::getIntegerCast(Constant *C, const Type *Ty, + bool isSigned) { + assert(C->getType()->isIntegral() && Ty->isIntegral() && "Invalid cast"); + unsigned SrcBits = C->getType()->getPrimitiveSizeInBits(); + unsigned DstBits = Ty->getPrimitiveSizeInBits(); + Instruction::CastOps opcode = + (SrcBits == DstBits ? Instruction::BitCast : + (SrcBits > DstBits ? Instruction::Trunc : + (isSigned ? Instruction::SExt : Instruction::ZExt))); + return getCast(opcode, C, Ty); +} + +Constant *ConstantExpr::getFPCast(Constant *C, const Type *Ty) { + assert(C->getType()->isFloatingPoint() && Ty->isFloatingPoint() && + "Invalid cast"); + unsigned SrcBits = C->getType()->getPrimitiveSizeInBits(); + unsigned DstBits = Ty->getPrimitiveSizeInBits(); + Instruction::CastOps opcode = + (SrcBits == DstBits ? Instruction::BitCast : + (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt)); + return getCast(opcode, C, Ty); +} + Constant *ConstantExpr::getTrunc(Constant *C, const Type *Ty) { assert(C->getType()->isInteger() && "Trunc operand must be integer"); assert(Ty->isIntegral() && "Trunc produces only integral"); |

