diff options
| author | Dan Gohman <gohman@apple.com> | 2010-05-28 21:41:37 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2010-05-28 21:41:37 +0000 |
| commit | 0d7f3b81954ba30f6b982c3dce5a71a672243210 (patch) | |
| tree | bcd5de8978d653760eb239e0064a4f793c73fa61 /llvm/lib/VMCore | |
| parent | a7f3cdb0f2775c42eccf70e257ae5789005f7c01 (diff) | |
| download | bcm5719-llvm-0d7f3b81954ba30f6b982c3dce5a71a672243210.tar.gz bcm5719-llvm-0d7f3b81954ba30f6b982c3dce5a71a672243210.zip | |
Split the logic behind CastInst::isNoopCast into a separate static function,
as is done with most other cast opcode predicates.
llvm-svn: 105008
Diffstat (limited to 'llvm/lib/VMCore')
| -rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index 3060a7601d0..76bf5838294 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -1911,9 +1911,12 @@ bool CastInst::isLosslessCast() const { /// # bitcast i32* %x to i8* /// # bitcast <2 x i32> %x to <4 x i16> /// # ptrtoint i32* %x to i32 ; on 32-bit plaforms only -/// @brief Determine if a cast is a no-op. -bool CastInst::isNoopCast(const Type *IntPtrTy) const { - switch (getOpcode()) { +/// @brief Determine if the described cast is a no-op. +bool CastInst::isNoopCast(Instruction::CastOps Opcode, + const Type *SrcTy, + const Type *DestTy, + const Type *IntPtrTy) { + switch (Opcode) { default: assert(!"Invalid CastOp"); case Instruction::Trunc: @@ -1930,13 +1933,18 @@ bool CastInst::isNoopCast(const Type *IntPtrTy) const { return true; // BitCast never modifies bits. case Instruction::PtrToInt: return IntPtrTy->getScalarSizeInBits() == - getType()->getScalarSizeInBits(); + DestTy->getScalarSizeInBits(); case Instruction::IntToPtr: return IntPtrTy->getScalarSizeInBits() == - getOperand(0)->getType()->getScalarSizeInBits(); + SrcTy->getScalarSizeInBits(); } } +/// @brief Determine if a cast is a no-op. +bool CastInst::isNoopCast(const Type *IntPtrTy) const { + return isNoopCast(getOpcode(), getOperand(0)->getType(), getType(), IntPtrTy); +} + /// This function determines if a pair of casts can be eliminated and what /// opcode should be used in the elimination. This assumes that there are two /// instructions like this: |

