[llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp
Reid Spencer
reid at x10sys.com
Mon Dec 4 19:28:41 PST 2006
Changes in directory llvm/lib/VMCore:
Instructions.cpp updated: 1.51 -> 1.52
---
Log message:
Implement createPointerCast.
---
Diffs of the changes: (+25 -0)
Instructions.cpp | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+)
Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.51 llvm/lib/VMCore/Instructions.cpp:1.52
--- llvm/lib/VMCore/Instructions.cpp:1.51 Mon Dec 4 14:17:56 2006
+++ llvm/lib/VMCore/Instructions.cpp Mon Dec 4 21:28:26 2006
@@ -1548,6 +1548,31 @@
return create(Instruction::Trunc, S, Ty, Name, InsertAtEnd);
}
+CastInst *CastInst::createPointerCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ BasicBlock *InsertAtEnd) {
+ assert(isa<PointerType>(S->getType()) && "Invalid cast");
+ assert((Ty->isIntegral() || Ty->getTypeID() == Type::PointerTyID) &&
+ "Invalid cast");
+
+ if (Ty->isIntegral())
+ return create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
+ return create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
+}
+
+/// @brief Create a BitCast or a PtrToInt cast instruction
+CastInst *CastInst::createPointerCast(Value *S, const Type *Ty,
+ const std::string &Name,
+ Instruction *InsertBefore) {
+ assert(isa<PointerType>(S->getType()) && "Invalid cast");
+ assert((Ty->isIntegral() || Ty->getTypeID() == Type::PointerTyID) &&
+ "Invalid cast");
+
+ if (Ty->isIntegral())
+ return create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
+ return create(Instruction::BitCast, S, Ty, Name, InsertBefore);
+}
+
// 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