diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2006-12-05 03:28:26 +0000 |
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2006-12-05 03:28:26 +0000 |
| commit | d5a3f0dd1b87552ac5ff4527c3b3a5137ef09f40 (patch) | |
| tree | 6711cd9739b0eb592eb72bf952220bdb61c37c4a /llvm/lib/VMCore/Instructions.cpp | |
| parent | bc245a0190bc3c2188d4579c16741ff120d4bb3c (diff) | |
| download | bcm5719-llvm-d5a3f0dd1b87552ac5ff4527c3b3a5137ef09f40.tar.gz bcm5719-llvm-d5a3f0dd1b87552ac5ff4527c3b3a5137ef09f40.zip | |
Implement createPointerCast.
llvm-svn: 32212
Diffstat (limited to 'llvm/lib/VMCore/Instructions.cpp')
| -rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index 8c1f47d8afb..65a910b8e8c 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -1548,6 +1548,31 @@ CastInst *CastInst::createTruncOrBitCast(Value *S, const Type *Ty, 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: |

