aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Instructions.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-12-12 00:49:44 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-12-12 00:49:44 +0000
commit6d81a7d2aefd769267efe40e5a78f9427039e8b0 (patch)
tree1de434b7c1c746262859cd714241ff4732eb1b30 /lib/VMCore/Instructions.cpp
parent4fbcdf61e88f942a85eee5f49aa6550b3dd2a79b (diff)
downloadexternal_llvm-6d81a7d2aefd769267efe40e5a78f9427039e8b0.zip
external_llvm-6d81a7d2aefd769267efe40e5a78f9427039e8b0.tar.gz
external_llvm-6d81a7d2aefd769267efe40e5a78f9427039e8b0.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32456 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Instructions.cpp')
-rw-r--r--lib/VMCore/Instructions.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 57dd5a5..07a44ee 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/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: