ValueTypes.h revision 249423
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 30218893Sdim /// MVT - Machine Value Type. Every type that is supported natively by some 31218893Sdim /// processor targeted by LLVM occurs here. This means that any legal value 32218893Sdim /// type can be represented by a 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 70249423Sdim v2i8 = 19, // 2 x i8 71249423Sdim v4i8 = 20, // 4 x i8 72249423Sdim v8i8 = 21, // 8 x i8 73249423Sdim v16i8 = 22, // 16 x i8 74249423Sdim v32i8 = 23, // 32 x i8 75249423Sdim v64i8 = 24, // 64 x i8 76249423Sdim v1i16 = 25, // 1 x i16 77249423Sdim v2i16 = 26, // 2 x i16 78249423Sdim v4i16 = 27, // 4 x i16 79249423Sdim v8i16 = 28, // 8 x i16 80249423Sdim v16i16 = 29, // 16 x i16 81249423Sdim v32i16 = 30, // 32 x i16 82249423Sdim v1i32 = 31, // 1 x i32 83249423Sdim v2i32 = 32, // 2 x i32 84249423Sdim v4i32 = 33, // 4 x i32 85249423Sdim v8i32 = 34, // 8 x i32 86249423Sdim v16i32 = 35, // 16 x i32 87249423Sdim v1i64 = 36, // 1 x i64 88249423Sdim v2i64 = 37, // 2 x i64 89249423Sdim v4i64 = 38, // 4 x i64 90249423Sdim v8i64 = 39, // 8 x i64 91249423Sdim v16i64 = 40, // 16 x i64 92234353Sdim 93243830Sdim FIRST_INTEGER_VECTOR_VALUETYPE = v2i1, 94239462Sdim LAST_INTEGER_VECTOR_VALUETYPE = v16i64, 95249423Sdim 96249423Sdim v2f16 = 41, // 2 x f16 97249423Sdim v2f32 = 42, // 2 x f32 98249423Sdim v4f32 = 43, // 4 x f32 99249423Sdim v8f32 = 44, // 8 x f32 100249423Sdim v16f32 = 45, // 16 x f32 101249423Sdim v2f64 = 46, // 2 x f64 102249423Sdim v4f64 = 47, // 4 x f64 103249423Sdim v8f64 = 48, // 8 x f64 104249423Sdim 105234353Sdim FIRST_FP_VECTOR_VALUETYPE = v2f16, 106249423Sdim LAST_FP_VECTOR_VALUETYPE = v8f64, 107193323Sed 108249423Sdim FIRST_VECTOR_VALUETYPE = v2i1, 109249423Sdim LAST_VECTOR_VALUETYPE = v8f64, 110200581Srdivacky 111249423Sdim x86mmx = 49, // This is an X86 MMX value 112200581Srdivacky 113249423Sdim Glue = 50, // This glues nodes together during pre-RA sched 114193323Sed 115249423Sdim isVoid = 51, // This has no value 116249423Sdim 117249423Sdim Untyped = 52, // This value takes a register, but has 118224145Sdim // unspecified type. The register class 119224145Sdim // will be determined by the opcode. 120218893Sdim 121249423Sdim LAST_VALUETYPE = 53, // This always remains at the end of the list. 122224145Sdim 123195098Sed // This is the current maximum for LAST_VALUETYPE. 124218893Sdim // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors 125195098Sed // This value must be a multiple of 32. 126195098Sed MAX_ALLOWED_VALUETYPE = 64, 127195098Sed 128198090Srdivacky // Metadata - This is MDNode or MDString. 129198090Srdivacky Metadata = 250, 130198090Srdivacky 131193323Sed // iPTRAny - An int value the size of the pointer of the current 132193323Sed // target to any address space. This must only be used internal to 133193323Sed // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR. 134198090Srdivacky iPTRAny = 251, 135193323Sed 136198090Srdivacky // vAny - A vector with any length and element size. This is used 137198090Srdivacky // for intrinsics that have overloadings based on vector types. 138198090Srdivacky // This is only for tblgen's consumption! 139198090Srdivacky vAny = 252, 140198090Srdivacky 141193323Sed // fAny - Any floating-point or vector floating-point value. This is used 142193323Sed // for intrinsics that have overloadings based on floating-point types. 143193323Sed // This is only for tblgen's consumption! 144198090Srdivacky fAny = 253, 145193323Sed 146193323Sed // iAny - An integer or vector integer value of any bit width. This is 147193323Sed // used for intrinsics that have overloadings based on integer bit widths. 148193323Sed // This is only for tblgen's consumption! 149198090Srdivacky iAny = 254, 150193323Sed 151193323Sed // iPTR - An int value the size of the pointer of the current 152193323Sed // target. This should only be used internal to tblgen! 153249423Sdim iPTR = 255 154193323Sed }; 155193323Sed 156198090Srdivacky SimpleValueType SimpleTy; 157193323Sed 158198090Srdivacky MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {} 159198090Srdivacky MVT(SimpleValueType SVT) : SimpleTy(SVT) { } 160218893Sdim 161198090Srdivacky bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; } 162198090Srdivacky bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; } 163198090Srdivacky bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; } 164218893Sdim bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; } 165198090Srdivacky bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; } 166198090Srdivacky bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; } 167218893Sdim 168198090Srdivacky /// isFloatingPoint - Return true if this is a FP, or a vector FP type. 169198090Srdivacky bool isFloatingPoint() const { 170234353Sdim return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE && 171234353Sdim SimpleTy <= MVT::LAST_FP_VALUETYPE) || 172239462Sdim (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE && 173239462Sdim SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE)); 174193323Sed } 175198090Srdivacky 176198090Srdivacky /// isInteger - Return true if this is an integer, or a vector integer type. 177198090Srdivacky bool isInteger() const { 178198090Srdivacky return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE && 179198090Srdivacky SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) || 180239462Sdim (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE && 181239462Sdim SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE)); 182193323Sed } 183193323Sed 184198090Srdivacky /// isVector - Return true if this is a vector value type. 185198090Srdivacky bool isVector() const { 186198090Srdivacky return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE && 187198090Srdivacky SimpleTy <= MVT::LAST_VECTOR_VALUETYPE); 188198090Srdivacky } 189218893Sdim 190243830Sdim /// is16BitVector - Return true if this is a 16-bit vector type. 191243830Sdim bool is16BitVector() const { 192243830Sdim return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 || 193243830Sdim SimpleTy == MVT::v16i1); 194243830Sdim } 195243830Sdim 196243830Sdim /// is32BitVector - Return true if this is a 32-bit vector type. 197243830Sdim bool is32BitVector() const { 198243830Sdim return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 || 199243830Sdim SimpleTy == MVT::v1i32); 200243830Sdim } 201243830Sdim 202239462Sdim /// is64BitVector - Return true if this is a 64-bit vector type. 203239462Sdim bool is64BitVector() const { 204239462Sdim return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 || 205239462Sdim SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 || 206239462Sdim SimpleTy == MVT::v2f32); 207239462Sdim } 208239462Sdim 209239462Sdim /// is128BitVector - Return true if this is a 128-bit vector type. 210239462Sdim bool is128BitVector() const { 211239462Sdim return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 || 212239462Sdim SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 || 213239462Sdim SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64); 214239462Sdim } 215239462Sdim 216239462Sdim /// is256BitVector - Return true if this is a 256-bit vector type. 217239462Sdim bool is256BitVector() const { 218239462Sdim return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 || 219239462Sdim SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 || 220239462Sdim SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64); 221239462Sdim } 222239462Sdim 223239462Sdim /// is512BitVector - Return true if this is a 512-bit vector type. 224239462Sdim bool is512BitVector() const { 225249423Sdim return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 || 226249423Sdim SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 || 227249423Sdim SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32); 228239462Sdim } 229239462Sdim 230239462Sdim /// is1024BitVector - Return true if this is a 1024-bit vector type. 231239462Sdim bool is1024BitVector() const { 232239462Sdim return (SimpleTy == MVT::v16i64); 233239462Sdim } 234239462Sdim 235202375Srdivacky /// isPow2VectorType - Returns true if the given vector is a power of 2. 236198090Srdivacky bool isPow2VectorType() const { 237198090Srdivacky unsigned NElts = getVectorNumElements(); 238198090Srdivacky return !(NElts & (NElts - 1)); 239198090Srdivacky } 240198090Srdivacky 241218893Sdim /// getPow2VectorType - Widens the length of the given vector MVT up to 242198090Srdivacky /// the nearest power of 2 and returns that type. 243198090Srdivacky MVT getPow2VectorType() const { 244212904Sdim if (isPow2VectorType()) 245198090Srdivacky return *this; 246212904Sdim 247212904Sdim unsigned NElts = getVectorNumElements(); 248212904Sdim unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts); 249212904Sdim return MVT::getVectorVT(getVectorElementType(), Pow2NElts); 250198090Srdivacky } 251200581Srdivacky 252200581Srdivacky /// getScalarType - If this is a vector type, return the element type, 253200581Srdivacky /// otherwise return this. 254200581Srdivacky MVT getScalarType() const { 255200581Srdivacky return isVector() ? getVectorElementType() : *this; 256200581Srdivacky } 257218893Sdim 258198090Srdivacky MVT getVectorElementType() const { 259198090Srdivacky switch (SimpleTy) { 260198090Srdivacky default: 261239462Sdim llvm_unreachable("Not a vector MVT!"); 262243830Sdim case v2i1 : 263243830Sdim case v4i1 : 264243830Sdim case v8i1 : 265249423Sdim case v16i1 : 266249423Sdim case v32i1 : 267249423Sdim case v64i1: return i1; 268198090Srdivacky case v2i8 : 269198090Srdivacky case v4i8 : 270198090Srdivacky case v8i8 : 271198090Srdivacky case v16i8: 272249423Sdim case v32i8: 273249423Sdim case v64i8: return i8; 274243830Sdim case v1i16: 275198090Srdivacky case v2i16: 276198090Srdivacky case v4i16: 277198090Srdivacky case v8i16: 278249423Sdim case v16i16: 279249423Sdim case v32i16: return i16; 280243830Sdim case v1i32: 281198090Srdivacky case v2i32: 282198090Srdivacky case v4i32: 283239462Sdim case v8i32: 284239462Sdim case v16i32: return i32; 285198090Srdivacky case v1i64: 286198090Srdivacky case v2i64: 287208599Srdivacky case v4i64: 288239462Sdim case v8i64: 289239462Sdim case v16i64: return i64; 290234353Sdim case v2f16: return f16; 291198090Srdivacky case v2f32: 292198090Srdivacky case v4f32: 293249423Sdim case v8f32: 294249423Sdim case v16f32: return f32; 295198090Srdivacky case v2f64: 296249423Sdim case v4f64: 297249423Sdim case v8f64: return f64; 298198090Srdivacky } 299198090Srdivacky } 300218893Sdim 301198090Srdivacky unsigned getVectorNumElements() const { 302198090Srdivacky switch (SimpleTy) { 303198090Srdivacky default: 304239462Sdim llvm_unreachable("Not a vector MVT!"); 305249423Sdim case v32i1: 306249423Sdim case v32i8: 307249423Sdim case v32i16: return 32; 308249423Sdim case v64i1: 309249423Sdim case v64i8: return 64; 310243830Sdim case v16i1: 311198090Srdivacky case v16i8: 312239462Sdim case v16i16: 313239462Sdim case v16i32: 314249423Sdim case v16i64: 315249423Sdim case v16f32: return 16; 316249423Sdim case v8i1 : 317198090Srdivacky case v8i8 : 318198090Srdivacky case v8i16: 319198090Srdivacky case v8i32: 320208599Srdivacky case v8i64: 321249423Sdim case v8f32: 322249423Sdim case v8f64: return 8; 323243830Sdim case v4i1: 324198090Srdivacky case v4i8: 325198090Srdivacky case v4i16: 326198090Srdivacky case v4i32: 327198090Srdivacky case v4i64: 328198090Srdivacky case v4f32: 329198090Srdivacky case v4f64: return 4; 330243830Sdim case v2i1: 331198090Srdivacky case v2i8: 332198090Srdivacky case v2i16: 333198090Srdivacky case v2i32: 334198090Srdivacky case v2i64: 335234353Sdim case v2f16: 336198090Srdivacky case v2f32: 337198090Srdivacky case v2f64: return 2; 338243830Sdim case v1i16: 339243830Sdim case v1i32: 340198090Srdivacky case v1i64: return 1; 341198090Srdivacky } 342198090Srdivacky } 343218893Sdim 344198090Srdivacky unsigned getSizeInBits() const { 345198090Srdivacky switch (SimpleTy) { 346198090Srdivacky case iPTR: 347234353Sdim llvm_unreachable("Value type size is target-dependent. Ask TLI."); 348198090Srdivacky case iPTRAny: 349198090Srdivacky case iAny: 350198090Srdivacky case fAny: 351249423Sdim case vAny: 352234353Sdim llvm_unreachable("Value type is overloaded."); 353249423Sdim case Metadata: 354249423Sdim llvm_unreachable("Value type is metadata."); 355198090Srdivacky default: 356234353Sdim llvm_unreachable("getSizeInBits called on extended MVT."); 357198090Srdivacky case i1 : return 1; 358243830Sdim case v2i1: return 2; 359243830Sdim case v4i1: return 4; 360243830Sdim case i8 : 361243830Sdim case v8i1: return 8; 362198090Srdivacky case i16 : 363234353Sdim case f16: 364243830Sdim case v16i1: 365243830Sdim case v2i8: 366243830Sdim case v1i16: return 16; 367198090Srdivacky case f32 : 368198090Srdivacky case i32 : 369249423Sdim case v32i1: 370198090Srdivacky case v4i8: 371234353Sdim case v2i16: 372249423Sdim case v2f16: 373243830Sdim case v1i32: return 32; 374218893Sdim case x86mmx: 375198090Srdivacky case f64 : 376198090Srdivacky case i64 : 377249423Sdim case v64i1: 378198090Srdivacky case v8i8: 379198090Srdivacky case v4i16: 380198090Srdivacky case v2i32: 381198090Srdivacky case v1i64: 382198090Srdivacky case v2f32: return 64; 383198090Srdivacky case f80 : return 80; 384198090Srdivacky case f128: 385198090Srdivacky case ppcf128: 386198090Srdivacky case i128: 387198090Srdivacky case v16i8: 388198090Srdivacky case v8i16: 389198090Srdivacky case v4i32: 390198090Srdivacky case v2i64: 391198090Srdivacky case v4f32: 392198090Srdivacky case v2f64: return 128; 393198090Srdivacky case v32i8: 394198090Srdivacky case v16i16: 395198090Srdivacky case v8i32: 396198090Srdivacky case v4i64: 397198090Srdivacky case v8f32: 398198090Srdivacky case v4f64: return 256; 399249423Sdim case v64i8: 400249423Sdim case v32i16: 401239462Sdim case v16i32: 402249423Sdim case v8i64: 403249423Sdim case v16f32: 404249423Sdim case v8f64: return 512; 405239462Sdim case v16i64:return 1024; 406198090Srdivacky } 407198090Srdivacky } 408218893Sdim 409218893Sdim /// getStoreSize - Return the number of bytes overwritten by a store 410218893Sdim /// of the specified value type. 411218893Sdim unsigned getStoreSize() const { 412218893Sdim return (getSizeInBits() + 7) / 8; 413218893Sdim } 414218893Sdim 415218893Sdim /// getStoreSizeInBits - Return the number of bits overwritten by a store 416218893Sdim /// of the specified value type. 417218893Sdim unsigned getStoreSizeInBits() const { 418218893Sdim return getStoreSize() * 8; 419218893Sdim } 420218893Sdim 421249423Sdim /// Return true if this has more bits than VT. 422249423Sdim bool bitsGT(MVT VT) const { 423249423Sdim return getSizeInBits() > VT.getSizeInBits(); 424249423Sdim } 425249423Sdim 426249423Sdim /// Return true if this has no less bits than VT. 427249423Sdim bool bitsGE(MVT VT) const { 428249423Sdim return getSizeInBits() >= VT.getSizeInBits(); 429249423Sdim } 430249423Sdim 431249423Sdim /// Return true if this has less bits than VT. 432249423Sdim bool bitsLT(MVT VT) const { 433249423Sdim return getSizeInBits() < VT.getSizeInBits(); 434249423Sdim } 435249423Sdim 436249423Sdim /// Return true if this has no more bits than VT. 437249423Sdim bool bitsLE(MVT VT) const { 438249423Sdim return getSizeInBits() <= VT.getSizeInBits(); 439249423Sdim } 440249423Sdim 441249423Sdim 442193323Sed static MVT getFloatingPointVT(unsigned BitWidth) { 443193323Sed switch (BitWidth) { 444193323Sed default: 445234353Sdim llvm_unreachable("Bad bit width!"); 446234353Sdim case 16: 447234353Sdim return MVT::f16; 448193323Sed case 32: 449198090Srdivacky return MVT::f32; 450193323Sed case 64: 451198090Srdivacky return MVT::f64; 452193323Sed case 80: 453198090Srdivacky return MVT::f80; 454193323Sed case 128: 455198090Srdivacky return MVT::f128; 456193323Sed } 457193323Sed } 458218893Sdim 459193323Sed static MVT getIntegerVT(unsigned BitWidth) { 460193323Sed switch (BitWidth) { 461193323Sed default: 462198090Srdivacky return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE); 463193323Sed case 1: 464198090Srdivacky return MVT::i1; 465193323Sed case 8: 466198090Srdivacky return MVT::i8; 467193323Sed case 16: 468198090Srdivacky return MVT::i16; 469193323Sed case 32: 470198090Srdivacky return MVT::i32; 471193323Sed case 64: 472198090Srdivacky return MVT::i64; 473193323Sed case 128: 474198090Srdivacky return MVT::i128; 475193323Sed } 476193323Sed } 477218893Sdim 478193323Sed static MVT getVectorVT(MVT VT, unsigned NumElements) { 479198090Srdivacky switch (VT.SimpleTy) { 480193323Sed default: 481193323Sed break; 482243830Sdim case MVT::i1: 483243830Sdim if (NumElements == 2) return MVT::v2i1; 484243830Sdim if (NumElements == 4) return MVT::v4i1; 485243830Sdim if (NumElements == 8) return MVT::v8i1; 486243830Sdim if (NumElements == 16) return MVT::v16i1; 487249423Sdim if (NumElements == 32) return MVT::v32i1; 488249423Sdim if (NumElements == 64) return MVT::v64i1; 489243830Sdim break; 490198090Srdivacky case MVT::i8: 491198090Srdivacky if (NumElements == 2) return MVT::v2i8; 492198090Srdivacky if (NumElements == 4) return MVT::v4i8; 493198090Srdivacky if (NumElements == 8) return MVT::v8i8; 494198090Srdivacky if (NumElements == 16) return MVT::v16i8; 495198090Srdivacky if (NumElements == 32) return MVT::v32i8; 496249423Sdim if (NumElements == 64) return MVT::v64i8; 497193323Sed break; 498198090Srdivacky case MVT::i16: 499243830Sdim if (NumElements == 1) return MVT::v1i16; 500198090Srdivacky if (NumElements == 2) return MVT::v2i16; 501198090Srdivacky if (NumElements == 4) return MVT::v4i16; 502198090Srdivacky if (NumElements == 8) return MVT::v8i16; 503198090Srdivacky if (NumElements == 16) return MVT::v16i16; 504249423Sdim if (NumElements == 32) return MVT::v32i16; 505193323Sed break; 506198090Srdivacky case MVT::i32: 507243830Sdim if (NumElements == 1) return MVT::v1i32; 508198090Srdivacky if (NumElements == 2) return MVT::v2i32; 509198090Srdivacky if (NumElements == 4) return MVT::v4i32; 510198090Srdivacky if (NumElements == 8) return MVT::v8i32; 511239462Sdim if (NumElements == 16) return MVT::v16i32; 512193323Sed break; 513198090Srdivacky case MVT::i64: 514198090Srdivacky if (NumElements == 1) return MVT::v1i64; 515198090Srdivacky if (NumElements == 2) return MVT::v2i64; 516198090Srdivacky if (NumElements == 4) return MVT::v4i64; 517208599Srdivacky if (NumElements == 8) return MVT::v8i64; 518239462Sdim if (NumElements == 16) return MVT::v16i64; 519193323Sed break; 520234353Sdim case MVT::f16: 521234353Sdim if (NumElements == 2) return MVT::v2f16; 522234353Sdim break; 523198090Srdivacky case MVT::f32: 524198090Srdivacky if (NumElements == 2) return MVT::v2f32; 525198090Srdivacky if (NumElements == 4) return MVT::v4f32; 526198090Srdivacky if (NumElements == 8) return MVT::v8f32; 527249423Sdim if (NumElements == 16) return MVT::v16f32; 528193323Sed break; 529198090Srdivacky case MVT::f64: 530198090Srdivacky if (NumElements == 2) return MVT::v2f64; 531198090Srdivacky if (NumElements == 4) return MVT::v4f64; 532249423Sdim if (NumElements == 8) return MVT::v8f64; 533193323Sed break; 534193323Sed } 535198090Srdivacky return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE); 536193323Sed } 537249423Sdim 538249423Sdim /// Return the value type corresponding to the specified type. This returns 539249423Sdim /// all pointers as iPTR. If HandleUnknown is true, unknown types are 540249423Sdim /// returned as Other, otherwise they are invalid. 541249423Sdim static MVT getVT(Type *Ty, bool HandleUnknown = false); 542249423Sdim 543198090Srdivacky }; 544193323Sed 545218893Sdim 546218893Sdim /// EVT - Extended Value Type. Capable of holding value types which are not 547218893Sdim /// native for any processor (such as the i12345 type), as well as the types 548218893Sdim /// a MVT can represent. 549218893Sdim struct EVT { 550198090Srdivacky private: 551198090Srdivacky MVT V; 552226633Sdim Type *LLVMTy; 553198090Srdivacky 554198090Srdivacky public: 555198090Srdivacky EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)), 556198090Srdivacky LLVMTy(0) {} 557198090Srdivacky EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { } 558198090Srdivacky EVT(MVT S) : V(S), LLVMTy(0) {} 559198090Srdivacky 560212904Sdim bool operator==(EVT VT) const { 561212904Sdim return !(*this != VT); 562212904Sdim } 563212904Sdim bool operator!=(EVT VT) const { 564212904Sdim if (V.SimpleTy != VT.V.SimpleTy) 565198090Srdivacky return true; 566249423Sdim if (V.SimpleTy < 0) 567212904Sdim return LLVMTy != VT.LLVMTy; 568198090Srdivacky return false; 569198090Srdivacky } 570198090Srdivacky 571198090Srdivacky /// getFloatingPointVT - Returns the EVT that represents a floating point 572198090Srdivacky /// type with the given number of bits. There are two floating point types 573198090Srdivacky /// with 128 bits - this returns f128 rather than ppcf128. 574198090Srdivacky static EVT getFloatingPointVT(unsigned BitWidth) { 575198090Srdivacky return MVT::getFloatingPointVT(BitWidth); 576198090Srdivacky } 577198090Srdivacky 578198090Srdivacky /// getIntegerVT - Returns the EVT that represents an integer with the given 579198090Srdivacky /// number of bits. 580198090Srdivacky static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) { 581198090Srdivacky MVT M = MVT::getIntegerVT(BitWidth); 582249423Sdim if (M.SimpleTy >= 0) 583198090Srdivacky return M; 584212904Sdim return getExtendedIntegerVT(Context, BitWidth); 585198090Srdivacky } 586198090Srdivacky 587198090Srdivacky /// getVectorVT - Returns the EVT that represents a vector NumElements in 588198090Srdivacky /// length, where each element is of type VT. 589198090Srdivacky static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) { 590198090Srdivacky MVT M = MVT::getVectorVT(VT.V, NumElements); 591249423Sdim if (M.SimpleTy >= 0) 592198090Srdivacky return M; 593212904Sdim return getExtendedVectorVT(Context, VT, NumElements); 594198090Srdivacky } 595198090Srdivacky 596226633Sdim /// changeVectorElementTypeToInteger - Return a vector with the same number 597226633Sdim /// of elements as this vector, but with the element type converted to an 598226633Sdim /// integer type with the same bitwidth. 599226633Sdim EVT changeVectorElementTypeToInteger() const { 600226633Sdim if (!isSimple()) 601226633Sdim return changeExtendedVectorElementTypeToInteger(); 602226633Sdim MVT EltTy = getSimpleVT().getVectorElementType(); 603226633Sdim unsigned BitWidth = EltTy.getSizeInBits(); 604226633Sdim MVT IntTy = MVT::getIntegerVT(BitWidth); 605226633Sdim MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements()); 606249423Sdim assert(VecTy.SimpleTy >= 0 && 607226633Sdim "Simple vector VT not representable by simple integer vector VT!"); 608226633Sdim return VecTy; 609226633Sdim } 610226633Sdim 611198090Srdivacky /// isSimple - Test if the given EVT is simple (as opposed to being 612193323Sed /// extended). 613193323Sed bool isSimple() const { 614249423Sdim return V.SimpleTy >= 0; 615193323Sed } 616193323Sed 617198090Srdivacky /// isExtended - Test if the given EVT is extended (as opposed to 618193323Sed /// being simple). 619193323Sed bool isExtended() const { 620193323Sed return !isSimple(); 621193323Sed } 622193323Sed 623193323Sed /// isFloatingPoint - Return true if this is a FP, or a vector FP type. 624193323Sed bool isFloatingPoint() const { 625202375Srdivacky return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint(); 626193323Sed } 627193323Sed 628193323Sed /// isInteger - Return true if this is an integer, or a vector integer type. 629193323Sed bool isInteger() const { 630202375Srdivacky return isSimple() ? V.isInteger() : isExtendedInteger(); 631193323Sed } 632193323Sed 633193323Sed /// isVector - Return true if this is a vector value type. 634193323Sed bool isVector() const { 635202375Srdivacky return isSimple() ? V.isVector() : isExtendedVector(); 636193323Sed } 637193323Sed 638243830Sdim /// is16BitVector - Return true if this is a 16-bit vector type. 639243830Sdim bool is16BitVector() const { 640243830Sdim return isSimple() ? V.is16BitVector() : isExtended16BitVector(); 641243830Sdim } 642243830Sdim 643243830Sdim /// is32BitVector - Return true if this is a 32-bit vector type. 644243830Sdim bool is32BitVector() const { 645243830Sdim return isSimple() ? V.is32BitVector() : isExtended32BitVector(); 646243830Sdim } 647243830Sdim 648193323Sed /// is64BitVector - Return true if this is a 64-bit vector type. 649193323Sed bool is64BitVector() const { 650239462Sdim return isSimple() ? V.is64BitVector() : isExtended64BitVector(); 651193323Sed } 652193323Sed 653193323Sed /// is128BitVector - Return true if this is a 128-bit vector type. 654193323Sed bool is128BitVector() const { 655239462Sdim return isSimple() ? V.is128BitVector() : isExtended128BitVector(); 656193323Sed } 657193323Sed 658195340Sed /// is256BitVector - Return true if this is a 256-bit vector type. 659239462Sdim bool is256BitVector() const { 660239462Sdim return isSimple() ? V.is256BitVector() : isExtended256BitVector(); 661195340Sed } 662195340Sed 663208599Srdivacky /// is512BitVector - Return true if this is a 512-bit vector type. 664239462Sdim bool is512BitVector() const { 665239462Sdim return isSimple() ? V.is512BitVector() : isExtended512BitVector(); 666208599Srdivacky } 667208599Srdivacky 668239462Sdim /// is1024BitVector - Return true if this is a 1024-bit vector type. 669239462Sdim bool is1024BitVector() const { 670239462Sdim return isSimple() ? V.is1024BitVector() : isExtended1024BitVector(); 671239462Sdim } 672239462Sdim 673198090Srdivacky /// isOverloaded - Return true if this is an overloaded type for TableGen. 674198090Srdivacky bool isOverloaded() const { 675198090Srdivacky return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny); 676198090Srdivacky } 677198090Srdivacky 678193323Sed /// isByteSized - Return true if the bit size is a multiple of 8. 679193323Sed bool isByteSized() const { 680193323Sed return (getSizeInBits() & 7) == 0; 681193323Sed } 682193323Sed 683193323Sed /// isRound - Return true if the size is a power-of-two number of bytes. 684193323Sed bool isRound() const { 685193323Sed unsigned BitSize = getSizeInBits(); 686193323Sed return BitSize >= 8 && !(BitSize & (BitSize - 1)); 687193323Sed } 688193323Sed 689193323Sed /// bitsEq - Return true if this has the same number of bits as VT. 690198090Srdivacky bool bitsEq(EVT VT) const { 691203954Srdivacky if (EVT::operator==(VT)) return true; 692193323Sed return getSizeInBits() == VT.getSizeInBits(); 693193323Sed } 694193323Sed 695193323Sed /// bitsGT - Return true if this has more bits than VT. 696198090Srdivacky bool bitsGT(EVT VT) const { 697203954Srdivacky if (EVT::operator==(VT)) return false; 698193323Sed return getSizeInBits() > VT.getSizeInBits(); 699193323Sed } 700193323Sed 701193323Sed /// bitsGE - Return true if this has no less bits than VT. 702198090Srdivacky bool bitsGE(EVT VT) const { 703203954Srdivacky if (EVT::operator==(VT)) return true; 704193323Sed return getSizeInBits() >= VT.getSizeInBits(); 705193323Sed } 706193323Sed 707193323Sed /// bitsLT - Return true if this has less bits than VT. 708198090Srdivacky bool bitsLT(EVT VT) const { 709203954Srdivacky if (EVT::operator==(VT)) return false; 710193323Sed return getSizeInBits() < VT.getSizeInBits(); 711193323Sed } 712193323Sed 713193323Sed /// bitsLE - Return true if this has no more bits than VT. 714198090Srdivacky bool bitsLE(EVT VT) const { 715203954Srdivacky if (EVT::operator==(VT)) return true; 716193323Sed return getSizeInBits() <= VT.getSizeInBits(); 717193323Sed } 718193323Sed 719193323Sed 720193323Sed /// getSimpleVT - Return the SimpleValueType held in the specified 721198090Srdivacky /// simple EVT. 722198090Srdivacky MVT getSimpleVT() const { 723193323Sed assert(isSimple() && "Expected a SimpleValueType!"); 724198090Srdivacky return V; 725193323Sed } 726193323Sed 727200581Srdivacky /// getScalarType - If this is a vector type, return the element type, 728200581Srdivacky /// otherwise return this. 729200581Srdivacky EVT getScalarType() const { 730200581Srdivacky return isVector() ? getVectorElementType() : *this; 731200581Srdivacky } 732218893Sdim 733193323Sed /// getVectorElementType - Given a vector type, return the type of 734193323Sed /// each element. 735198090Srdivacky EVT getVectorElementType() const { 736193323Sed assert(isVector() && "Invalid vector type!"); 737198090Srdivacky if (isSimple()) 738198090Srdivacky return V.getVectorElementType(); 739212904Sdim return getExtendedVectorElementType(); 740193323Sed } 741193323Sed 742193323Sed /// getVectorNumElements - Given a vector type, return the number of 743193323Sed /// elements it contains. 744193323Sed unsigned getVectorNumElements() const { 745193323Sed assert(isVector() && "Invalid vector type!"); 746198090Srdivacky if (isSimple()) 747198090Srdivacky return V.getVectorNumElements(); 748212904Sdim return getExtendedVectorNumElements(); 749193323Sed } 750193323Sed 751193323Sed /// getSizeInBits - Return the size of the specified value type in bits. 752193323Sed unsigned getSizeInBits() const { 753198090Srdivacky if (isSimple()) 754198090Srdivacky return V.getSizeInBits(); 755212904Sdim return getExtendedSizeInBits(); 756193323Sed } 757193323Sed 758198090Srdivacky /// getStoreSize - Return the number of bytes overwritten by a store 759198090Srdivacky /// of the specified value type. 760198090Srdivacky unsigned getStoreSize() const { 761198090Srdivacky return (getSizeInBits() + 7) / 8; 762198090Srdivacky } 763198090Srdivacky 764193323Sed /// getStoreSizeInBits - Return the number of bits overwritten by a store 765193323Sed /// of the specified value type. 766193323Sed unsigned getStoreSizeInBits() const { 767198090Srdivacky return getStoreSize() * 8; 768193323Sed } 769193323Sed 770198090Srdivacky /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up 771193323Sed /// to the nearest power of two (and at least to eight), and returns the 772198090Srdivacky /// integer EVT with that number of bits. 773198090Srdivacky EVT getRoundIntegerType(LLVMContext &Context) const { 774193323Sed assert(isInteger() && !isVector() && "Invalid integer type!"); 775193323Sed unsigned BitWidth = getSizeInBits(); 776193323Sed if (BitWidth <= 8) 777198090Srdivacky return EVT(MVT::i8); 778212904Sdim return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth)); 779193323Sed } 780193323Sed 781201360Srdivacky /// getHalfSizedIntegerVT - Finds the smallest simple value type that is 782201360Srdivacky /// greater than or equal to half the width of this EVT. If no simple 783201360Srdivacky /// value type can be found, an extended integer value type of half the 784201360Srdivacky /// size (rounded up) is returned. 785201360Srdivacky EVT getHalfSizedIntegerVT(LLVMContext &Context) const { 786201360Srdivacky assert(isInteger() && !isVector() && "Invalid integer type!"); 787201360Srdivacky unsigned EVTSize = getSizeInBits(); 788201360Srdivacky for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE; 789212904Sdim IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) { 790201360Srdivacky EVT HalfVT = EVT((MVT::SimpleValueType)IntVT); 791212904Sdim if (HalfVT.getSizeInBits() * 2 >= EVTSize) 792201360Srdivacky return HalfVT; 793201360Srdivacky } 794201360Srdivacky return getIntegerVT(Context, (EVTSize + 1) / 2); 795201360Srdivacky } 796201360Srdivacky 797201360Srdivacky /// isPow2VectorType - Returns true if the given vector is a power of 2. 798193323Sed bool isPow2VectorType() const { 799193323Sed unsigned NElts = getVectorNumElements(); 800193323Sed return !(NElts & (NElts - 1)); 801193323Sed } 802193323Sed 803198090Srdivacky /// getPow2VectorType - Widens the length of the given vector EVT up to 804193323Sed /// the nearest power of 2 and returns that type. 805198090Srdivacky EVT getPow2VectorType(LLVMContext &Context) const { 806193323Sed if (!isPow2VectorType()) { 807193323Sed unsigned NElts = getVectorNumElements(); 808193323Sed unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts); 809198090Srdivacky return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts); 810193323Sed } 811193323Sed else { 812193323Sed return *this; 813193323Sed } 814193323Sed } 815193323Sed 816198090Srdivacky /// getEVTString - This function returns value type as a string, 817193323Sed /// e.g. "i32". 818198090Srdivacky std::string getEVTString() const; 819193323Sed 820198090Srdivacky /// getTypeForEVT - This method returns an LLVM type corresponding to the 821198090Srdivacky /// specified EVT. For integer types, this returns an unsigned type. Note 822193323Sed /// that this will abort for types that cannot be represented. 823226633Sdim Type *getTypeForEVT(LLVMContext &Context) const; 824193323Sed 825198090Srdivacky /// getEVT - Return the value type corresponding to the specified type. 826193323Sed /// This returns all pointers as iPTR. If HandleUnknown is true, unknown 827193323Sed /// types are returned as Other, otherwise they are invalid. 828226633Sdim static EVT getEVT(Type *Ty, bool HandleUnknown = false); 829193323Sed 830249423Sdim intptr_t getRawBits() const { 831202375Srdivacky if (isSimple()) 832198090Srdivacky return V.SimpleTy; 833198090Srdivacky else 834198090Srdivacky return (intptr_t)(LLVMTy); 835198090Srdivacky } 836193323Sed 837193323Sed /// compareRawBits - A meaningless but well-behaved order, useful for 838193323Sed /// constructing containers. 839193323Sed struct compareRawBits { 840198090Srdivacky bool operator()(EVT L, EVT R) const { 841198090Srdivacky if (L.V.SimpleTy == R.V.SimpleTy) 842198090Srdivacky return L.LLVMTy < R.LLVMTy; 843198090Srdivacky else 844198090Srdivacky return L.V.SimpleTy < R.V.SimpleTy; 845193323Sed } 846193323Sed }; 847193323Sed 848193323Sed private: 849193323Sed // Methods for handling the Extended-type case in functions above. 850193323Sed // These are all out-of-line to prevent users of this header file 851193323Sed // from having a dependency on Type.h. 852226633Sdim EVT changeExtendedVectorElementTypeToInteger() const; 853198090Srdivacky static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth); 854198090Srdivacky static EVT getExtendedVectorVT(LLVMContext &C, EVT VT, 855198090Srdivacky unsigned NumElements); 856193323Sed bool isExtendedFloatingPoint() const; 857193323Sed bool isExtendedInteger() const; 858193323Sed bool isExtendedVector() const; 859243830Sdim bool isExtended16BitVector() const; 860243830Sdim bool isExtended32BitVector() const; 861193323Sed bool isExtended64BitVector() const; 862193323Sed bool isExtended128BitVector() const; 863195340Sed bool isExtended256BitVector() const; 864208599Srdivacky bool isExtended512BitVector() const; 865239462Sdim bool isExtended1024BitVector() const; 866198090Srdivacky EVT getExtendedVectorElementType() const; 867193323Sed unsigned getExtendedVectorNumElements() const; 868193323Sed unsigned getExtendedSizeInBits() const; 869193323Sed }; 870193323Sed 871193323Sed} // End llvm namespace 872193323Sed 873193323Sed#endif 874