diff options
author | Chris Lattner <sabre@nondot.org> | 2006-09-18 04:54:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-09-18 04:54:57 +0000 |
commit | 79bc332ddb5200d61fb3739502cb0e8b8bb850bf (patch) | |
tree | 13125f713680fa4686e568689b7c9c9892ab3015 | |
parent | b33a42a21f3e44e12c291752dd2cdf3b5d5d65a2 (diff) |
add a helper method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30452 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Instructions.h | 5 | ||||
-rw-r--r-- | lib/VMCore/Instructions.cpp | 16 |
2 files changed, 21 insertions, 0 deletions
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index d7e52d1d6a..03ce2467a5 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -498,6 +498,11 @@ public: : UnaryInstruction(Ty, Cast, S, Name, InsertAtEnd) { } + /// isTruncIntCast - Return true if this is a truncating integer cast + /// instruction, e.g. a cast from long to uint. + bool isTruncIntCast() const; + + virtual CastInst *clone() const; // Methods for support type inquiry through isa, cast, and dyn_cast: diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 393858cd87..8f3633a66b 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1151,6 +1151,22 @@ bool ShiftInst::isLogicalShift() const { return getOpcode() == Instruction::Shl || getType()->isUnsigned(); } +//===----------------------------------------------------------------------===// +// CastInst Class +//===----------------------------------------------------------------------===// + +/// isTruncIntCast - Return true if this is a truncating integer cast +/// instruction, e.g. a cast from long to uint. +bool CastInst::isTruncIntCast() const { + // The dest type has to be integral, the input has to be integer. + if (!getType()->isIntegral() || !getOperand(0)->getType()->isInteger()) + return false; + + // Has to be large to smaller. + return getOperand(0)->getType()->getPrimitiveSizeInBits() > + getType()->getPrimitiveSizeInBits(); +} + //===----------------------------------------------------------------------===// // SetCondInst Class |