For PR950:
[oota-llvm.git] / lib / VMCore / Instructions.cpp
index d3c7b54d2a8e98640ae021a0c90d173b1739c405..800eb9cd1d866850315993ded9d946c57f5c26b6 100644 (file)
@@ -34,6 +34,8 @@ void CallSite::setCallingConv(unsigned CC) {
 }
 
 
+
+
 //===----------------------------------------------------------------------===//
 //                            TerminatorInst Class
 //===----------------------------------------------------------------------===//
@@ -48,6 +50,13 @@ TerminatorInst::TerminatorInst(Instruction::TermOps iType,
   : Instruction(Type::VoidTy, iType, Ops, NumOps, "", IAE) {
 }
 
+// Out of line virtual method, so the vtable, etc has a home.
+TerminatorInst::~TerminatorInst() {
+}
+
+// Out of line virtual method, so the vtable, etc has a home.
+UnaryInstruction::~UnaryInstruction() {
+}
 
 
 //===----------------------------------------------------------------------===//
@@ -504,10 +513,13 @@ void BranchInst::setSuccessorV(unsigned idx, BasicBlock *B) {
 
 static Value *getAISize(Value *Amt) {
   if (!Amt)
-    Amt = ConstantUInt::get(Type::UIntTy, 1);
-  else
+    Amt = ConstantInt::get(Type::UIntTy, 1);
+  else {
+    assert(!isa<BasicBlock>(Amt) &&
+           "Passed basic block into allocation size parameter!  Ue other ctor");
     assert(Amt->getType() == Type::UIntTy &&
            "Malloc/Allocation array size != UIntTy!");
+  }
   return Amt;
 }
 
@@ -529,9 +541,13 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
   assert(Ty != Type::VoidTy && "Cannot allocate void!");
 }
 
+// Out of line virtual method, so the vtable, etc has a home.
+AllocationInst::~AllocationInst() {
+}
+
 bool AllocationInst::isArrayAllocation() const {
-  if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(getOperand(0)))
-    return CUI->getValue() != 1;
+  if (ConstantInt *CUI = dyn_cast<ConstantInt>(getOperand(0)))
+    return CUI->getZExtValue() != 1;
   return true;
 }
 
@@ -664,7 +680,7 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,
 // message on bad indexes for a gep instruction.
 //
 static inline const Type *checkType(const Type *Ty) {
-  assert(Ty && "Invalid indices for type!");
+  assert(Ty && "Invalid GetElementPtrInst indices for type!");
   return Ty;
 }
 
@@ -828,6 +844,19 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
   Ops[1].init(Index, this);
 }
 
+ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
+                                       const std::string &Name,
+                                       Instruction *InsertBef)
+  : Instruction(cast<PackedType>(Val->getType())->getElementType(),
+                ExtractElement, Ops, 2, Name, InsertBef) {
+  Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
+  assert(isValidOperands(Val, Index) &&
+         "Invalid extractelement instruction operands!");
+  Ops[0].init(Val, this);
+  Ops[1].init(Index, this);
+}
+
+
 ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
                                        const std::string &Name,
                                        BasicBlock *InsertAE)
@@ -840,6 +869,20 @@ ExtractElementInst::ExtractElementInst(Value *Val, Value *Index,
   Ops[1].init(Index, this);
 }
 
+ExtractElementInst::ExtractElementInst(Value *Val, unsigned IndexV,
+                                       const std::string &Name,
+                                       BasicBlock *InsertAE)
+  : Instruction(cast<PackedType>(Val->getType())->getElementType(),
+                ExtractElement, Ops, 2, Name, InsertAE) {
+  Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
+  assert(isValidOperands(Val, Index) &&
+         "Invalid extractelement instruction operands!");
+  
+  Ops[0].init(Val, this);
+  Ops[1].init(Index, this);
+}
+
+
 bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) {
   if (!isa<PackedType>(Val->getType()) || Index->getType() != Type::UIntTy)
     return false;
@@ -868,6 +911,19 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
   Ops[2].init(Index, this);
 }
 
+InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
+                                     const std::string &Name,
+                                     Instruction *InsertBef)
+  : Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertBef) {
+  Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
+  assert(isValidOperands(Vec, Elt, Index) &&
+         "Invalid insertelement instruction operands!");
+  Ops[0].init(Vec, this);
+  Ops[1].init(Elt, this);
+  Ops[2].init(Index, this);
+}
+
+
 InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
                                      const std::string &Name,
                                      BasicBlock *InsertAE)
@@ -880,6 +936,19 @@ InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, Value *Index,
   Ops[2].init(Index, this);
 }
 
+InsertElementInst::InsertElementInst(Value *Vec, Value *Elt, unsigned IndexV,
+                                     const std::string &Name,
+                                     BasicBlock *InsertAE)
+: Instruction(Vec->getType(), InsertElement, Ops, 3, Name, InsertAE) {
+  Constant *Index = ConstantInt::get(Type::UIntTy, IndexV);
+  assert(isValidOperands(Vec, Elt, Index) &&
+         "Invalid insertelement instruction operands!");
+  
+  Ops[0].init(Vec, this);
+  Ops[1].init(Elt, this);
+  Ops[2].init(Index, this);
+}
+
 bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt, 
                                         const Value *Index) {
   if (!isa<PackedType>(Vec->getType()))
@@ -1125,6 +1194,33 @@ bool BinaryOperator::swapOperands() {
 }
 
 
+//===----------------------------------------------------------------------===//
+//                               ShiftInst Class
+//===----------------------------------------------------------------------===//
+
+/// isLogicalShift - Return true if this is a logical shift left or a logical
+/// shift right.
+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
 //===----------------------------------------------------------------------===//