[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp Instructions.cpp
Reid Spencer
reid at x10sys.com
Mon Dec 4 12:18:13 PST 2006
Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.177 -> 1.178
Instructions.cpp updated: 1.50 -> 1.51
---
Log message:
Implement new cast creation functions for both instructions and constant
expressions. These will get used to reduce clutter as we replace various
calls to createInferredCast and getCast.
---
Diffs of the changes: (+68 -2)
Constants.cpp | 22 ++++++++++++++++++++--
Instructions.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 2 deletions(-)
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.177 llvm/lib/VMCore/Constants.cpp:1.178
--- llvm/lib/VMCore/Constants.cpp:1.177 Mon Dec 4 12:38:05 2006
+++ llvm/lib/VMCore/Constants.cpp Mon Dec 4 14:17:56 2006
@@ -1534,6 +1534,24 @@
return 0;
}
+Constant *ConstantExpr::getZExtOrBitCast(Constant *C, const Type *Ty) {
+ if (C->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return getCast(Instruction::BitCast, C, Ty);
+ return getCast(Instruction::ZExt, C, Ty);
+}
+
+Constant *ConstantExpr::getSExtOrBitCast(Constant *C, const Type *Ty) {
+ if (C->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return getCast(Instruction::BitCast, C, Ty);
+ return getCast(Instruction::SExt, C, Ty);
+}
+
+Constant *ConstantExpr::getTruncOrBitCast(Constant *C, const Type *Ty) {
+ if (C->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return getCast(Instruction::BitCast, C, Ty);
+ return getCast(Instruction::Trunc, 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");
@@ -1616,14 +1634,14 @@
// can't cast pointers to anything but pointers.
const Type *SrcTy = C->getType();
assert((isa<PointerType>(SrcTy) == isa<PointerType>(DstTy)) &&
- "Bitcast cannot cast pointer to non-pointer and vice versa");
+ "BitCast cannot cast pointer to non-pointer and vice versa");
// Now we know we're not dealing with mismatched pointer casts (ptr->nonptr
// or nonptr->ptr). For all the other types, the cast is okay if source and
// destination bit widths are identical.
unsigned SrcBitSize = SrcTy->getPrimitiveSizeInBits();
unsigned DstBitSize = DstTy->getPrimitiveSizeInBits();
- assert(SrcBitSize == DstBitSize && "Bitcast requies types of same width");
+ assert(SrcBitSize == DstBitSize && "BitCast requies types of same width");
return getFoldedCast(Instruction::BitCast, C, DstTy);
}
Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.50 llvm/lib/VMCore/Instructions.cpp:1.51
--- llvm/lib/VMCore/Instructions.cpp:1.50 Sun Dec 3 20:43:42 2006
+++ llvm/lib/VMCore/Instructions.cpp Mon Dec 4 14:17:56 2006
@@ -1500,6 +1500,54 @@
return 0;
}
+CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ Instruction *InsertBefore) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return create(Instruction::ZExt, S, Ty, Name, InsertBefore);
+}
+
+CastInst *CastInst::createZExtOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return create(Instruction::ZExt, S, Ty, Name, InsertAtEnd);
+}
+
+CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ Instruction *InsertBefore) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return create(Instruction::SExt, S, Ty, Name, InsertBefore);
+}
+
+CastInst *CastInst::createSExtOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return create(Instruction::SExt, S, Ty, Name, InsertAtEnd);
+}
+
+CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ Instruction *InsertBefore) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+ return create(Instruction::Trunc, S, Ty, Name, InsertBefore);
+}
+
+CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd) {
+ if (S->getType()->getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits())
+ return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+ return create(Instruction::Trunc, S, 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