diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-12-07 02:58:41 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-12-07 02:58:41 +0000 |
commit | 21f38f45392af5902f043a8ccb0247f6f2ea182c (patch) | |
tree | dafa5aafa9f1ab9a7531cde21b343c696dce6e6c | |
parent | 42a91ef2acaa67df6823f24e67337fbb24a944fa (diff) | |
download | bcm5719-llvm-21f38f45392af5902f043a8ccb0247f6f2ea182c.tar.gz bcm5719-llvm-21f38f45392af5902f043a8ccb0247f6f2ea182c.zip |
Add getBitCastOrAddrSpaceCast
llvm-svn: 196637
-rw-r--r-- | llvm/include/llvm/IR/Constants.h | 10 | ||||
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 13 |
2 files changed, 21 insertions, 2 deletions
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h index f1cee5a8f7f..dac20c9ec5c 100644 --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -943,12 +943,20 @@ public: Type *Ty ///< The type to trunc or bitcast C to ); - /// @brief Create a BitCast or a PtrToInt cast constant expression + /// @brief Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant + /// expression. static Constant *getPointerCast( Constant *C, ///< The pointer value to be casted (operand 0) Type *Ty ///< The type to which cast should be made ); + /// @brief Create a BitCast or AddrSpaceCast for a pointer type depending on + /// the address space. + static Constant *getPointerBitCastOrAddrSpaceCast( + Constant *C, ///< The constant to addrspacecast or bitcast + Type *Ty ///< The type to bitcast or addrspacecast C to + ); + /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts static Constant *getIntegerCast( Constant *C, ///< The integer constant to be casted diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index a8a325ae27b..690ac597b06 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -1499,7 +1499,18 @@ Constant *ConstantExpr::getPointerCast(Constant *S, Type *Ty) { return getBitCast(S, Ty); } -Constant *ConstantExpr::getIntegerCast(Constant *C, Type *Ty, +Constant *ConstantExpr::getPointerBitCastOrAddrSpaceCast(Constant *S, + Type *Ty) { + assert(S->getType()->isPtrOrPtrVectorTy() && "Invalid cast"); + assert(Ty->isPtrOrPtrVectorTy() && "Invalid cast"); + + if (S->getType()->getPointerAddressSpace() != Ty->getPointerAddressSpace()) + return getAddrSpaceCast(S, Ty); + + return getBitCast(S, Ty); +} + +Constant *ConstantExpr::getIntegerCast(Constant *C, Type *Ty, bool isSigned) { assert(C->getType()->isIntOrIntVectorTy() && Ty->isIntOrIntVectorTy() && "Invalid cast"); |