Reverting dtor devirtualization patch.
[oota-llvm.git] / lib / VMCore / Instructions.cpp
index 369e98afe3739e0694f1e02a4490e1c46d0f83b0..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
 //===----------------------------------------------------------------------===//
@@ -397,8 +439,9 @@ void InvokeInst::init(Value *Fn, BasicBlock *IfNormal, BasicBlock *IfException,
 
 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)
@@ -415,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();
 
@@ -425,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
 //===----------------------------------------------------------------------===//
@@ -601,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!");
   }
@@ -1912,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();