Reverting dtor devirtualization patch.
[oota-llvm.git] / lib / VMCore / Instructions.cpp
index 43f89760af81366c9d22d64914e7f1f8ce468bde..0df0466112bc797aeeacb2ef1fcad8486687d905 100644 (file)
@@ -35,7 +35,36 @@ void CallSite::setCallingConv(unsigned CC) {
   else
     cast<InvokeInst>(I)->setCallingConv(CC);
 }
-
+const ParamAttrsList* CallSite::getParamAttrs() const {
+  if (CallInst *CI = dyn_cast<CallInst>(I))
+    return CI->getParamAttrs();
+  else
+    return cast<InvokeInst>(I)->getParamAttrs();
+}
+void CallSite::setParamAttrs(const ParamAttrsList *PAL) {
+  if (CallInst *CI = dyn_cast<CallInst>(I))
+    CI->setParamAttrs(PAL);
+  else
+    cast<InvokeInst>(I)->setParamAttrs(PAL);
+}
+bool CallSite::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
+  if (CallInst *CI = dyn_cast<CallInst>(I))
+    return CI->paramHasAttr(i, attr);
+  else
+    return cast<InvokeInst>(I)->paramHasAttr(i, attr);
+}
+bool CallSite::doesNotAccessMemory() const {
+  if (CallInst *CI = dyn_cast<CallInst>(I))
+    return CI->doesNotAccessMemory();
+  else
+    return cast<InvokeInst>(I)->doesNotAccessMemory();
+}
+bool CallSite::onlyReadsMemory() const {
+  if (CallInst *CI = dyn_cast<CallInst>(I))
+    return CI->onlyReadsMemory();
+  else
+    return cast<InvokeInst>(I)->onlyReadsMemory();
+}
 
 
 
@@ -341,8 +370,9 @@ CallInst::CallInst(Value *Func, const std::string &Name,
 
 CallInst::CallInst(const CallInst &CI)
   : Instruction(CI.getType(), Instruction::Call, new Use[CI.getNumOperands()],
-                CI.getNumOperands()) {
-  ParamAttrs = 0;
+                CI.getNumOperands()),
+    ParamAttrs(0) {
+  setParamAttrs(CI.getParamAttrs());
   SubclassData = CI.SubclassData;
   Use *OL = OperandList;
   Use *InOL = CI.OperandList;
@@ -350,7 +380,10 @@ CallInst::CallInst(const CallInst &CI)
     OL[i].init(InOL[i], this);
 }
 
-void CallInst::setParamAttrs(ParamAttrsList *newAttrs) {
+void CallInst::setParamAttrs(const ParamAttrsList *newAttrs) {
+  if (ParamAttrs == newAttrs)
+    return;
+
   if (ParamAttrs)
     ParamAttrs->dropRef();
 
@@ -360,6 +393,15 @@ void CallInst::setParamAttrs(ParamAttrsList *newAttrs) {
   ParamAttrs = newAttrs; 
 }
 
+bool CallInst::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
+  if (ParamAttrs && ParamAttrs->paramHasAttr(i, attr))
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->paramHasAttr(i, attr);
+  return false;
+}
+
+
 //===----------------------------------------------------------------------===//
 //                        InvokeInst Implementation
 //===----------------------------------------------------------------------===//
@@ -395,32 +437,11 @@ void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
   }
 }
 
-InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
-                       BasicBlock *IfException,
-                       Value* const *Args, unsigned NumArgs,
-                       const std::string &Name, Instruction *InsertBefore)
-  : TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
-                                    ->getElementType())->getReturnType(),
-                   Instruction::Invoke, 0, 0, InsertBefore) {
-  init(Fn, IfNormal, IfException, Args, NumArgs);
-  setName(Name);
-}
-
-InvokeInst::InvokeInst(Value *Fn, BasicBlock *IfNormal,
-                       BasicBlock *IfException,
-                       Value* const *Args, unsigned NumArgs,
-                       const std::string &Name, BasicBlock *InsertAtEnd)
-  : TerminatorInst(cast<FunctionType>(cast<PointerType>(Fn->getType())
-                                    ->getElementType())->getReturnType(),
-                   Instruction::Invoke, 0, 0, InsertAtEnd) {
-  init(Fn, IfNormal, IfException, Args, NumArgs);
-  setName(Name);
-}
-
 InvokeInst::InvokeInst(const InvokeInst &II)
   : TerminatorInst(II.getType(), Instruction::Invoke,
-                   new Use[II.getNumOperands()], II.getNumOperands()) {
-  ParamAttrs = 0;
+                   new Use[II.getNumOperands()], II.getNumOperands()),
+    ParamAttrs(0) {
+  setParamAttrs(II.getParamAttrs());
   SubclassData = II.SubclassData;
   Use *OL = OperandList, *InOL = II.OperandList;
   for (unsigned i = 0, e = II.getNumOperands(); i != e; ++i)
@@ -437,7 +458,10 @@ void InvokeInst::setSuccessorV(unsigned idx, BasicBlock *B) {
   return setSuccessor(idx, B);
 }
 
-void InvokeInst::setParamAttrs(ParamAttrsList *newAttrs) {
+void InvokeInst::setParamAttrs(const ParamAttrsList *newAttrs) {
+  if (ParamAttrs == newAttrs)
+    return;
+
   if (ParamAttrs)
     ParamAttrs->dropRef();
 
@@ -447,6 +471,15 @@ void InvokeInst::setParamAttrs(ParamAttrsList *newAttrs) {
   ParamAttrs = newAttrs; 
 }
 
+bool InvokeInst::paramHasAttr(uint16_t i, ParameterAttributes attr) const {
+  if (ParamAttrs && ParamAttrs->paramHasAttr(i, attr))
+    return true;
+  if (const Function *F = getCalledFunction())
+    return F->paramHasAttr(i, attr);
+  return false;
+}
+
+
 //===----------------------------------------------------------------------===//
 //                        ReturnInst Implementation
 //===----------------------------------------------------------------------===//
@@ -623,7 +656,7 @@ static Value *getAISize(Value *Amt) {
     Amt = ConstantInt::get(Type::Int32Ty, 1);
   else {
     assert(!isa<BasicBlock>(Amt) &&
-           "Passed basic block into allocation size parameter!  Ue other ctor");
+           "Passed basic block into allocation size parameter! Use other ctor");
     assert(Amt->getType() == Type::Int32Ty &&
            "Malloc/Allocation array size is not a 32-bit integer!");
   }
@@ -886,14 +919,6 @@ void StoreInst::setAlignment(unsigned Align) {
 //                       GetElementPtrInst Implementation
 //===----------------------------------------------------------------------===//
 
-// checkType - Simple wrapper function to give a better assertion failure
-// message on bad indexes for a gep instruction.
-//
-static inline const Type *checkType(const Type *Ty) {
-  assert(Ty && "Invalid GetElementPtrInst indices for type!");
-  return Ty;
-}
-
 void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
   NumOperands = 1+NumIdx;
   Use *OL = OperandList = new Use[NumOperands];
@@ -903,14 +928,6 @@ void GetElementPtrInst::init(Value *Ptr, Value* const *Idx, unsigned NumIdx) {
     OL[i+1].init(Idx[i], this);
 }
 
-void GetElementPtrInst::init(Value *Ptr, Value *Idx0, Value *Idx1) {
-  NumOperands = 3;
-  Use *OL = OperandList = new Use[3];
-  OL[0].init(Ptr, this);
-  OL[1].init(Idx0, this);
-  OL[2].init(Idx1, this);
-}
-
 void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
   NumOperands = 2;
   Use *OL = OperandList = new Use[2];
@@ -918,27 +935,6 @@ void GetElementPtrInst::init(Value *Ptr, Value *Idx) {
   OL[1].init(Idx, this);
 }
 
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx,
-                                     unsigned NumIdx,
-                                     const std::string &Name, Instruction *InBe)
-: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
-                                                        Idx, NumIdx, true))),
-              GetElementPtr, 0, 0, InBe) {
-  init(Ptr, Idx, NumIdx);
-  setName(Name);
-}
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value* const *Idx, 
-                                     unsigned NumIdx,
-                                     const std::string &Name, BasicBlock *IAE)
-: Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
-                                                        Idx, NumIdx, true))),
-              GetElementPtr, 0, 0, IAE) {
-  init(Ptr, Idx, NumIdx);
-  setName(Name);
-}
-
 GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
                                      const std::string &Name, Instruction *InBe)
   : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),Idx))),
