diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2006-12-12 00:49:44 +0000 |
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2006-12-12 00:49:44 +0000 |
| commit | 7e93347b579b7f58668f0dfe078cdf4cc14fc272 (patch) | |
| tree | b1d88c7fb4a856cd820c79d3ff9c79adc521460a /llvm/lib/VMCore/Instructions.cpp | |
| parent | b7e5180d3cfc158ed78c8bae38839851436e1da7 (diff) | |
| download | bcm5719-llvm-7e93347b579b7f58668f0dfe078cdf4cc14fc272.tar.gz bcm5719-llvm-7e93347b579b7f58668f0dfe078cdf4cc14fc272.zip | |
Implement createIntegerCast and createFPCast factory methods for handling
integer and floating point cast creation. createIntegerCast generates
ZExt/SExt, BitCast or Trunc. createFPCast generates FPExt, Bitcast, or
FPTrunc.
llvm-svn: 32456
Diffstat (limited to 'llvm/lib/VMCore/Instructions.cpp')
| -rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index 57dd5a56b8a..07a44ee750f 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -1580,6 +1580,58 @@ CastInst *CastInst::createPointerCast(Value *S, const Type *Ty, return create(Instruction::BitCast, S, Ty, Name, InsertBefore); } +CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty, + bool isSigned, const std::string &Name, + Instruction *InsertBefore) { + 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 create(opcode, C, Ty, Name, InsertBefore); +} + +CastInst *CastInst::createIntegerCast(Value *C, const Type *Ty, + bool isSigned, const std::string &Name, + BasicBlock *InsertAtEnd) { + 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 create(opcode, C, Ty, Name, InsertAtEnd); +} + +CastInst *CastInst::createFPCast(Value *C, const Type *Ty, + const std::string &Name, + Instruction *InsertBefore) { + 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 create(opcode, C, Ty, Name, InsertBefore); +} + +CastInst *CastInst::createFPCast(Value *C, const Type *Ty, + const std::string &Name, + BasicBlock *InsertAtEnd) { + 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 create(opcode, C, Ty, Name, InsertAtEnd); +} + // Provide a way to get a "cast" where the cast opcode is inferred from the // types and size of the operand. This, basically, is a parallel of the // logic in the checkCast function below. This axiom should hold: |

