add a method to turn a type into a VT.
authorChris Lattner <sabre@nondot.org>
Sat, 31 Mar 2007 04:03:02 +0000 (04:03 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 31 Mar 2007 04:03:02 +0000 (04:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35526 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/ValueTypes.h
lib/VMCore/ValueTypes.cpp

index cc24563b8dfd21a2a8a6075d2e80e3b88bc6f820..f35f460a1be5175e3720e8a26a41abe194554045 100644 (file)
@@ -197,6 +197,11 @@ namespace MVT {  // MVT = Machine Value Types
   /// to the specified ValueType.  For integer types, this returns an unsigned
   /// type.  Note that this will abort for types that cannot be represented.
   const Type *getTypeForValueType(ValueType VT);
+  
+  /// MVT::getValueType - Return the value type corresponding to the specified
+  /// type.  This returns all vectors as MVT::Vector and all pointers as
+  /// MVT::iPTR.
+  ValueType getValueType(const Type *Ty);
 }
 
 } // End llvm namespace
index 9fb76554f7f31064d72f91c1eb1baaf05f25b370..ccbd29771de380e04e4b803de99a619d40642b51 100644 (file)
@@ -110,3 +110,31 @@ const Type *MVT::getTypeForValueType(MVT::ValueType VT) {
   case MVT::v2f64: return VectorType::get(Type::DoubleTy, 2);
   }
 }
+
+/// MVT::getValueType - Return the value type corresponding to the specified
+/// type.  This returns all vectors as MVT::Vector and all pointers as
+/// MVT::iPTR.
+MVT::ValueType MVT::getValueType(const Type *Ty) {
+  switch (Ty->getTypeID()) {
+  default: assert(0 && "Unknown type!");
+  case Type::VoidTyID:
+    return MVT::isVoid;
+  case Type::IntegerTyID:
+    switch (cast<IntegerType>(Ty)->getBitWidth()) {
+    default:
+      // FIXME: Return MVT::iANY.
+      assert(0 && "Invalid width for value type");
+    case 1:    return MVT::i1;
+    case 8:    return MVT::i8;
+    case 16:   return MVT::i16;
+    case 32:   return MVT::i32;
+    case 64:   return MVT::i64;
+    case 128:  return MVT::i128;
+    }
+    break;
+  case Type::FloatTyID:   return MVT::f32;
+  case Type::DoubleTyID:  return MVT::f64;
+  case Type::PointerTyID: return MVT::iPTR;
+  case Type::VectorTyID:  return MVT::Vector;
+  }
+}