add a helper method

llvm-svn: 30452
This commit is contained in:
Chris Lattner 2006-09-18 04:54:57 +00:00
parent 4a13d3b391
commit b0b8ddd175
2 changed files with 21 additions and 0 deletions

View File

@ -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:

View File

@ -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