add a helper method
authorChris Lattner <sabre@nondot.org>
Mon, 18 Sep 2006 04:54:57 +0000 (04:54 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 18 Sep 2006 04:54:57 +0000 (04:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30452 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Instructions.h
lib/VMCore/Instructions.cpp

index d7e52d1d6aa021fe61d413531d44c273864ae042..03ce2467a50edbb59c7387db8d6fd51418941ed4 100644 (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:
index 393858cd8716e4381426affc8ef0afe3c22530c1..8f3633a66b545049494ae3920024b4ec6b5bb4ba 100644 (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