@@ -955,24 +951,6 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx,
   setName(Name);
 }
 
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
-                                     const std::string &Name, Instruction *InBe)
-  : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
-                                                          Idx0, Idx1, true))),
-                GetElementPtr, 0, 0, InBe) {
-  init(Ptr, Idx0, Idx1);
-  setName(Name);
-}
-
-GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx0, Value *Idx1,
-                                     const std::string &Name, BasicBlock *IAE)
-  : Instruction(PointerType::get(checkType(getIndexedType(Ptr->getType(),
-                                                          Idx0, Idx1, true))),
-                GetElementPtr, 0, 0, IAE) {
-  init(Ptr, Idx0, Idx1);
-  setName(Name);
-}
-
 GetElementPtrInst::~GetElementPtrInst() {
   delete[] OperandList;
 }
@@ -1021,24 +999,6 @@ const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
   return CurIdx == NumIdx ? Ptr : 0;
 }
 
-const Type* GetElementPtrInst::getIndexedType(const Type *Ptr,
-                                              Value *Idx0, Value *Idx1,
-                                              bool AllowCompositeLeaf) {
-  const PointerType *PTy = dyn_cast<PointerType>(Ptr);
-  if (!PTy) return 0;   // Type isn't a pointer type!
-
-  // Check the pointer index.
-  if (!PTy->indexValid(Idx0)) return 0;
-
-  const CompositeType *CT = dyn_cast<CompositeType>(PTy->getElementType());
-  if (!CT || !CT->indexValid(Idx1)) return 0;
-
-  const Type *ElTy = CT->getTypeAtIndex(Idx1);
-  if (AllowCompositeLeaf || ElTy->isFirstClassType())
-    return ElTy;
-  return 0;
-}
-
 const Type* GetElementPtrInst::getIndexedType(const Type *Ptr, Value *Idx) {
   const PointerType *PTy = dyn_cast<PointerType>(Ptr);
   if (!PTy) return 0;   // Type isn't a pointer type!
@@ -2007,12 +1967,24 @@ CastInst::castIsValid(Instruction::CastOps op, Value *S, const Type *DstTy) {
     return SrcTy->isFloatingPoint() && DstTy->isFloatingPoint() && 
       SrcBitSize < DstBitSize;
   case Instruction::UIToFP:
-    return SrcTy->isInteger() && DstTy->isFloatingPoint();
   case Instruction::SIToFP:
+    if (const VectorType *SVTy = dyn_cast<VectorType>(SrcTy)) {
+      if (const VectorType *DVTy = dyn_cast<VectorType>(DstTy)) {
+        return SVTy->getElementType()->isInteger() &&
+               DVTy->getElementType()->isFloatingPoint() &&
+               SVTy->getNumElements() == DVTy->getNumElements();
+      }
+    }
     return SrcTy->isInteger() && DstTy->isFloatingPoint();
   case Instruction::FPToUI:
-    return SrcTy->isFloatingPoint() && DstTy->isInteger();
   case Instruction::FPToSI:
+    if (const VectorType *SVTy = dyn_cast<VectorType>(SrcTy)) {
+      if (const VectorType *DVTy = dyn_cast<VectorType>(DstTy)) {
+        return SVTy->getElementType()->isFloatingPoint() &&
+               DVTy->getElementType()->isInteger() &&
+               SVTy->getNumElements() == DVTy->getNumElements();
+      }
+    }
     return SrcTy->isFloatingPoint() && DstTy->isInteger();
   case Instruction::PtrToInt:
     return isa<PointerType>(SrcTy) && DstTy->isInteger();