1193323Sed//===- CodeGen/ValueTypes.h - Low-Level Target independ. types --*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file defines the set of low-level target independent types which various 11193323Sed// values in the code generator are. This allows the target specific behavior 12193323Sed// of instructions to be described to target independent passes. 13193323Sed// 14193323Sed//===----------------------------------------------------------------------===// 15193323Sed 16193323Sed#ifndef LLVM_CODEGEN_VALUETYPES_H 17193323Sed#define LLVM_CODEGEN_VALUETYPES_H 18193323Sed 19234353Sdim#include "llvm/Support/DataTypes.h" 20234353Sdim#include "llvm/Support/ErrorHandling.h" 21234353Sdim#include "llvm/Support/MathExtras.h" 22193323Sed#include <cassert> 23193323Sed#include <string> 24193323Sed 25193323Sednamespace llvm { 26193323Sed class Type; 27198090Srdivacky class LLVMContext; 28198090Srdivacky struct EVT; 29193323Sed 30263508Sdim /// MVT - Machine Value Type. Every type that is supported natively by some 31263508Sdim /// processor targeted by LLVM occurs here. This means that any legal value 32263508Sdim /// type can be represented by an MVT. 33218893Sdim class MVT { 34193323Sed public: 35193323Sed enum SimpleValueType { 36249423Sdim // INVALID_SIMPLE_VALUE_TYPE - Simple value types less than zero are 37249423Sdim // considered extended value types. 38249423Sdim INVALID_SIMPLE_VALUE_TYPE = -1, 39249423Sdim 40193323Sed // If you change this numbering, you must change the values in 41193323Sed // ValueTypes.td as well! 42193323Sed Other = 0, // This is a non-standard value 43193323Sed i1 = 1, // This is a 1 bit integer value 44193323Sed i8 = 2, // This is an 8 bit integer value 45193323Sed i16 = 3, // This is a 16 bit integer value 46193323Sed i32 = 4, // This is a 32 bit integer value 47193323Sed i64 = 5, // This is a 64 bit integer value 48193323Sed i128 = 6, // This is a 128 bit integer value 49193323Sed 50193323Sed FIRST_INTEGER_VALUETYPE = i1, 51193323Sed LAST_INTEGER_VALUETYPE = i128, 52193323Sed 53234353Sdim f16 = 7, // This is a 16 bit floating point value 54234353Sdim f32 = 8, // This is a 32 bit floating point value 55234353Sdim f64 = 9, // This is a 64 bit floating point value 56234353Sdim f80 = 10, // This is a 80 bit floating point value 57234353Sdim f128 = 11, // This is a 128 bit floating point value 58234353Sdim ppcf128 = 12, // This is a PPC 128-bit floating point value 59193323Sed 60234353Sdim FIRST_FP_VALUETYPE = f16, 61234353Sdim LAST_FP_VALUETYPE = ppcf128, 62193323Sed 63243830Sdim v2i1 = 13, // 2 x i1 64243830Sdim v4i1 = 14, // 4 x i1 65243830Sdim v8i1 = 15, // 8 x i1 66243830Sdim v16i1 = 16, // 16 x i1 67249423Sdim v32i1 = 17, // 32 x i1 68249423Sdim v64i1 = 18, // 64 x i1 69193323Sed 70263508Sdim v1i8 = 19, // 1 x i8 71263508Sdim v2i8 = 20, // 2 x i8 72263508Sdim v4i8 = 21, // 4 x i8 73263508Sdim v8i8 = 22, // 8 x i8 74263508Sdim v16i8 = 23, // 16 x i8 75263508Sdim v32i8 = 24, // 32 x i8 76263508Sdim v64i8 = 25, // 64 x i8 77263508Sdim v1i16 = 26, // 1 x i16 78263508Sdim v2i16 = 27, // 2 x i16 79263508Sdim v4i16 = 28, // 4 x i16 80263508Sdim v8i16 = 29, // 8 x i16 81263508Sdim v16i16 = 30, // 16 x i16 82263508Sdim v32i16 = 31, // 32 x i16 83263508Sdim v1i32 = 32, // 1 x i32 84263508Sdim v2i32 = 33, // 2 x i32 85263508Sdim v4i32 = 34, // 4 x i32 86263508Sdim v8i32 = 35, // 8 x i32 87263508Sdim v16i32 = 36, // 16 x i32 88263508Sdim v1i64 = 37, // 1 x i64 89263508Sdim v2i64 = 38, // 2 x i64 90263508Sdim v4i64 = 39, // 4 x i64 91263508Sdim v8i64 = 40, // 8 x i64 92263508Sdim v16i64 = 41, // 16 x i64 93234353Sdim 94243830Sdim FIRST_INTEGER_VECTOR_VALUETYPE = v2i1, 95239462Sdim LAST_INTEGER_VECTOR_VALUETYPE = v16i64, 96249423Sdim 97263508Sdim v2f16 = 42, // 2 x f16 98263508Sdim v4f16 = 43, // 4 x f16 99263508Sdim v8f16 = 44, // 8 x f16 100263508Sdim v1f32 = 45, // 1 x f32 101263508Sdim v2f32 = 46, // 2 x f32 102263508Sdim v4f32 = 47, // 4 x f32 103263508Sdim v8f32 = 48, // 8 x f32 104263508Sdim v16f32 = 49, // 16 x f32 105263508Sdim v1f64 = 50, // 1 x f64 106263508Sdim v2f64 = 51, // 2 x f64 107263508Sdim v4f64 = 52, // 4 x f64 108263508Sdim v8f64 = 53, // 8 x f64 109249423Sdim 110234353Sdim FIRST_FP_VECTOR_VALUETYPE = v2f16, 111249423Sdim LAST_FP_VECTOR_VALUETYPE = v8f64, 112193323Sed 113249423Sdim FIRST_VECTOR_VALUETYPE = v2i1, 114249423Sdim LAST_VECTOR_VALUETYPE = v8f64, 115200581Srdivacky 116263508Sdim x86mmx = 54, // This is an X86 MMX value 117200581Srdivacky 118263508Sdim Glue = 55, // This glues nodes together during pre-RA sched 119193323Sed 120263508Sdim isVoid = 56, // This has no value 121249423Sdim 122263508Sdim Untyped = 57, // This value takes a register, but has 123224145Sdim // unspecified type. The register class 124224145Sdim // will be determined by the opcode. 125218893Sdim 126263508Sdim LAST_VALUETYPE = 58, // This always remains at the end of the list. 127224145Sdim 128195098Sed // This is the current maximum for LAST_VALUETYPE. 129218893Sdim // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors 130195098Sed // This value must be a multiple of 32. 131195098Sed MAX_ALLOWED_VALUETYPE = 64, 132195098Sed 133198090Srdivacky // Metadata - This is MDNode or MDString. 134198090Srdivacky Metadata = 250, 135198090Srdivacky 136193323Sed // iPTRAny - An int value the size of the pointer of the current 137193323Sed // target to any address space. This must only be used internal to 138193323Sed // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR. 139198090Srdivacky iPTRAny = 251, 140193323Sed 141198090Srdivacky // vAny - A vector with any length and element size. This is used 142198090Srdivacky // for intrinsics that have overloadings based on vector types. 143198090Srdivacky // This is only for tblgen's consumption! 144198090Srdivacky vAny = 252, 145198090Srdivacky 146193323Sed // fAny - Any floating-point or vector floating-point value. This is used 147193323Sed // for intrinsics that have overloadings based on floating-point types. 148193323Sed // This is only for tblgen's consumption! 149198090Srdivacky fAny = 253, 150193323Sed 151193323Sed // iAny - An integer or vector integer value of any bit width. This is 152193323Sed // used for intrinsics that have overloadings based on integer bit widths. 153193323Sed // This is only for tblgen's consumption! 154198090Srdivacky iAny = 254, 155193323Sed 156193323Sed // iPTR - An int value the size of the pointer of the current 157193323Sed // target. This should only be used internal to tblgen! 158249423Sdim iPTR = 255 159193323Sed }; 160193323Sed 161198090Srdivacky SimpleValueType SimpleTy; 162193323Sed 163198090Srdivacky MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {} 164198090Srdivacky MVT(SimpleValueType SVT) : SimpleTy(SVT) { } 165218893Sdim 166198090Srdivacky bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; } 167198090Srdivacky bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; } 168198090Srdivacky bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; } 169218893Sdim bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; } 170198090Srdivacky bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; } 171198090Srdivacky bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; } 172218893Sdim 173198090Srdivacky /// isFloatingPoint - Return true if this is a FP, or a vector FP type. 174198090Srdivacky bool isFloatingPoint() const { 175234353Sdim return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE && 176234353Sdim SimpleTy <= MVT::LAST_FP_VALUETYPE) || 177239462Sdim (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE && 178239462Sdim SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE)); 179193323Sed } 180198090Srdivacky 181198090Srdivacky /// isInteger - Return true if this is an integer, or a vector integer type. 182198090Srdivacky bool isInteger() const { 183198090Srdivacky return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE && 184198090Srdivacky SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) || 185239462Sdim (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE && 186239462Sdim SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE)); 187193323Sed } 188193323Sed 189198090Srdivacky /// isVector - Return true if this is a vector value type. 190198090Srdivacky bool isVector() const { 191198090Srdivacky return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE && 192198090Srdivacky SimpleTy <= MVT::LAST_VECTOR_VALUETYPE); 193198090Srdivacky } 194218893Sdim 195243830Sdim /// is16BitVector - Return true if this is a 16-bit vector type. 196243830Sdim bool is16BitVector() const { 197243830Sdim return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 || 198243830Sdim SimpleTy == MVT::v16i1); 199243830Sdim } 200243830Sdim 201243830Sdim /// is32BitVector - Return true if this is a 32-bit vector type. 202243830Sdim bool is32BitVector() const { 203243830Sdim return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 || 204243830Sdim SimpleTy == MVT::v1i32); 205243830Sdim } 206243830Sdim 207239462Sdim /// is64BitVector - Return true if this is a 64-bit vector type. 208239462Sdim bool is64BitVector() const { 209239462Sdim return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 || 210239462Sdim SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 || 211263508Sdim SimpleTy == MVT::v1f64 || SimpleTy == MVT::v2f32); 212239462Sdim } 213239462Sdim 214239462Sdim /// is128BitVector - Return true if this is a 128-bit vector type. 215239462Sdim bool is128BitVector() const { 216239462Sdim return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 || 217239462Sdim SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 || 218239462Sdim SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64); 219239462Sdim } 220239462Sdim 221239462Sdim /// is256BitVector - Return true if this is a 256-bit vector type. 222239462Sdim bool is256BitVector() const { 223239462Sdim return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 || 224239462Sdim SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 || 225239462Sdim SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64); 226239462Sdim } 227239462Sdim 228239462Sdim /// is512BitVector - Return true if this is a 512-bit vector type. 229239462Sdim bool is512BitVector() const { 230249423Sdim return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 || 231249423Sdim SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 || 232249423Sdim SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32); 233239462Sdim } 234239462Sdim 235239462Sdim /// is1024BitVector - Return true if this is a 1024-bit vector type. 236239462Sdim bool is1024BitVector() const { 237239462Sdim return (SimpleTy == MVT::v16i64); 238239462Sdim } 239239462Sdim 240202375Srdivacky /// isPow2VectorType - Returns true if the given vector is a power of 2. 241198090Srdivacky bool isPow2VectorType() const { 242198090Srdivacky unsigned NElts = getVectorNumElements(); 243198090Srdivacky return !(NElts & (NElts - 1)); 244198090Srdivacky } 245198090Srdivacky 246218893Sdim /// getPow2VectorType - Widens the length of the given vector MVT up to 247198090Srdivacky /// the nearest power of 2 and returns that type. 248198090Srdivacky MVT getPow2VectorType() const { 249212904Sdim if (isPow2VectorType()) 250198090Srdivacky return *this; 251212904Sdim 252212904Sdim unsigned NElts = getVectorNumElements(); 253212904Sdim unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts); 254212904Sdim return MVT::getVectorVT(getVectorElementType(), Pow2NElts); 255198090Srdivacky } 256200581Srdivacky 257200581Srdivacky /// getScalarType - If this is a vector type, return the element type, 258200581Srdivacky /// otherwise return this. 259200581Srdivacky MVT getScalarType() const { 260200581Srdivacky return isVector() ? getVectorElementType() : *this; 261200581Srdivacky } 262218893Sdim 263198090Srdivacky MVT getVectorElementType() const { 264198090Srdivacky switch (SimpleTy) { 265198090Srdivacky default: 266239462Sdim llvm_unreachable("Not a vector MVT!"); 267243830Sdim case v2i1 : 268243830Sdim case v4i1 : 269243830Sdim case v8i1 : 270249423Sdim case v16i1 : 271249423Sdim case v32i1 : 272249423Sdim case v64i1: return i1; 273263508Sdim case v1i8 : 274198090Srdivacky case v2i8 : 275198090Srdivacky case v4i8 : 276198090Srdivacky case v8i8 : 277198090Srdivacky case v16i8: 278249423Sdim case v32i8: 279249423Sdim case v64i8: return i8; 280243830Sdim case v1i16: 281198090Srdivacky case v2i16: 282198090Srdivacky case v4i16: 283198090Srdivacky case v8i16: 284249423Sdim case v16i16: 285249423Sdim case v32i16: return i16; 286243830Sdim case v1i32: 287198090Srdivacky case v2i32: 288198090Srdivacky case v4i32: 289239462Sdim case v8i32: 290239462Sdim case v16i32: return i32; 291198090Srdivacky case v1i64: 292198090Srdivacky case v2i64: 293208599Srdivacky case v4i64: 294239462Sdim case v8i64: 295239462Sdim case v16i64: return i64; 296263508Sdim case v2f16: 297263508Sdim case v4f16: 298263508Sdim case v8f16: return f16; 299263508Sdim case v1f32: 300198090Srdivacky case v2f32: 301198090Srdivacky case v4f32: 302249423Sdim case v8f32: 303249423Sdim case v16f32: return f32; 304263508Sdim case v1f64: 305198090Srdivacky case v2f64: 306249423Sdim case v4f64: 307249423Sdim case v8f64: return f64; 308198090Srdivacky } 309198090Srdivacky } 310218893Sdim 311198090Srdivacky unsigned getVectorNumElements() const { 312198090Srdivacky switch (SimpleTy) { 313198090Srdivacky default: 314239462Sdim llvm_unreachable("Not a vector MVT!"); 315249423Sdim case v32i1: 316249423Sdim case v32i8: 317249423Sdim case v32i16: return 32; 318249423Sdim case v64i1: 319249423Sdim case v64i8: return 64; 320243830Sdim case v16i1: 321198090Srdivacky case v16i8: 322239462Sdim case v16i16: 323239462Sdim case v16i32: 324249423Sdim case v16i64: 325249423Sdim case v16f32: return 16; 326249423Sdim case v8i1 : 327198090Srdivacky case v8i8 : 328198090Srdivacky case v8i16: 329198090Srdivacky case v8i32: 330208599Srdivacky case v8i64: 331263508Sdim case v8f16: 332249423Sdim case v8f32: 333249423Sdim case v8f64: return 8; 334243830Sdim case v4i1: 335198090Srdivacky case v4i8: 336198090Srdivacky case v4i16: 337198090Srdivacky case v4i32: 338198090Srdivacky case v4i64: 339263508Sdim case v4f16: 340198090Srdivacky case v4f32: 341198090Srdivacky case v4f64: return 4; 342243830Sdim case v2i1: 343198090Srdivacky case v2i8: 344198090Srdivacky case v2i16: 345198090Srdivacky case v2i32: 346198090Srdivacky case v2i64: 347234353Sdim case v2f16: 348198090Srdivacky case v2f32: 349198090Srdivacky case v2f64: return 2; 350263508Sdim case v1i8: 351243830Sdim case v1i16: 352243830Sdim case v1i32: 353263508Sdim case v1i64: 354263508Sdim case v1f32: 355263508Sdim case v1f64: return 1; 356198090Srdivacky } 357198090Srdivacky } 358218893Sdim 359198090Srdivacky unsigned getSizeInBits() const { 360198090Srdivacky switch (SimpleTy) { 361263508Sdim default: 362263508Sdim llvm_unreachable("getSizeInBits called on extended MVT."); 363263508Sdim case Other: 364263508Sdim llvm_unreachable("Value type is non-standard value, Other."); 365198090Srdivacky case iPTR: 366234353Sdim llvm_unreachable("Value type size is target-dependent. Ask TLI."); 367198090Srdivacky case iPTRAny: 368198090Srdivacky case iAny: 369198090Srdivacky case fAny: 370249423Sdim case vAny: 371234353Sdim llvm_unreachable("Value type is overloaded."); 372249423Sdim case Metadata: 373249423Sdim llvm_unreachable("Value type is metadata."); 374198090Srdivacky case i1 : return 1; 375243830Sdim case v2i1: return 2; 376243830Sdim case v4i1: return 4; 377243830Sdim case i8 : 378263508Sdim case v1i8: 379243830Sdim case v8i1: return 8; 380198090Srdivacky case i16 : 381234353Sdim case f16: 382243830Sdim case v16i1: 383243830Sdim case v2i8: 384243830Sdim case v1i16: return 16; 385198090Srdivacky case f32 : 386198090Srdivacky case i32 : 387249423Sdim case v32i1: 388198090Srdivacky case v4i8: 389234353Sdim case v2i16: 390249423Sdim case v2f16: 391263508Sdim case v1f32: 392243830Sdim case v1i32: return 32; 393218893Sdim case x86mmx: 394198090Srdivacky case f64 : 395198090Srdivacky case i64 : 396249423Sdim case v64i1: 397198090Srdivacky case v8i8: 398198090Srdivacky case v4i16: 399198090Srdivacky case v2i32: 400198090Srdivacky case v1i64: 401263508Sdim case v4f16: 402263508Sdim case v2f32: 403263508Sdim case v1f64: return 64; 404198090Srdivacky case f80 : return 80; 405198090Srdivacky case f128: 406198090Srdivacky case ppcf128: 407198090Srdivacky case i128: 408198090Srdivacky case v16i8: 409198090Srdivacky case v8i16: 410198090Srdivacky case v4i32: 411198090Srdivacky case v2i64: 412263508Sdim case v8f16: 413198090Srdivacky case v4f32: 414198090Srdivacky case v2f64: return 128; 415198090Srdivacky case v32i8: 416198090Srdivacky case v16i16: 417198090Srdivacky case v8i32: 418198090Srdivacky case v4i64: 419198090Srdivacky case v8f32: 420198090Srdivacky case v4f64: return 256; 421249423Sdim case v64i8: 422249423Sdim case v32i16: 423239462Sdim case v16i32: 424249423Sdim case v8i64: 425249423Sdim case v16f32: 426249423Sdim case v8f64: return 512; 427239462Sdim case v16i64:return 1024; 428198090Srdivacky } 429198090Srdivacky } 430218893Sdim 431218893Sdim /// getStoreSize - Return the number of bytes overwritten by a store 432218893Sdim /// of the specified value type. 433218893Sdim unsigned getStoreSize() const { 434218893Sdim return (getSizeInBits() + 7) / 8; 435218893Sdim } 436218893Sdim 437218893Sdim /// getStoreSizeInBits - Return the number of bits overwritten by a store 438218893Sdim /// of the specified value type. 439218893Sdim unsigned getStoreSizeInBits() const { 440218893Sdim return getStoreSize() * 8; 441218893Sdim } 442218893Sdim 443249423Sdim /// Return true if this has more bits than VT. 444249423Sdim bool bitsGT(MVT VT) const { 445249423Sdim return getSizeInBits() > VT.getSizeInBits(); 446249423Sdim } 447249423Sdim 448249423Sdim /// Return true if this has no less bits than VT. 449249423Sdim bool bitsGE(MVT VT) const { 450249423Sdim return getSizeInBits() >= VT.getSizeInBits(); 451249423Sdim } 452249423Sdim 453249423Sdim /// Return true if this has less bits than VT. 454249423Sdim bool bitsLT(MVT VT) const { 455249423Sdim return getSizeInBits() < VT.getSizeInBits(); 456249423Sdim } 457249423Sdim 458249423Sdim /// Return true if this has no more bits than VT. 459249423Sdim bool bitsLE(MVT VT) const { 460249423Sdim return getSizeInBits() <= VT.getSizeInBits(); 461249423Sdim } 462249423Sdim 463249423Sdim 464193323Sed static MVT getFloatingPointVT(unsigned BitWidth) { 465193323Sed switch (BitWidth) { 466193323Sed default: 467234353Sdim llvm_unreachable("Bad bit width!"); 468234353Sdim case 16: 469234353Sdim return MVT::f16; 470193323Sed case 32: 471198090Srdivacky return MVT::f32; 472193323Sed case 64: 473198090Srdivacky return MVT::f64; 474193323Sed case 80: 475198090Srdivacky return MVT::f80; 476193323Sed case 128: 477198090Srdivacky return MVT::f128; 478193323Sed } 479193323Sed } 480218893Sdim 481193323Sed static MVT getIntegerVT(unsigned BitWidth) { 482193323Sed switch (BitWidth) { 483193323Sed default: 484198090Srdivacky return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE); 485193323Sed case 1: 486198090Srdivacky return MVT::i1; 487193323Sed case 8: 488198090Srdivacky return MVT::i8; 489193323Sed case 16: 490198090Srdivacky return MVT::i16; 491193323Sed case 32: 492198090Srdivacky return MVT::i32; 493193323Sed case 64: 494198090Srdivacky return MVT::i64; 495193323Sed case 128: 496198090Srdivacky return MVT::i128; 497193323Sed } 498193323Sed } 499218893Sdim 500193323Sed static MVT getVectorVT(MVT VT, unsigned NumElements) { 501198090Srdivacky switch (VT.SimpleTy) { 502193323Sed default: 503193323Sed break; 504243830Sdim case MVT::i1: 505243830Sdim if (NumElements == 2) return MVT::v2i1; 506243830Sdim if (NumElements == 4) return MVT::v4i1; 507243830Sdim if (NumElements == 8) return MVT::v8i1; 508243830Sdim if (NumElements == 16) return MVT::v16i1; 509249423Sdim if (NumElements == 32) return MVT::v32i1; 510249423Sdim if (NumElements == 64) return MVT::v64i1; 511243830Sdim break; 512198090Srdivacky case MVT::i8: 513263508Sdim if (NumElements == 1) return MVT::v1i8; 514198090Srdivacky if (NumElements == 2) return MVT::v2i8; 515198090Srdivacky if (NumElements == 4) return MVT::v4i8; 516198090Srdivacky if (NumElements == 8) return MVT::v8i8; 517198090Srdivacky if (NumElements == 16) return MVT::v16i8; 518198090Srdivacky if (NumElements == 32) return MVT::v32i8; 519249423Sdim if (NumElements == 64) return MVT::v64i8; 520193323Sed break; 521198090Srdivacky case MVT::i16: 522243830Sdim if (NumElements == 1) return MVT::v1i16; 523198090Srdivacky if (NumElements == 2) return MVT::v2i16; 524198090Srdivacky if (NumElements == 4) return MVT::v4i16; 525198090Srdivacky if (NumElements == 8) return MVT::v8i16; 526198090Srdivacky if (NumElements == 16) return MVT::v16i16; 527249423Sdim if (NumElements == 32) return MVT::v32i16; 528193323Sed break; 529198090Srdivacky case MVT::i32: 530243830Sdim if (NumElements == 1) return MVT::v1i32; 531198090Srdivacky if (NumElements == 2) return MVT::v2i32; 532198090Srdivacky if (NumElements == 4) return MVT::v4i32; 533198090Srdivacky if (NumElements == 8) return MVT::v8i32; 534239462Sdim if (NumElements == 16) return MVT::v16i32; 535193323Sed break; 536198090Srdivacky case MVT::i64: 537198090Srdivacky if (NumElements == 1) return MVT::v1i64; 538198090Srdivacky if (NumElements == 2) return MVT::v2i64; 539198090Srdivacky if (NumElements == 4) return MVT::v4i64; 540208599Srdivacky if (NumElements == 8) return MVT::v8i64; 541239462Sdim if (NumElements == 16) return MVT::v16i64; 542193323Sed break; 543234353Sdim case MVT::f16: 544234353Sdim if (NumElements == 2) return MVT::v2f16; 545263508Sdim if (NumElements == 4) return MVT::v4f16; 546263508Sdim if (NumElements == 8) return MVT::v8f16; 547234353Sdim break; 548198090Srdivacky case MVT::f32: 549263508Sdim if (NumElements == 1) return MVT::v1f32; 550198090Srdivacky if (NumElements == 2) return MVT::v2f32; 551198090Srdivacky if (NumElements == 4) return MVT::v4f32; 552198090Srdivacky if (NumElements == 8) return MVT::v8f32; 553249423Sdim if (NumElements == 16) return MVT::v16f32; 554193323Sed break; 555198090Srdivacky case MVT::f64: 556263508Sdim if (NumElements == 1) return MVT::v1f64; 557198090Srdivacky if (NumElements == 2) return MVT::v2f64; 558198090Srdivacky if (NumElements == 4) return MVT::v4f64; 559249423Sdim if (NumElements == 8) return MVT::v8f64; 560193323Sed break; 561193323Sed } 562198090Srdivacky return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE); 563193323Sed } 564249423Sdim 565249423Sdim /// Return the value type corresponding to the specified type. This returns 566249423Sdim /// all pointers as iPTR. If HandleUnknown is true, unknown types are 567249423Sdim /// returned as Other, otherwise they are invalid. 568249423Sdim static MVT getVT(Type *Ty, bool HandleUnknown = false); 569249423Sdim 570198090Srdivacky }; 571193323Sed 572218893Sdim 573218893Sdim /// EVT - Extended Value Type. Capable of holding value types which are not 574218893Sdim /// native for any processor (such as the i12345 type), as well as the types 575218893Sdim /// a MVT can represent. 576218893Sdim struct EVT { 577198090Srdivacky private: 578198090Srdivacky MVT V; 579226633Sdim Type *LLVMTy; 580198090Srdivacky 581198090Srdivacky public: 582198090Srdivacky EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)), 583198090Srdivacky LLVMTy(0) {} 584198090Srdivacky EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { } 585198090Srdivacky EVT(MVT S) : V(S), LLVMTy(0) {} 586198090Srdivacky 587212904Sdim bool operator==(EVT VT) const { 588212904Sdim return !(*this != VT); 589212904Sdim } 590212904Sdim bool operator!=(EVT VT) const { 591212904Sdim if (V.SimpleTy != VT.V.SimpleTy) 592198090Srdivacky return true; 593249423Sdim if (V.SimpleTy < 0) 594212904Sdim return LLVMTy != VT.LLVMTy; 595198090Srdivacky return false; 596198090Srdivacky } 597198090Srdivacky 598198090Srdivacky /// getFloatingPointVT - Returns the EVT that represents a floating point 599198090Srdivacky /// type with the given number of bits. There are two floating point types 600198090Srdivacky /// with 128 bits - this returns f128 rather than ppcf128. 601198090Srdivacky static EVT getFloatingPointVT(unsigned BitWidth) { 602198090Srdivacky return MVT::getFloatingPointVT(BitWidth); 603198090Srdivacky } 604198090Srdivacky 605198090Srdivacky /// getIntegerVT - Returns the EVT that represents an integer with the given 606198090Srdivacky /// number of bits. 607198090Srdivacky static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) { 608198090Srdivacky MVT M = MVT::getIntegerVT(BitWidth); 609249423Sdim if (M.SimpleTy >= 0) 610198090Srdivacky return M; 611212904Sdim return getExtendedIntegerVT(Context, BitWidth); 612198090Srdivacky } 613198090Srdivacky 614198090Srdivacky /// getVectorVT - Returns the EVT that represents a vector NumElements in 615198090Srdivacky /// length, where each element is of type VT. 616198090Srdivacky static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) { 617198090Srdivacky MVT M = MVT::getVectorVT(VT.V, NumElements); 618249423Sdim if (M.SimpleTy >= 0) 619198090Srdivacky return M; 620212904Sdim return getExtendedVectorVT(Context, VT, NumElements); 621198090Srdivacky } 622198090Srdivacky 623226633Sdim /// changeVectorElementTypeToInteger - Return a vector with the same number 624226633Sdim /// of elements as this vector, but with the element type converted to an 625226633Sdim /// integer type with the same bitwidth. 626226633Sdim EVT changeVectorElementTypeToInteger() const { 627226633Sdim if (!isSimple()) 628226633Sdim return changeExtendedVectorElementTypeToInteger(); 629226633Sdim MVT EltTy = getSimpleVT().getVectorElementType(); 630226633Sdim unsigned BitWidth = EltTy.getSizeInBits(); 631226633Sdim MVT IntTy = MVT::getIntegerVT(BitWidth); 632226633Sdim MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements()); 633249423Sdim assert(VecTy.SimpleTy >= 0 && 634226633Sdim "Simple vector VT not representable by simple integer vector VT!"); 635226633Sdim return VecTy; 636226633Sdim } 637226633Sdim 638198090Srdivacky /// isSimple - Test if the given EVT is simple (as opposed to being 639193323Sed /// extended). 640193323Sed bool isSimple() const { 641249423Sdim return V.SimpleTy >= 0; 642193323Sed } 643193323Sed 644198090Srdivacky /// isExtended - Test if the given EVT is extended (as opposed to 645193323Sed /// being simple). 646193323Sed bool isExtended() const { 647193323Sed return !isSimple(); 648193323Sed } 649193323Sed 650193323Sed /// isFloatingPoint - Return true if this is a FP, or a vector FP type. 651193323Sed bool isFloatingPoint() const { 652202375Srdivacky return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint(); 653193323Sed } 654193323Sed 655193323Sed /// isInteger - Return true if this is an integer, or a vector integer type. 656193323Sed bool isInteger() const { 657202375Srdivacky return isSimple() ? V.isInteger() : isExtendedInteger(); 658193323Sed } 659193323Sed 660193323Sed /// isVector - Return true if this is a vector value type. 661193323Sed bool isVector() const { 662202375Srdivacky return isSimple() ? V.isVector() : isExtendedVector(); 663193323Sed } 664193323Sed 665243830Sdim /// is16BitVector - Return true if this is a 16-bit vector type. 666243830Sdim bool is16BitVector() const { 667243830Sdim return isSimple() ? V.is16BitVector() : isExtended16BitVector(); 668243830Sdim } 669243830Sdim 670243830Sdim /// is32BitVector - Return true if this is a 32-bit vector type. 671243830Sdim bool is32BitVector() const { 672243830Sdim return isSimple() ? V.is32BitVector() : isExtended32BitVector(); 673243830Sdim } 674243830Sdim 675193323Sed /// is64BitVector - Return true if this is a 64-bit vector type. 676193323Sed bool is64BitVector() const { 677239462Sdim return isSimple() ? V.is64BitVector() : isExtended64BitVector(); 678193323Sed } 679193323Sed 680193323Sed /// is128BitVector - Return true if this is a 128-bit vector type. 681193323Sed bool is128BitVector() const { 682239462Sdim return isSimple() ? V.is128BitVector() : isExtended128BitVector(); 683193323Sed } 684193323Sed 685195340Sed /// is256BitVector - Return true if this is a 256-bit vector type. 686239462Sdim bool is256BitVector() const { 687239462Sdim return isSimple() ? V.is256BitVector() : isExtended256BitVector(); 688195340Sed } 689195340Sed 690208599Srdivacky /// is512BitVector - Return true if this is a 512-bit vector type. 691239462Sdim bool is512BitVector() const { 692239462Sdim return isSimple() ? V.is512BitVector() : isExtended512BitVector(); 693208599Srdivacky } 694208599Srdivacky 695239462Sdim /// is1024BitVector - Return true if this is a 1024-bit vector type. 696239462Sdim bool is1024BitVector() const { 697239462Sdim return isSimple() ? V.is1024BitVector() : isExtended1024BitVector(); 698239462Sdim } 699239462Sdim 700198090Srdivacky /// isOverloaded - Return true if this is an overloaded type for TableGen. 701198090Srdivacky bool isOverloaded() const { 702198090Srdivacky return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny); 703198090Srdivacky } 704198090Srdivacky 705193323Sed /// isByteSized - Return true if the bit size is a multiple of 8. 706193323Sed bool isByteSized() const { 707193323Sed return (getSizeInBits() & 7) == 0; 708193323Sed } 709193323Sed 710193323Sed /// isRound - Return true if the size is a power-of-two number of bytes. 711193323Sed bool isRound() const { 712193323Sed unsigned BitSize = getSizeInBits(); 713193323Sed return BitSize >= 8 && !(BitSize & (BitSize - 1)); 714193323Sed } 715193323Sed 716193323Sed /// bitsEq - Return true if this has the same number of bits as VT. 717198090Srdivacky bool bitsEq(EVT VT) const { 718203954Srdivacky if (EVT::operator==(VT)) return true; 719193323Sed return getSizeInBits() == VT.getSizeInBits(); 720193323Sed } 721193323Sed 722193323Sed /// bitsGT - Return true if this has more bits than VT. 723198090Srdivacky bool bitsGT(EVT VT) const { 724203954Srdivacky if (EVT::operator==(VT)) return false; 725193323Sed return getSizeInBits() > VT.getSizeInBits(); 726193323Sed } 727193323Sed 728193323Sed /// bitsGE - Return true if this has no less bits than VT. 729198090Srdivacky bool bitsGE(EVT VT) const { 730203954Srdivacky if (EVT::operator==(VT)) return true; 731193323Sed return getSizeInBits() >= VT.getSizeInBits(); 732193323Sed } 733193323Sed 734193323Sed /// bitsLT - Return true if this has less bits than VT. 735198090Srdivacky bool bitsLT(EVT VT) const { 736203954Srdivacky if (EVT::operator==(VT)) return false; 737193323Sed return getSizeInBits() < VT.getSizeInBits(); 738193323Sed } 739193323Sed 740193323Sed /// bitsLE - Return true if this has no more bits than VT. 741198090Srdivacky bool bitsLE(EVT VT) const { 742203954Srdivacky if (EVT::operator==(VT)) return true; 743193323Sed return getSizeInBits() <= VT.getSizeInBits(); 744193323Sed } 745193323Sed 746193323Sed 747193323Sed /// getSimpleVT - Return the SimpleValueType held in the specified 748198090Srdivacky /// simple EVT. 749198090Srdivacky MVT getSimpleVT() const { 750193323Sed assert(isSimple() && "Expected a SimpleValueType!"); 751198090Srdivacky return V; 752193323Sed } 753193323Sed 754200581Srdivacky /// getScalarType - If this is a vector type, return the element type, 755200581Srdivacky /// otherwise return this. 756200581Srdivacky EVT getScalarType() const { 757200581Srdivacky return isVector() ? getVectorElementType() : *this; 758200581Srdivacky } 759218893Sdim 760193323Sed /// getVectorElementType - Given a vector type, return the type of 761193323Sed /// each element. 762198090Srdivacky EVT getVectorElementType() const { 763193323Sed assert(isVector() && "Invalid vector type!"); 764198090Srdivacky if (isSimple()) 765198090Srdivacky return V.getVectorElementType(); 766212904Sdim return getExtendedVectorElementType(); 767193323Sed } 768193323Sed 769193323Sed /// getVectorNumElements - Given a vector type, return the number of 770193323Sed /// elements it contains. 771193323Sed unsigned getVectorNumElements() const { 772193323Sed assert(isVector() && "Invalid vector type!"); 773198090Srdivacky if (isSimple()) 774198090Srdivacky return V.getVectorNumElements(); 775212904Sdim return getExtendedVectorNumElements(); 776193323Sed } 777193323Sed 778193323Sed /// getSizeInBits - Return the size of the specified value type in bits. 779193323Sed unsigned getSizeInBits() const { 780198090Srdivacky if (isSimple()) 781198090Srdivacky return V.getSizeInBits(); 782212904Sdim return getExtendedSizeInBits(); 783193323Sed } 784193323Sed 785198090Srdivacky /// getStoreSize - Return the number of bytes overwritten by a store 786198090Srdivacky /// of the specified value type. 787198090Srdivacky unsigned getStoreSize() const { 788198090Srdivacky return (getSizeInBits() + 7) / 8; 789198090Srdivacky } 790198090Srdivacky 791193323Sed /// getStoreSizeInBits - Return the number of bits overwritten by a store 792193323Sed /// of the specified value type. 793193323Sed unsigned getStoreSizeInBits() const { 794198090Srdivacky return getStoreSize() * 8; 795193323Sed } 796193323Sed 797198090Srdivacky /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up 798193323Sed /// to the nearest power of two (and at least to eight), and returns the 799198090Srdivacky /// integer EVT with that number of bits. 800198090Srdivacky EVT getRoundIntegerType(LLVMContext &Context) const { 801193323Sed assert(isInteger() && !isVector() && "Invalid integer type!"); 802193323Sed unsigned BitWidth = getSizeInBits(); 803193323Sed if (BitWidth <= 8) 804198090Srdivacky return EVT(MVT::i8); 805212904Sdim return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth)); 806193323Sed } 807193323Sed 808201360Srdivacky /// getHalfSizedIntegerVT - Finds the smallest simple value type that is 809201360Srdivacky /// greater than or equal to half the width of this EVT. If no simple 810201360Srdivacky /// value type can be found, an extended integer value type of half the 811201360Srdivacky /// size (rounded up) is returned. 812201360Srdivacky EVT getHalfSizedIntegerVT(LLVMContext &Context) const { 813201360Srdivacky assert(isInteger() && !isVector() && "Invalid integer type!"); 814201360Srdivacky unsigned EVTSize = getSizeInBits(); 815201360Srdivacky for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE; 816212904Sdim IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) { 817201360Srdivacky EVT HalfVT = EVT((MVT::SimpleValueType)IntVT); 818212904Sdim if (HalfVT.getSizeInBits() * 2 >= EVTSize) 819201360Srdivacky return HalfVT; 820201360Srdivacky } 821201360Srdivacky return getIntegerVT(Context, (EVTSize + 1) / 2); 822201360Srdivacky } 823201360Srdivacky 824201360Srdivacky /// isPow2VectorType - Returns true if the given vector is a power of 2. 825193323Sed bool isPow2VectorType() const { 826193323Sed unsigned NElts = getVectorNumElements(); 827193323Sed return !(NElts & (NElts - 1)); 828193323Sed } 829193323Sed 830198090Srdivacky /// getPow2VectorType - Widens the length of the given vector EVT up to 831193323Sed /// the nearest power of 2 and returns that type. 832198090Srdivacky EVT getPow2VectorType(LLVMContext &Context) const { 833193323Sed if (!isPow2VectorType()) { 834193323Sed unsigned NElts = getVectorNumElements(); 835193323Sed unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts); 836198090Srdivacky return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts); 837193323Sed } 838193323Sed else { 839193323Sed return *this; 840193323Sed } 841193323Sed } 842193323Sed 843198090Srdivacky /// getEVTString - This function returns value type as a string, 844193323Sed /// e.g. "i32". 845198090Srdivacky std::string getEVTString() const; 846193323Sed 847198090Srdivacky /// getTypeForEVT - This method returns an LLVM type corresponding to the 848198090Srdivacky /// specified EVT. For integer types, this returns an unsigned type. Note 849193323Sed /// that this will abort for types that cannot be represented. 850226633Sdim Type *getTypeForEVT(LLVMContext &Context) const; 851193323Sed 852198090Srdivacky /// getEVT - Return the value type corresponding to the specified type. 853193323Sed /// This returns all pointers as iPTR. If HandleUnknown is true, unknown 854193323Sed /// types are returned as Other, otherwise they are invalid. 855226633Sdim static EVT getEVT(Type *Ty, bool HandleUnknown = false); 856193323Sed 857249423Sdim intptr_t getRawBits() const { 858202375Srdivacky if (isSimple()) 859198090Srdivacky return V.SimpleTy; 860198090Srdivacky else 861198090Srdivacky return (intptr_t)(LLVMTy); 862198090Srdivacky } 863193323Sed 864193323Sed /// compareRawBits - A meaningless but well-behaved order, useful for 865193323Sed /// constructing containers. 866193323Sed struct compareRawBits { 867198090Srdivacky bool operator()(EVT L, EVT R) const { 868198090Srdivacky if (L.V.SimpleTy == R.V.SimpleTy) 869198090Srdivacky return L.LLVMTy < R.LLVMTy; 870198090Srdivacky else 871198090Srdivacky return L.V.SimpleTy < R.V.SimpleTy; 872193323Sed } 873193323Sed }; 874193323Sed 875193323Sed private: 876193323Sed // Methods for handling the Extended-type case in functions above. 877193323Sed // These are all out-of-line to prevent users of this header file 878193323Sed // from having a dependency on Type.h. 879226633Sdim EVT changeExtendedVectorElementTypeToInteger() const; 880198090Srdivacky static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth); 881198090Srdivacky static EVT getExtendedVectorVT(LLVMContext &C, EVT VT, 882198090Srdivacky unsigned NumElements); 883193323Sed bool isExtendedFloatingPoint() const; 884193323Sed bool isExtendedInteger() const; 885193323Sed bool isExtendedVector() const; 886243830Sdim bool isExtended16BitVector() const; 887243830Sdim bool isExtended32BitVector() const; 888193323Sed bool isExtended64BitVector() const; 889193323Sed bool isExtended128BitVector() const; 890195340Sed bool isExtended256BitVector() const; 891208599Srdivacky bool isExtended512BitVector() const; 892239462Sdim bool isExtended1024BitVector() const; 893198090Srdivacky EVT getExtendedVectorElementType() const; 894193323Sed unsigned getExtendedVectorNumElements() const; 895193323Sed unsigned getExtendedSizeInBits() const; 896193323Sed }; 897193323Sed 898193323Sed} // End llvm namespace 899193323Sed 900193323Sed#endif 901