[llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp

Reid Spencer reid at x10sys.com
Mon Dec 11 16:50:00 PST 2006



Changes in directory llvm/lib/VMCore:

Instructions.cpp updated: 1.54 -> 1.55
---
Log message:

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.


---
Diffs of the changes:  (+52 -0)

 Instructions.cpp |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+)


Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.54 llvm/lib/VMCore/Instructions.cpp:1.55
--- llvm/lib/VMCore/Instructions.cpp:1.54	Wed Dec  6 22:18:31 2006
+++ llvm/lib/VMCore/Instructions.cpp	Mon Dec 11 18:49:44 2006
@@ -1580,6 +1580,58 @@
   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:






More information about the llvm-commits mailing list