CMake: removed lib/VMCore/DebugInfoBuilder.cpp.
[oota-llvm.git] / lib / VMCore / Verifier.cpp
index 21646840e4c18d6e22566867a192a7b47d2eef36..f9ad41b2c42131325efb2e374ff6744b00c75a89 100644 (file)
@@ -72,6 +72,10 @@ namespace {  // Anonymous namespace for class
 
     PreVerifier() : FunctionPass(&ID) { }
 
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.setPreservesAll();
+    }
+
     // Check that the prerequisites for successful DominatorTree construction
     // are satisfied.
     bool runOnFunction(Function &F) {
@@ -683,23 +687,10 @@ void Verifier::visitSwitchInst(SwitchInst &SI) {
 }
 
 void Verifier::visitSelectInst(SelectInst &SI) {
-  if (const VectorType* vt
-             = dyn_cast<VectorType>(SI.getCondition()->getType())) {
-    Assert1( vt->getElementType() == Type::Int1Ty,
-            "Select condition type must be vector of bool!", &SI);
-    if (const VectorType* val_vt
-             = dyn_cast<VectorType>(SI.getTrueValue()->getType())) {
-      Assert1( vt->getNumElements() == val_vt->getNumElements(),
-               "Select vector size != value vector size", &SI);
-    } else {
-      Assert1(0, "Vector select values must have vector types", &SI);
-    }
-  } else {
-    Assert1(SI.getCondition()->getType() == Type::Int1Ty,
-            "Select condition type must be bool!", &SI);
-  }
-  Assert1(SI.getTrueValue()->getType() == SI.getFalseValue()->getType(),
-          "Select values must have identical types!", &SI);
+  Assert1(!SelectInst::areInvalidOperands(SI.getOperand(0), SI.getOperand(1),
+                                          SI.getOperand(2)),
+          "Invalid operands for select instruction!", &SI);
+
   Assert1(SI.getTrueValue()->getType() == SI.getType(),
           "Select values must have same type as select instruction!", &SI);
   visitInstruction(SI);
@@ -1322,6 +1313,11 @@ void Verifier::visitInstruction(Instruction &I) {
   InstsInThisBlock.insert(&I);
 }
 
+// Flags used by TableGen to mark intrinsic parameters with the
+// LLVMExtendedElementVectorType and LLVMTruncatedElementVectorType classes.
+static const unsigned ExtendedElementVectorType = 0x40000000;
+static const unsigned TruncatedElementVectorType = 0x20000000;
+
 /// visitIntrinsicFunction - Allow intrinsics to be verified in different ways.
 ///
 void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
@@ -1336,12 +1332,9 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
   switch (ID) {
   default:
     break;
-  case Intrinsic::memcpy_i32:
-  case Intrinsic::memcpy_i64:
-  case Intrinsic::memmove_i32:
-  case Intrinsic::memmove_i64:
-  case Intrinsic::memset_i32:
-  case Intrinsic::memset_i64:
+  case Intrinsic::memcpy:
+  case Intrinsic::memmove:
+  case Intrinsic::memset:
     Assert1(isa<ConstantInt>(CI.getOperand(4)),
             "alignment argument of memory intrinsics must be a constant int",
             &CI);
@@ -1375,7 +1368,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
             &CI);
     break;
   case Intrinsic::stackprotector:
-    Assert1(isa<AllocaInst>(CI.getOperand(2)),
+    Assert1(isa<AllocaInst>(CI.getOperand(2)->stripPointerCasts()),
             "llvm.stackprotector parameter #2 must resolve to an alloca.",
             &CI);
     break;
@@ -1388,13 +1381,40 @@ bool Verifier::PerformTypeCheck(Intrinsic::ID ID, Function *F, const Type *Ty,
 
   unsigned NumElts = 0;
   const Type *EltTy = Ty;
-  if (const VectorType *VTy = dyn_cast<VectorType>(Ty)) {
+  const VectorType *VTy = dyn_cast<VectorType>(Ty);
+  if (VTy) {
     EltTy = VTy->getElementType();
     NumElts = VTy->getNumElements();
   }
 
   if (VT < 0) {
     int Match = ~VT;
+
+    // Check flags that indicate a type that is an integral vector type with
+    // elements that are larger or smaller than the elements of the matched
+    // type.
+    if ((Match & (ExtendedElementVectorType |
+                  TruncatedElementVectorType)) != 0) {
+      const IntegerType *IEltTy = dyn_cast<IntegerType>(EltTy);
+      if (!VTy || !IEltTy) {
+        CheckFailed("Intrinsic parameter #" + utostr(ArgNo - 1) + " is not "
+                    "an integral vector type.", F);
+        return false;
+      }
+      // Adjust the current Ty (in the opposite direction) rather than
+      // the type being matched against.
+      if ((Match & ExtendedElementVectorType) != 0) {
+        if ((IEltTy->getBitWidth() & 1) != 0) {
+          CheckFailed("Intrinsic parameter #" + utostr(ArgNo - 1) + " vector "
+                      "element bit-width is odd.", F);
+          return false;
+        }
+        Ty = VectorType::getTruncatedElementVectorType(VTy);
+      } else
+        Ty = VectorType::getExtendedElementVectorType(VTy);
+      Match &= ~(ExtendedElementVectorType | TruncatedElementVectorType);
+    }
+
     const Type *RetTy = FTy->getReturnType();
     const StructType *ST = dyn_cast<StructType>(RetTy);
     unsigned NumRets = 1;