diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-07-30 22:02:14 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-07-30 22:02:14 +0000 |
commit | 485c7fd76b32a69c46782a715682ed8831b0873b (patch) | |
tree | 8af5394070afbcb779a16e1ca359651a1309349b /lib/IR | |
parent | 6aebd5facbbc80787270cc1b18bffbf6c6f655e8 (diff) | |
download | llvm-485c7fd76b32a69c46782a715682ed8831b0873b.tar.gz llvm-485c7fd76b32a69c46782a715682ed8831b0873b.tar.bz2 llvm-485c7fd76b32a69c46782a715682ed8831b0873b.tar.xz |
Revert "Remove isCastable since nothing uses it now"
Apparently dragonegg uses it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187454 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r-- | lib/IR/Instructions.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/IR/Instructions.cpp b/lib/IR/Instructions.cpp index f2c669131d..665fe66ccc 100644 --- a/lib/IR/Instructions.cpp +++ b/lib/IR/Instructions.cpp @@ -2454,6 +2454,69 @@ CastInst *CastInst::CreateFPCast(Value *C, Type *Ty, return Create(opcode, C, Ty, Name, InsertAtEnd); } +// Check whether it is valid to call getCastOpcode for these types. +// This routine must be kept in sync with getCastOpcode. +bool CastInst::isCastable(Type *SrcTy, Type *DestTy) { + if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType()) + return false; + + if (SrcTy == DestTy) + return true; + + if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) + if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy)) + if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) { + // An element by element cast. Valid if casting the elements is valid. + SrcTy = SrcVecTy->getElementType(); + DestTy = DestVecTy->getElementType(); + } + + // Get the bit sizes, we'll need these + unsigned SrcBits = SrcTy->getPrimitiveSizeInBits(); // 0 for ptr + unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr + + // Run through the possibilities ... + if (DestTy->isIntegerTy()) { // Casting to integral + if (SrcTy->isIntegerTy()) { // Casting from integral + return true; + } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt + return true; + } else if (SrcTy->isVectorTy()) { // Casting from vector + return DestBits == SrcBits; + } else { // Casting from something else + return SrcTy->isPointerTy(); + } + } else if (DestTy->isFloatingPointTy()) { // Casting to floating pt + if (SrcTy->isIntegerTy()) { // Casting from integral + return true; + } else if (SrcTy->isFloatingPointTy()) { // Casting from floating pt + return true; + } else if (SrcTy->isVectorTy()) { // Casting from vector + return DestBits == SrcBits; + } else { // Casting from something else + return false; + } + } else if (DestTy->isVectorTy()) { // Casting to vector + return DestBits == SrcBits; + } else if (DestTy->isPointerTy()) { // Casting to pointer + if (SrcTy->isPointerTy()) { // Casting from pointer + return true; + } else if (SrcTy->isIntegerTy()) { // Casting from integral + return true; + } else { // Casting from something else + return false; + } + } else if (DestTy->isX86_MMXTy()) { + if (SrcTy->isVectorTy()) { + return DestBits == SrcBits; // 64-bit vector to MMX + } else { + return false; + } + } else { // Casting to something else + return false; + } +} + bool CastInst::isBitCastable(Type *SrcTy, Type *DestTy) { if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType()) return false; |