LLVM API Documentation

ValueTypes.cpp

Go to the documentation of this file.
00001 //===-- ValueTypes.cpp - Implementation of MVT::ValueType methods ---------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements methods in the CodeGen/ValueTypes.h header.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/CodeGen/ValueTypes.h"
00015 #include "llvm/Type.h"
00016 using namespace llvm;
00017 
00018 /// MVT::getValueTypeString - This function returns value type as a string,
00019 /// e.g. "i32".
00020 const char *MVT::getValueTypeString(MVT::ValueType VT) {
00021   switch (VT) {
00022   default: assert(0 && "Invalid ValueType!");
00023   case MVT::i1:    return "i1";
00024   case MVT::i8:    return "i8";
00025   case MVT::i16:   return "i16";
00026   case MVT::i32:   return "i32";
00027   case MVT::i64:   return "i64";
00028   case MVT::i128:  return "i128";
00029   case MVT::f32:   return "f32";
00030   case MVT::f64:   return "f64";
00031   case MVT::f80:   return "f80";
00032   case MVT::f128:  return "f128";
00033   case MVT::isVoid:return "isVoid";
00034   case MVT::Other: return "ch";
00035   case MVT::Flag:  return "flag";
00036   case MVT::Vector:return "vec";
00037   case MVT::v8i8:  return "v8i8";
00038   case MVT::v4i16: return "v4i16";
00039   case MVT::v2i32: return "v2i32";
00040   case MVT::v16i8: return "v16i8";
00041   case MVT::v8i16: return "v8i16";
00042   case MVT::v4i32: return "v4i32";
00043   case MVT::v2i64: return "v2i64";
00044   case MVT::v4f32: return "v4f32";
00045   case MVT::v2f64: return "v2f64";
00046   }
00047 }
00048 
00049 /// MVT::getVectorType - Returns the ValueType that represents a vector
00050 /// NumElements in length, where each element is of type VT.  If there is no
00051 /// ValueType that represents this vector, a ValueType of Other is returned.
00052 ///
00053 MVT::ValueType MVT::getVectorType(ValueType VT, unsigned NumElements) {
00054   switch (VT) {
00055   default: 
00056     break;
00057   case MVT::i8:
00058     if (NumElements == 8)  return MVT::v8i8;
00059     if (NumElements == 16) return MVT::v16i8;
00060     break;
00061   case MVT::i16:
00062     if (NumElements == 4)  return MVT::v4i16;
00063     if (NumElements == 8)  return MVT::v8i16;
00064     break;
00065   case MVT::i32:
00066     if (NumElements == 2)  return MVT::v2i32;
00067     if (NumElements == 4)  return MVT::v4i32;
00068     break;
00069   case MVT::i64:
00070     if (NumElements == 2)  return MVT::v2i64;
00071     break;
00072   case MVT::f32:
00073     if (NumElements == 2)  return MVT::v2f32;
00074     if (NumElements == 4)  return MVT::v4f32;
00075     break;
00076   case MVT::f64:
00077     if (NumElements == 2)  return MVT::v2f64;
00078     break;
00079   }
00080   return MVT::Other;
00081 }
00082 
00083 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
00084 /// to the specified ValueType.  For integer types, this returns an unsigned
00085 /// type.  Note that this will abort for types that cannot be represented.
00086 const Type *MVT::getTypeForValueType(MVT::ValueType VT) {
00087   switch (VT) {
00088   default: assert(0 && "ValueType does not correspond to LLVM type!");
00089   case MVT::isVoid:return Type::VoidTy;
00090   case MVT::i1:    return Type::BoolTy;
00091   case MVT::i8:    return Type::UByteTy;
00092   case MVT::i16:   return Type::UShortTy;
00093   case MVT::i32:   return Type::UIntTy;
00094   case MVT::i64:   return Type::ULongTy;
00095   case MVT::f32:   return Type::FloatTy;
00096   case MVT::f64:   return Type::DoubleTy;
00097   }
00098 }