Use stripPointerCasts when checking for AllocaInsts for the stackprotector intrinsic.
[oota-llvm.git] / lib / VMCore / ValueTypes.cpp
index 88add7c174c41cad04389b4dd76ed8d73b416461..0229f155bc97b78ae986d5c3441780d161acb0ee 100644 (file)
@@ -1,4 +1,4 @@
-//===-- ValueTypes.cpp - Implementation of MVT::ValueType methods ---------===//
+//===----------- ValueTypes.cpp - Implementation of MVT methods -----------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
 #include "llvm/DerivedTypes.h"
 using namespace llvm;
 
-/// MVT::getValueTypeString - This function returns value type as a string,
-/// e.g. "i32".
-std::string MVT::getValueTypeString(MVT::ValueType VT) {
-  switch (VT) {
+MVT MVT::getExtendedIntegerVT(unsigned BitWidth) {
+  MVT VT;
+  VT.LLVMTy = IntegerType::get(BitWidth);
+  assert(VT.isExtended() && "Type is not extended!");
+  return VT;
+}
+
+MVT MVT::getExtendedVectorVT(MVT VT, unsigned NumElements) {
+  MVT ResultVT;
+  ResultVT.LLVMTy = VectorType::get(VT.getTypeForMVT(), NumElements);
+  assert(ResultVT.isExtended() && "Type is not extended!");
+  return ResultVT;
+}
+
+bool MVT::isExtendedFloatingPoint() const {
+  assert(isExtended() && "Type is not extended!");
+  return LLVMTy->isFPOrFPVector();
+}
+
+bool MVT::isExtendedInteger() const {
+  assert(isExtended() && "Type is not extended!");
+  return LLVMTy->isIntOrIntVector();
+}
+
+bool MVT::isExtendedVector() const {
+  assert(isExtended() && "Type is not extended!");
+  return isa<VectorType>(LLVMTy);
+}
+
+bool MVT::isExtended64BitVector() const {
+  return isExtendedVector() && getSizeInBits() == 64;
+}
+
+bool MVT::isExtended128BitVector() const {
+  return isExtendedVector() && getSizeInBits() == 128;
+}
+
+MVT MVT::getExtendedVectorElementType() const {
+  assert(isExtended() && "Type is not extended!");
+  return MVT::getMVT(cast<VectorType>(LLVMTy)->getElementType());
+}
+
+unsigned MVT::getExtendedVectorNumElements() const {
+  assert(isExtended() && "Type is not extended!");
+  return cast<VectorType>(LLVMTy)->getNumElements();
+}
+
+unsigned MVT::getExtendedSizeInBits() const {
+  assert(isExtended() && "Type is not extended!");
+  if (const IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
+    return ITy->getBitWidth();
+  if (const VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
+    return VTy->getBitWidth();
+  assert(false && "Unrecognized extended type!");
+  return 0; // Suppress warnings.
+}
+
+/// getMVTString - This function returns value type as a string, e.g. "i32".
+std::string MVT::getMVTString() const {
+  switch (V) {
   default:
-    if (isVector(VT))
-      return "v" + utostr(getVectorNumElements(VT)) +
-             getValueTypeString(getVectorElementType(VT));
-    if (isInteger(VT))
-      return "i" + utostr(getSizeInBits(VT));
-    assert(0 && "Invalid ValueType!");
+    if (isVector())
+      return "v" + utostr(getVectorNumElements()) +
+             getVectorElementType().getMVTString();
+    if (isInteger())
+      return "i" + utostr(getSizeInBits());
+    assert(0 && "Invalid MVT!");
+    return "?";
   case MVT::i1:      return "i1";
   case MVT::i8:      return "i8";
   case MVT::i16:     return "i16";
@@ -58,19 +115,15 @@ std::string MVT::getValueTypeString(MVT::ValueType VT) {
   }
 }
 
-/// MVT::getTypeForValueType - This method returns an LLVM type corresponding
-/// to the specified ValueType.  Note that this will abort for types that cannot
-/// be represented.
-const Type *MVT::getTypeForValueType(MVT::ValueType VT) {
-  switch (VT) {
+/// getTypeForMVT - This method returns an LLVM type corresponding to the
+/// specified MVT.  For integer types, this returns an unsigned type.  Note
+/// that this will abort for types that cannot be represented.
+const Type *MVT::getTypeForMVT() const {
+  switch (V) {
   default:
-    if (isVector(VT))
-      return VectorType::get(getTypeForValueType(getVectorElementType(VT)),
-                             getVectorNumElements(VT));
-    if (isInteger(VT))
-      return IntegerType::get(getSizeInBits(VT));
-    assert(0 && "ValueType does not correspond to LLVM type!");
-  case MVT::isVoid:return Type::VoidTy;
+    assert(isExtended() && "Type is not extended!");
+    return LLVMTy;
+  case MVT::isVoid:  return Type::VoidTy;
   case MVT::i1:      return Type::Int1Ty;
   case MVT::i8:      return Type::Int8Ty;
   case MVT::i16:     return Type::Int16Ty;
@@ -98,18 +151,19 @@ const Type *MVT::getTypeForValueType(MVT::ValueType VT) {
   }
 }
 
-/// MVT::getValueType - Return the value type corresponding to the specified
-/// type.  This returns all pointers as MVT::iPTR.  If HandleUnknown is true,
-/// unknown types are returned as Other, otherwise they are invalid.
-MVT::ValueType MVT::getValueType(const Type *Ty, bool HandleUnknown) {
+/// getMVT - Return the value type corresponding to the specified type.  This
+/// returns all pointers as MVT::iPTR.  If HandleUnknown is true, unknown types
+/// are returned as Other, otherwise they are invalid.
+MVT MVT::getMVT(const Type *Ty, bool HandleUnknown){
   switch (Ty->getTypeID()) {
   default:
     if (HandleUnknown) return MVT::Other;
     assert(0 && "Unknown type!");
+    return MVT::isVoid;
   case Type::VoidTyID:
     return MVT::isVoid;
   case Type::IntegerTyID:
-    return getIntegerType(cast<IntegerType>(Ty)->getBitWidth());
+    return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
   case Type::FloatTyID:     return MVT::f32;
   case Type::DoubleTyID:    return MVT::f64;
   case Type::X86_FP80TyID:  return MVT::f80;
@@ -118,8 +172,8 @@ MVT::ValueType MVT::getValueType(const Type *Ty, bool HandleUnknown) {
   case Type::PointerTyID:   return MVT::iPTR;
   case Type::VectorTyID: {
     const VectorType *VTy = cast<VectorType>(Ty);
-    return getVectorType(getValueType(VTy->getElementType(), false),
-                         VTy->getNumElements());
+    return getVectorVT(getMVT(VTy->getElementType(), false),
+                       VTy->getNumElements());
   }
   }
 }