Home | History | Annotate | Line # | Download | only in Support
      1 //===- Support/MachineValueType.h - Machine-Level types ---------*- C++ -*-===//
      2 //
      3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4 // See https://llvm.org/LICENSE.txt for license information.
      5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6 //
      7 //===----------------------------------------------------------------------===//
      8 //
      9 // This file defines the set of machine-level target independent types which
     10 // legal values in the code generator use.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_SUPPORT_MACHINEVALUETYPE_H
     15 #define LLVM_SUPPORT_MACHINEVALUETYPE_H
     16 
     17 #include "llvm/ADT/iterator_range.h"
     18 #include "llvm/Support/ErrorHandling.h"
     19 #include "llvm/Support/MathExtras.h"
     20 #include "llvm/Support/TypeSize.h"
     21 #include <cassert>
     22 
     23 namespace llvm {
     24 
     25   class Type;
     26 
     27   /// Machine Value Type. Every type that is supported natively by some
     28   /// processor targeted by LLVM occurs here. This means that any legal value
     29   /// type can be represented by an MVT.
     30   class MVT {
     31   public:
     32     enum SimpleValueType : uint8_t {
     33       // Simple value types that aren't explicitly part of this enumeration
     34       // are considered extended value types.
     35       INVALID_SIMPLE_VALUE_TYPE = 0,
     36 
     37       // If you change this numbering, you must change the values in
     38       // ValueTypes.td as well!
     39       Other          =   1,   // This is a non-standard value
     40       i1             =   2,   // This is a 1 bit integer value
     41       i8             =   3,   // This is an 8 bit integer value
     42       i16            =   4,   // This is a 16 bit integer value
     43       i32            =   5,   // This is a 32 bit integer value
     44       i64            =   6,   // This is a 64 bit integer value
     45       i128           =   7,   // This is a 128 bit integer value
     46 
     47       FIRST_INTEGER_VALUETYPE = i1,
     48       LAST_INTEGER_VALUETYPE  = i128,
     49 
     50       bf16           =   8,   // This is a 16 bit brain floating point value
     51       f16            =   9,   // This is a 16 bit floating point value
     52       f32            =  10,   // This is a 32 bit floating point value
     53       f64            =  11,   // This is a 64 bit floating point value
     54       f80            =  12,   // This is a 80 bit floating point value
     55       f128           =  13,   // This is a 128 bit floating point value
     56       ppcf128        =  14,   // This is a PPC 128-bit floating point value
     57 
     58       FIRST_FP_VALUETYPE = bf16,
     59       LAST_FP_VALUETYPE  = ppcf128,
     60 
     61       v1i1           =  15,   //    1 x i1
     62       v2i1           =  16,   //    2 x i1
     63       v4i1           =  17,   //    4 x i1
     64       v8i1           =  18,   //    8 x i1
     65       v16i1          =  19,   //   16 x i1
     66       v32i1          =  20,   //   32 x i1
     67       v64i1          =  21,   //   64 x i1
     68       v128i1         =  22,   //  128 x i1
     69       v256i1         =  23,   //  256 x i1
     70       v512i1         =  24,   //  512 x i1
     71       v1024i1        =  25,   // 1024 x i1
     72 
     73       v1i8           =  26,   //   1 x i8
     74       v2i8           =  27,   //   2 x i8
     75       v4i8           =  28,   //   4 x i8
     76       v8i8           =  29,   //   8 x i8
     77       v16i8          =  30,   //  16 x i8
     78       v32i8          =  31,   //  32 x i8
     79       v64i8          =  32,   //  64 x i8
     80       v128i8         =  33,   // 128 x i8
     81       v256i8         =  34,   // 256 x i8
     82 
     83       v1i16          =  35,   //   1 x i16
     84       v2i16          =  36,   //   2 x i16
     85       v3i16          =  37,   //   3 x i16
     86       v4i16          =  38,   //   4 x i16
     87       v8i16          =  39,   //   8 x i16
     88       v16i16         =  40,   //  16 x i16
     89       v32i16         =  41,   //  32 x i16
     90       v64i16         =  42,   //  64 x i16
     91       v128i16        =  43,   // 128 x i16
     92       v256i16        =  44,   // 256 x i16
     93 
     94       v1i32          =  45,   //    1 x i32
     95       v2i32          =  46,   //    2 x i32
     96       v3i32          =  47,   //    3 x i32
     97       v4i32          =  48,   //    4 x i32
     98       v5i32          =  49,   //    5 x i32
     99       v8i32          =  50,   //    8 x i32
    100       v16i32         =  51,   //   16 x i32
    101       v32i32         =  52,   //   32 x i32
    102       v64i32         =  53,   //   64 x i32
    103       v128i32        =  54,   //  128 x i32
    104       v256i32        =  55,   //  256 x i32
    105       v512i32        =  56,   //  512 x i32
    106       v1024i32       =  57,   // 1024 x i32
    107       v2048i32       =  58,   // 2048 x i32
    108 
    109       v1i64          =  59,   //   1 x i64
    110       v2i64          =  60,   //   2 x i64
    111       v4i64          =  61,   //   4 x i64
    112       v8i64          =  62,   //   8 x i64
    113       v16i64         =  63,   //  16 x i64
    114       v32i64         =  64,   //  32 x i64
    115       v64i64         =  65,   //  64 x i64
    116       v128i64        =  66,   // 128 x i64
    117       v256i64        =  67,   // 256 x i64
    118 
    119       v1i128         =  68,   //  1 x i128
    120 
    121       FIRST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE = v1i1,
    122       LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE = v1i128,
    123 
    124       v1f16          =  69,   //    1 x f16
    125       v2f16          =  70,   //    2 x f16
    126       v3f16          =  71,   //    3 x f16
    127       v4f16          =  72,   //    4 x f16
    128       v8f16          =  73,   //    8 x f16
    129       v16f16         =  74,   //   16 x f16
    130       v32f16         =  75,   //   32 x f16
    131       v64f16         =  76,   //   64 x f16
    132       v128f16        =  77,   //  128 x f16
    133       v256f16        =  78,   //  256 x f16
    134 
    135       v2bf16         =  79,   //    2 x bf16
    136       v3bf16         =  80,   //    3 x bf16
    137       v4bf16         =  81,   //    4 x bf16
    138       v8bf16         =  82,   //    8 x bf16
    139       v16bf16        =  83,   //   16 x bf16
    140       v32bf16        =  84,   //   32 x bf16
    141       v64bf16        =  85,   //   64 x bf16
    142       v128bf16       =  86,   //  128 x bf16
    143 
    144       v1f32          =  87,   //    1 x f32
    145       v2f32          =  88,   //    2 x f32
    146       v3f32          =  89,   //    3 x f32
    147       v4f32          =  90,   //    4 x f32
    148       v5f32          =  91,   //    5 x f32
    149       v8f32          =  92,   //    8 x f32
    150       v16f32         =  93,   //   16 x f32
    151       v32f32         =  94,   //   32 x f32
    152       v64f32         =  95,   //   64 x f32
    153       v128f32        =  96,   //  128 x f32
    154       v256f32        =  97,   //  256 x f32
    155       v512f32        =  98,   //  512 x f32
    156       v1024f32       =  99,   // 1024 x f32
    157       v2048f32       = 100,   // 2048 x f32
    158 
    159       v1f64          = 101,   //    1 x f64
    160       v2f64          = 102,   //    2 x f64
    161       v4f64          = 103,   //    4 x f64
    162       v8f64          = 104,   //    8 x f64
    163       v16f64         = 105,   //   16 x f64
    164       v32f64         = 106,   //   32 x f64
    165       v64f64         = 107,   //   64 x f64
    166       v128f64        = 108,   //  128 x f64
    167       v256f64        = 109,   //  256 x f64
    168 
    169       FIRST_FP_FIXEDLEN_VECTOR_VALUETYPE = v1f16,
    170       LAST_FP_FIXEDLEN_VECTOR_VALUETYPE = v256f64,
    171 
    172       FIRST_FIXEDLEN_VECTOR_VALUETYPE = v1i1,
    173       LAST_FIXEDLEN_VECTOR_VALUETYPE = v256f64,
    174 
    175       nxv1i1         = 110,   // n x  1 x i1
    176       nxv2i1         = 111,   // n x  2 x i1
    177       nxv4i1         = 112,   // n x  4 x i1
    178       nxv8i1         = 113,   // n x  8 x i1
    179       nxv16i1        = 114,   // n x 16 x i1
    180       nxv32i1        = 115,   // n x 32 x i1
    181       nxv64i1        = 116,   // n x 64 x i1
    182 
    183       nxv1i8         = 117,   // n x  1 x i8
    184       nxv2i8         = 118,   // n x  2 x i8
    185       nxv4i8         = 119,   // n x  4 x i8
    186       nxv8i8         = 120,   // n x  8 x i8
    187       nxv16i8        = 121,   // n x 16 x i8
    188       nxv32i8        = 122,   // n x 32 x i8
    189       nxv64i8        = 123,   // n x 64 x i8
    190 
    191       nxv1i16        = 124,  // n x  1 x i16
    192       nxv2i16        = 125,  // n x  2 x i16
    193       nxv4i16        = 126,  // n x  4 x i16
    194       nxv8i16        = 127,  // n x  8 x i16
    195       nxv16i16       = 128,  // n x 16 x i16
    196       nxv32i16       = 129,  // n x 32 x i16
    197 
    198       nxv1i32        = 130,  // n x  1 x i32
    199       nxv2i32        = 131,  // n x  2 x i32
    200       nxv4i32        = 132,  // n x  4 x i32
    201       nxv8i32        = 133,  // n x  8 x i32
    202       nxv16i32       = 134,  // n x 16 x i32
    203       nxv32i32       = 135,  // n x 32 x i32
    204 
    205       nxv1i64        = 136,  // n x  1 x i64
    206       nxv2i64        = 137,  // n x  2 x i64
    207       nxv4i64        = 138,  // n x  4 x i64
    208       nxv8i64        = 139,  // n x  8 x i64
    209       nxv16i64       = 140,  // n x 16 x i64
    210       nxv32i64       = 141,  // n x 32 x i64
    211 
    212       FIRST_INTEGER_SCALABLE_VECTOR_VALUETYPE = nxv1i1,
    213       LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE = nxv32i64,
    214 
    215       nxv1f16        = 142,  // n x  1 x f16
    216       nxv2f16        = 143,  // n x  2 x f16
    217       nxv4f16        = 144,  // n x  4 x f16
    218       nxv8f16        = 145,  // n x  8 x f16
    219       nxv16f16       = 146,  // n x 16 x f16
    220       nxv32f16       = 147,  // n x 32 x f16
    221 
    222       nxv1bf16       = 148,  // n x  1 x bf16
    223       nxv2bf16       = 149,  // n x  2 x bf16
    224       nxv4bf16       = 150,  // n x  4 x bf16
    225       nxv8bf16       = 151,  // n x  8 x bf16
    226 
    227       nxv1f32        = 152,  // n x  1 x f32
    228       nxv2f32        = 153,  // n x  2 x f32
    229       nxv4f32        = 154,  // n x  4 x f32
    230       nxv8f32        = 155,  // n x  8 x f32
    231       nxv16f32       = 156,  // n x 16 x f32
    232 
    233       nxv1f64        = 157,  // n x  1 x f64
    234       nxv2f64        = 158,  // n x  2 x f64
    235       nxv4f64        = 159,  // n x  4 x f64
    236       nxv8f64        = 160,  // n x  8 x f64
    237 
    238       FIRST_FP_SCALABLE_VECTOR_VALUETYPE = nxv1f16,
    239       LAST_FP_SCALABLE_VECTOR_VALUETYPE = nxv8f64,
    240 
    241       FIRST_SCALABLE_VECTOR_VALUETYPE = nxv1i1,
    242       LAST_SCALABLE_VECTOR_VALUETYPE = nxv8f64,
    243 
    244       FIRST_VECTOR_VALUETYPE = v1i1,
    245       LAST_VECTOR_VALUETYPE  = nxv8f64,
    246 
    247       x86mmx         = 161,   // This is an X86 MMX value
    248 
    249       Glue           = 162,   // This glues nodes together during pre-RA sched
    250 
    251       isVoid         = 163,   // This has no value
    252 
    253       Untyped        = 164,   // This value takes a register, but has
    254                               // unspecified type.  The register class
    255                               // will be determined by the opcode.
    256 
    257       funcref        = 165,   // WebAssembly's funcref type
    258       externref      = 166,   // WebAssembly's externref type
    259       x86amx         = 167,   // This is an X86 AMX value
    260 
    261       FIRST_VALUETYPE =  1,   // This is always the beginning of the list.
    262       LAST_VALUETYPE = 168,   // This always remains at the end of the list.
    263 
    264       // This is the current maximum for LAST_VALUETYPE.
    265       // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
    266       // This value must be a multiple of 32.
    267       MAX_ALLOWED_VALUETYPE = 192,
    268 
    269       // A value of type llvm::TokenTy
    270       token          = 248,
    271 
    272       // This is MDNode or MDString.
    273       Metadata       = 249,
    274 
    275       // An int value the size of the pointer of the current
    276       // target to any address space. This must only be used internal to
    277       // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
    278       iPTRAny        = 250,
    279 
    280       // A vector with any length and element size. This is used
    281       // for intrinsics that have overloadings based on vector types.
    282       // This is only for tblgen's consumption!
    283       vAny           = 251,
    284 
    285       // Any floating-point or vector floating-point value. This is used
    286       // for intrinsics that have overloadings based on floating-point types.
    287       // This is only for tblgen's consumption!
    288       fAny           = 252,
    289 
    290       // An integer or vector integer value of any bit width. This is
    291       // used for intrinsics that have overloadings based on integer bit widths.
    292       // This is only for tblgen's consumption!
    293       iAny           = 253,
    294 
    295       // An int value the size of the pointer of the current
    296       // target.  This should only be used internal to tblgen!
    297       iPTR           = 254,
    298 
    299       // Any type. This is used for intrinsics that have overloadings.
    300       // This is only for tblgen's consumption!
    301       Any            = 255
    302     };
    303 
    304     SimpleValueType SimpleTy = INVALID_SIMPLE_VALUE_TYPE;
    305 
    306     constexpr MVT() = default;
    307     constexpr MVT(SimpleValueType SVT) : SimpleTy(SVT) {}
    308 
    309     bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
    310     bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
    311     bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
    312     bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
    313     bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
    314     bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
    315 
    316     /// Return true if this is a valid simple valuetype.
    317     bool isValid() const {
    318       return (SimpleTy >= MVT::FIRST_VALUETYPE &&
    319               SimpleTy < MVT::LAST_VALUETYPE);
    320     }
    321 
    322     /// Return true if this is a FP or a vector FP type.
    323     bool isFloatingPoint() const {
    324       return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
    325                SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
    326               (SimpleTy >= MVT::FIRST_FP_FIXEDLEN_VECTOR_VALUETYPE &&
    327                SimpleTy <= MVT::LAST_FP_FIXEDLEN_VECTOR_VALUETYPE) ||
    328               (SimpleTy >= MVT::FIRST_FP_SCALABLE_VECTOR_VALUETYPE &&
    329                SimpleTy <= MVT::LAST_FP_SCALABLE_VECTOR_VALUETYPE));
    330     }
    331 
    332     /// Return true if this is an integer or a vector integer type.
    333     bool isInteger() const {
    334       return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
    335                SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
    336               (SimpleTy >= MVT::FIRST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE &&
    337                SimpleTy <= MVT::LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE) ||
    338               (SimpleTy >= MVT::FIRST_INTEGER_SCALABLE_VECTOR_VALUETYPE &&
    339                SimpleTy <= MVT::LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE));
    340     }
    341 
    342     /// Return true if this is an integer, not including vectors.
    343     bool isScalarInteger() const {
    344       return (SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
    345               SimpleTy <= MVT::LAST_INTEGER_VALUETYPE);
    346     }
    347 
    348     /// Return true if this is a vector value type.
    349     bool isVector() const {
    350       return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
    351               SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
    352     }
    353 
    354     /// Return true if this is a vector value type where the
    355     /// runtime length is machine dependent
    356     bool isScalableVector() const {
    357       return (SimpleTy >= MVT::FIRST_SCALABLE_VECTOR_VALUETYPE &&
    358               SimpleTy <= MVT::LAST_SCALABLE_VECTOR_VALUETYPE);
    359     }
    360 
    361     bool isFixedLengthVector() const {
    362       return (SimpleTy >= MVT::FIRST_FIXEDLEN_VECTOR_VALUETYPE &&
    363               SimpleTy <= MVT::LAST_FIXEDLEN_VECTOR_VALUETYPE);
    364     }
    365 
    366     /// Return true if this is a 16-bit vector type.
    367     bool is16BitVector() const {
    368       return (SimpleTy == MVT::v2i8  || SimpleTy == MVT::v1i16 ||
    369               SimpleTy == MVT::v16i1 || SimpleTy == MVT::v1f16);
    370     }
    371 
    372     /// Return true if this is a 32-bit vector type.
    373     bool is32BitVector() const {
    374       return (SimpleTy == MVT::v32i1 || SimpleTy == MVT::v4i8   ||
    375               SimpleTy == MVT::v2i16 || SimpleTy == MVT::v1i32  ||
    376               SimpleTy == MVT::v2f16 || SimpleTy == MVT::v2bf16 ||
    377               SimpleTy == MVT::v1f32);
    378     }
    379 
    380     /// Return true if this is a 64-bit vector type.
    381     bool is64BitVector() const {
    382       return (SimpleTy == MVT::v64i1  || SimpleTy == MVT::v8i8  ||
    383               SimpleTy == MVT::v4i16  || SimpleTy == MVT::v2i32 ||
    384               SimpleTy == MVT::v1i64  || SimpleTy == MVT::v4f16 ||
    385               SimpleTy == MVT::v4bf16 ||SimpleTy == MVT::v2f32  ||
    386               SimpleTy == MVT::v1f64);
    387     }
    388 
    389     /// Return true if this is a 128-bit vector type.
    390     bool is128BitVector() const {
    391       return (SimpleTy == MVT::v128i1 || SimpleTy == MVT::v16i8  ||
    392               SimpleTy == MVT::v8i16  || SimpleTy == MVT::v4i32  ||
    393               SimpleTy == MVT::v2i64  || SimpleTy == MVT::v1i128 ||
    394               SimpleTy == MVT::v8f16  || SimpleTy == MVT::v8bf16 ||
    395               SimpleTy == MVT::v4f32  || SimpleTy == MVT::v2f64);
    396     }
    397 
    398     /// Return true if this is a 256-bit vector type.
    399     bool is256BitVector() const {
    400       return (SimpleTy == MVT::v16f16 || SimpleTy == MVT::v16bf16 ||
    401               SimpleTy == MVT::v8f32  || SimpleTy == MVT::v4f64   ||
    402               SimpleTy == MVT::v32i8  || SimpleTy == MVT::v16i16  ||
    403               SimpleTy == MVT::v8i32  || SimpleTy == MVT::v4i64   ||
    404               SimpleTy == MVT::v256i1);
    405     }
    406 
    407     /// Return true if this is a 512-bit vector type.
    408     bool is512BitVector() const {
    409       return (SimpleTy == MVT::v32f16 || SimpleTy == MVT::v32bf16 ||
    410               SimpleTy == MVT::v16f32 || SimpleTy == MVT::v8f64   ||
    411               SimpleTy == MVT::v512i1 || SimpleTy == MVT::v64i8   ||
    412               SimpleTy == MVT::v32i16 || SimpleTy == MVT::v16i32  ||
    413               SimpleTy == MVT::v8i64);
    414     }
    415 
    416     /// Return true if this is a 1024-bit vector type.
    417     bool is1024BitVector() const {
    418       return (SimpleTy == MVT::v1024i1 || SimpleTy == MVT::v128i8 ||
    419               SimpleTy == MVT::v64i16  || SimpleTy == MVT::v32i32 ||
    420               SimpleTy == MVT::v16i64  || SimpleTy == MVT::v64f16 ||
    421               SimpleTy == MVT::v32f32  || SimpleTy == MVT::v16f64 ||
    422               SimpleTy == MVT::v64bf16);
    423     }
    424 
    425     /// Return true if this is a 2048-bit vector type.
    426     bool is2048BitVector() const {
    427       return (SimpleTy == MVT::v256i8  || SimpleTy == MVT::v128i16 ||
    428               SimpleTy == MVT::v64i32  || SimpleTy == MVT::v32i64  ||
    429               SimpleTy == MVT::v128f16 || SimpleTy == MVT::v64f32  ||
    430               SimpleTy == MVT::v32f64  || SimpleTy == MVT::v128bf16);
    431     }
    432 
    433     /// Return true if this is an overloaded type for TableGen.
    434     bool isOverloaded() const {
    435       return (SimpleTy == MVT::Any || SimpleTy == MVT::iAny ||
    436               SimpleTy == MVT::fAny || SimpleTy == MVT::vAny ||
    437               SimpleTy == MVT::iPTRAny);
    438     }
    439 
    440     /// Return a vector with the same number of elements as this vector, but
    441     /// with the element type converted to an integer type with the same
    442     /// bitwidth.
    443     MVT changeVectorElementTypeToInteger() const {
    444       MVT EltTy = getVectorElementType();
    445       MVT IntTy = MVT::getIntegerVT(EltTy.getSizeInBits());
    446       MVT VecTy = MVT::getVectorVT(IntTy, getVectorElementCount());
    447       assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
    448              "Simple vector VT not representable by simple integer vector VT!");
    449       return VecTy;
    450     }
    451 
    452     /// Return a VT for a vector type whose attributes match ourselves
    453     /// with the exception of the element type that is chosen by the caller.
    454     MVT changeVectorElementType(MVT EltVT) const {
    455       MVT VecTy = MVT::getVectorVT(EltVT, getVectorElementCount());
    456       assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
    457              "Simple vector VT not representable by simple integer vector VT!");
    458       return VecTy;
    459     }
    460 
    461     /// Return the type converted to an equivalently sized integer or vector
    462     /// with integer element type. Similar to changeVectorElementTypeToInteger,
    463     /// but also handles scalars.
    464     MVT changeTypeToInteger() {
    465       if (isVector())
    466         return changeVectorElementTypeToInteger();
    467       return MVT::getIntegerVT(getSizeInBits());
    468     }
    469 
    470     /// Return a VT for a vector type with the same element type but
    471     /// half the number of elements.
    472     MVT getHalfNumVectorElementsVT() const {
    473       MVT EltVT = getVectorElementType();
    474       auto EltCnt = getVectorElementCount();
    475       assert(EltCnt.isKnownEven() && "Splitting vector, but not in half!");
    476       return getVectorVT(EltVT, EltCnt.divideCoefficientBy(2));
    477     }
    478 
    479     /// Returns true if the given vector is a power of 2.
    480     bool isPow2VectorType() const {
    481       unsigned NElts = getVectorMinNumElements();
    482       return !(NElts & (NElts - 1));
    483     }
    484 
    485     /// Widens the length of the given vector MVT up to the nearest power of 2
    486     /// and returns that type.
    487     MVT getPow2VectorType() const {
    488       if (isPow2VectorType())
    489         return *this;
    490 
    491       ElementCount NElts = getVectorElementCount();
    492       unsigned NewMinCount = 1 << Log2_32_Ceil(NElts.getKnownMinValue());
    493       NElts = ElementCount::get(NewMinCount, NElts.isScalable());
    494       return MVT::getVectorVT(getVectorElementType(), NElts);
    495     }
    496 
    497     /// If this is a vector, return the element type, otherwise return this.
    498     MVT getScalarType() const {
    499       return isVector() ? getVectorElementType() : *this;
    500     }
    501 
    502     MVT getVectorElementType() const {
    503       switch (SimpleTy) {
    504       default:
    505         llvm_unreachable("Not a vector MVT!");
    506       case v1i1:
    507       case v2i1:
    508       case v4i1:
    509       case v8i1:
    510       case v16i1:
    511       case v32i1:
    512       case v64i1:
    513       case v128i1:
    514       case v256i1:
    515       case v512i1:
    516       case v1024i1:
    517       case nxv1i1:
    518       case nxv2i1:
    519       case nxv4i1:
    520       case nxv8i1:
    521       case nxv16i1:
    522       case nxv32i1:
    523       case nxv64i1: return i1;
    524       case v1i8:
    525       case v2i8:
    526       case v4i8:
    527       case v8i8:
    528       case v16i8:
    529       case v32i8:
    530       case v64i8:
    531       case v128i8:
    532       case v256i8:
    533       case nxv1i8:
    534       case nxv2i8:
    535       case nxv4i8:
    536       case nxv8i8:
    537       case nxv16i8:
    538       case nxv32i8:
    539       case nxv64i8: return i8;
    540       case v1i16:
    541       case v2i16:
    542       case v3i16:
    543       case v4i16:
    544       case v8i16:
    545       case v16i16:
    546       case v32i16:
    547       case v64i16:
    548       case v128i16:
    549       case v256i16:
    550       case nxv1i16:
    551       case nxv2i16:
    552       case nxv4i16:
    553       case nxv8i16:
    554       case nxv16i16:
    555       case nxv32i16: return i16;
    556       case v1i32:
    557       case v2i32:
    558       case v3i32:
    559       case v4i32:
    560       case v5i32:
    561       case v8i32:
    562       case v16i32:
    563       case v32i32:
    564       case v64i32:
    565       case v128i32:
    566       case v256i32:
    567       case v512i32:
    568       case v1024i32:
    569       case v2048i32:
    570       case nxv1i32:
    571       case nxv2i32:
    572       case nxv4i32:
    573       case nxv8i32:
    574       case nxv16i32:
    575       case nxv32i32: return i32;
    576       case v1i64:
    577       case v2i64:
    578       case v4i64:
    579       case v8i64:
    580       case v16i64:
    581       case v32i64:
    582       case v64i64:
    583       case v128i64:
    584       case v256i64:
    585       case nxv1i64:
    586       case nxv2i64:
    587       case nxv4i64:
    588       case nxv8i64:
    589       case nxv16i64:
    590       case nxv32i64: return i64;
    591       case v1i128: return i128;
    592       case v1f16:
    593       case v2f16:
    594       case v3f16:
    595       case v4f16:
    596       case v8f16:
    597       case v16f16:
    598       case v32f16:
    599       case v64f16:
    600       case v128f16:
    601       case v256f16:
    602       case nxv1f16:
    603       case nxv2f16:
    604       case nxv4f16:
    605       case nxv8f16:
    606       case nxv16f16:
    607       case nxv32f16: return f16;
    608       case v2bf16:
    609       case v3bf16:
    610       case v4bf16:
    611       case v8bf16:
    612       case v16bf16:
    613       case v32bf16:
    614       case v64bf16:
    615       case v128bf16:
    616       case nxv1bf16:
    617       case nxv2bf16:
    618       case nxv4bf16:
    619       case nxv8bf16: return bf16;
    620       case v1f32:
    621       case v2f32:
    622       case v3f32:
    623       case v4f32:
    624       case v5f32:
    625       case v8f32:
    626       case v16f32:
    627       case v32f32:
    628       case v64f32:
    629       case v128f32:
    630       case v256f32:
    631       case v512f32:
    632       case v1024f32:
    633       case v2048f32:
    634       case nxv1f32:
    635       case nxv2f32:
    636       case nxv4f32:
    637       case nxv8f32:
    638       case nxv16f32: return f32;
    639       case v1f64:
    640       case v2f64:
    641       case v4f64:
    642       case v8f64:
    643       case v16f64:
    644       case v32f64:
    645       case v64f64:
    646       case v128f64:
    647       case v256f64:
    648       case nxv1f64:
    649       case nxv2f64:
    650       case nxv4f64:
    651       case nxv8f64: return f64;
    652       }
    653     }
    654 
    655     /// Given a vector type, return the minimum number of elements it contains.
    656     unsigned getVectorMinNumElements() const {
    657       switch (SimpleTy) {
    658       default:
    659         llvm_unreachable("Not a vector MVT!");
    660       case v2048i32:
    661       case v2048f32: return 2048;
    662       case v1024i1:
    663       case v1024i32:
    664       case v1024f32: return 1024;
    665       case v512i1:
    666       case v512i32:
    667       case v512f32: return 512;
    668       case v256i1:
    669       case v256i8:
    670       case v256i16:
    671       case v256f16:
    672       case v256i32:
    673       case v256i64:
    674       case v256f32:
    675       case v256f64: return 256;
    676       case v128i1:
    677       case v128i8:
    678       case v128i16:
    679       case v128i32:
    680       case v128i64:
    681       case v128f16:
    682       case v128bf16:
    683       case v128f32:
    684       case v128f64: return 128;
    685       case v64i1:
    686       case v64i8:
    687       case v64i16:
    688       case v64i32:
    689       case v64i64:
    690       case v64f16:
    691       case v64bf16:
    692       case v64f32:
    693       case v64f64:
    694       case nxv64i1:
    695       case nxv64i8: return 64;
    696       case v32i1:
    697       case v32i8:
    698       case v32i16:
    699       case v32i32:
    700       case v32i64:
    701       case v32f16:
    702       case v32bf16:
    703       case v32f32:
    704       case v32f64:
    705       case nxv32i1:
    706       case nxv32i8:
    707       case nxv32i16:
    708       case nxv32i32:
    709       case nxv32i64:
    710       case nxv32f16: return 32;
    711       case v16i1:
    712       case v16i8:
    713       case v16i16:
    714       case v16i32:
    715       case v16i64:
    716       case v16f16:
    717       case v16bf16:
    718       case v16f32:
    719       case v16f64:
    720       case nxv16i1:
    721       case nxv16i8:
    722       case nxv16i16:
    723       case nxv16i32:
    724       case nxv16i64:
    725       case nxv16f16:
    726       case nxv16f32: return 16;
    727       case v8i1:
    728       case v8i8:
    729       case v8i16:
    730       case v8i32:
    731       case v8i64:
    732       case v8f16:
    733       case v8bf16:
    734       case v8f32:
    735       case v8f64:
    736       case nxv8i1:
    737       case nxv8i8:
    738       case nxv8i16:
    739       case nxv8i32:
    740       case nxv8i64:
    741       case nxv8f16:
    742       case nxv8bf16:
    743       case nxv8f32:
    744       case nxv8f64: return 8;
    745       case v5i32:
    746       case v5f32: return 5;
    747       case v4i1:
    748       case v4i8:
    749       case v4i16:
    750       case v4i32:
    751       case v4i64:
    752       case v4f16:
    753       case v4bf16:
    754       case v4f32:
    755       case v4f64:
    756       case nxv4i1:
    757       case nxv4i8:
    758       case nxv4i16:
    759       case nxv4i32:
    760       case nxv4i64:
    761       case nxv4f16:
    762       case nxv4bf16:
    763       case nxv4f32:
    764       case nxv4f64: return 4;
    765       case v3i16:
    766       case v3i32:
    767       case v3f16:
    768       case v3bf16:
    769       case v3f32: return 3;
    770       case v2i1:
    771       case v2i8:
    772       case v2i16:
    773       case v2i32:
    774       case v2i64:
    775       case v2f16:
    776       case v2bf16:
    777       case v2f32:
    778       case v2f64:
    779       case nxv2i1:
    780       case nxv2i8:
    781       case nxv2i16:
    782       case nxv2i32:
    783       case nxv2i64:
    784       case nxv2f16:
    785       case nxv2bf16:
    786       case nxv2f32:
    787       case nxv2f64: return 2;
    788       case v1i1:
    789       case v1i8:
    790       case v1i16:
    791       case v1i32:
    792       case v1i64:
    793       case v1i128:
    794       case v1f16:
    795       case v1f32:
    796       case v1f64:
    797       case nxv1i1:
    798       case nxv1i8:
    799       case nxv1i16:
    800       case nxv1i32:
    801       case nxv1i64:
    802       case nxv1f16:
    803       case nxv1bf16:
    804       case nxv1f32:
    805       case nxv1f64: return 1;
    806       }
    807     }
    808 
    809     ElementCount getVectorElementCount() const {
    810       return ElementCount::get(getVectorMinNumElements(), isScalableVector());
    811     }
    812 
    813     unsigned getVectorNumElements() const {
    814       // TODO: Check that this isn't a scalable vector.
    815       return getVectorMinNumElements();
    816     }
    817 
    818     /// Returns the size of the specified MVT in bits.
    819     ///
    820     /// If the value type is a scalable vector type, the scalable property will
    821     /// be set and the runtime size will be a positive integer multiple of the
    822     /// base size.
    823     TypeSize getSizeInBits() const {
    824       switch (SimpleTy) {
    825       default:
    826         llvm_unreachable("getSizeInBits called on extended MVT.");
    827       case Other:
    828         llvm_unreachable("Value type is non-standard value, Other.");
    829       case iPTR:
    830         llvm_unreachable("Value type size is target-dependent. Ask TLI.");
    831       case iPTRAny:
    832       case iAny:
    833       case fAny:
    834       case vAny:
    835       case Any:
    836         llvm_unreachable("Value type is overloaded.");
    837       case token:
    838         llvm_unreachable("Token type is a sentinel that cannot be used "
    839                          "in codegen and has no size");
    840       case Metadata:
    841         llvm_unreachable("Value type is metadata.");
    842       case i1:
    843       case v1i1: return TypeSize::Fixed(1);
    844       case nxv1i1: return TypeSize::Scalable(1);
    845       case v2i1: return TypeSize::Fixed(2);
    846       case nxv2i1: return TypeSize::Scalable(2);
    847       case v4i1: return TypeSize::Fixed(4);
    848       case nxv4i1: return TypeSize::Scalable(4);
    849       case i8  :
    850       case v1i8:
    851       case v8i1: return TypeSize::Fixed(8);
    852       case nxv1i8:
    853       case nxv8i1: return TypeSize::Scalable(8);
    854       case i16 :
    855       case f16:
    856       case bf16:
    857       case v16i1:
    858       case v2i8:
    859       case v1i16:
    860       case v1f16: return TypeSize::Fixed(16);
    861       case nxv16i1:
    862       case nxv2i8:
    863       case nxv1i16:
    864       case nxv1bf16:
    865       case nxv1f16: return TypeSize::Scalable(16);
    866       case f32 :
    867       case i32 :
    868       case v32i1:
    869       case v4i8:
    870       case v2i16:
    871       case v2f16:
    872       case v2bf16:
    873       case v1f32:
    874       case v1i32: return TypeSize::Fixed(32);
    875       case nxv32i1:
    876       case nxv4i8:
    877       case nxv2i16:
    878       case nxv1i32:
    879       case nxv2f16:
    880       case nxv2bf16:
    881       case nxv1f32: return TypeSize::Scalable(32);
    882       case v3i16:
    883       case v3f16:
    884       case v3bf16: return TypeSize::Fixed(48);
    885       case x86mmx:
    886       case f64 :
    887       case i64 :
    888       case v64i1:
    889       case v8i8:
    890       case v4i16:
    891       case v2i32:
    892       case v1i64:
    893       case v4f16:
    894       case v4bf16:
    895       case v2f32:
    896       case v1f64: return TypeSize::Fixed(64);
    897       case nxv64i1:
    898       case nxv8i8:
    899       case nxv4i16:
    900       case nxv2i32:
    901       case nxv1i64:
    902       case nxv4f16:
    903       case nxv4bf16:
    904       case nxv2f32:
    905       case nxv1f64: return TypeSize::Scalable(64);
    906       case f80 :  return TypeSize::Fixed(80);
    907       case v3i32:
    908       case v3f32: return TypeSize::Fixed(96);
    909       case f128:
    910       case ppcf128:
    911       case i128:
    912       case v128i1:
    913       case v16i8:
    914       case v8i16:
    915       case v4i32:
    916       case v2i64:
    917       case v1i128:
    918       case v8f16:
    919       case v8bf16:
    920       case v4f32:
    921       case v2f64: return TypeSize::Fixed(128);
    922       case nxv16i8:
    923       case nxv8i16:
    924       case nxv4i32:
    925       case nxv2i64:
    926       case nxv8f16:
    927       case nxv8bf16:
    928       case nxv4f32:
    929       case nxv2f64: return TypeSize::Scalable(128);
    930       case v5i32:
    931       case v5f32: return TypeSize::Fixed(160);
    932       case v256i1:
    933       case v32i8:
    934       case v16i16:
    935       case v8i32:
    936       case v4i64:
    937       case v16f16:
    938       case v16bf16:
    939       case v8f32:
    940       case v4f64: return TypeSize::Fixed(256);
    941       case nxv32i8:
    942       case nxv16i16:
    943       case nxv8i32:
    944       case nxv4i64:
    945       case nxv16f16:
    946       case nxv8f32:
    947       case nxv4f64: return TypeSize::Scalable(256);
    948       case v512i1:
    949       case v64i8:
    950       case v32i16:
    951       case v16i32:
    952       case v8i64:
    953       case v32f16:
    954       case v32bf16:
    955       case v16f32:
    956       case v8f64: return TypeSize::Fixed(512);
    957       case nxv64i8:
    958       case nxv32i16:
    959       case nxv16i32:
    960       case nxv8i64:
    961       case nxv32f16:
    962       case nxv16f32:
    963       case nxv8f64: return TypeSize::Scalable(512);
    964       case v1024i1:
    965       case v128i8:
    966       case v64i16:
    967       case v32i32:
    968       case v16i64:
    969       case v64f16:
    970       case v64bf16:
    971       case v32f32:
    972       case v16f64: return TypeSize::Fixed(1024);
    973       case nxv32i32:
    974       case nxv16i64: return TypeSize::Scalable(1024);
    975       case v256i8:
    976       case v128i16:
    977       case v64i32:
    978       case v32i64:
    979       case v128f16:
    980       case v128bf16:
    981       case v64f32:
    982       case v32f64: return TypeSize::Fixed(2048);
    983       case nxv32i64: return TypeSize::Scalable(2048);
    984       case v256i16:
    985       case v128i32:
    986       case v64i64:
    987       case v256f16:
    988       case v128f32:
    989       case v64f64:  return TypeSize::Fixed(4096);
    990       case v256i32:
    991       case v128i64:
    992       case v256f32:
    993       case x86amx:
    994       case v128f64:  return TypeSize::Fixed(8192);
    995       case v512i32:
    996       case v256i64:
    997       case v512f32:
    998       case v256f64:  return TypeSize::Fixed(16384);
    999       case v1024i32:
   1000       case v1024f32:  return TypeSize::Fixed(32768);
   1001       case v2048i32:
   1002       case v2048f32:  return TypeSize::Fixed(65536);
   1003       case funcref:
   1004       case externref: return TypeSize::Fixed(0); // opaque type
   1005       }
   1006     }
   1007 
   1008     /// Return the size of the specified fixed width value type in bits. The
   1009     /// function will assert if the type is scalable.
   1010     uint64_t getFixedSizeInBits() const {
   1011       return getSizeInBits().getFixedSize();
   1012     }
   1013 
   1014     uint64_t getScalarSizeInBits() const {
   1015       return getScalarType().getSizeInBits().getFixedSize();
   1016     }
   1017 
   1018     /// Return the number of bytes overwritten by a store of the specified value
   1019     /// type.
   1020     ///
   1021     /// If the value type is a scalable vector type, the scalable property will
   1022     /// be set and the runtime size will be a positive integer multiple of the
   1023     /// base size.
   1024     TypeSize getStoreSize() const {
   1025       TypeSize BaseSize = getSizeInBits();
   1026       return {(BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable()};
   1027     }
   1028 
   1029     /// Return the number of bits overwritten by a store of the specified value
   1030     /// type.
   1031     ///
   1032     /// If the value type is a scalable vector type, the scalable property will
   1033     /// be set and the runtime size will be a positive integer multiple of the
   1034     /// base size.
   1035     TypeSize getStoreSizeInBits() const {
   1036       return getStoreSize() * 8;
   1037     }
   1038 
   1039     /// Returns true if the number of bits for the type is a multiple of an
   1040     /// 8-bit byte.
   1041     bool isByteSized() const { return getSizeInBits().isKnownMultipleOf(8); }
   1042 
   1043     /// Return true if we know at compile time this has more bits than VT.
   1044     bool knownBitsGT(MVT VT) const {
   1045       return TypeSize::isKnownGT(getSizeInBits(), VT.getSizeInBits());
   1046     }
   1047 
   1048     /// Return true if we know at compile time this has more than or the same
   1049     /// bits as VT.
   1050     bool knownBitsGE(MVT VT) const {
   1051       return TypeSize::isKnownGE(getSizeInBits(), VT.getSizeInBits());
   1052     }
   1053 
   1054     /// Return true if we know at compile time this has fewer bits than VT.
   1055     bool knownBitsLT(MVT VT) const {
   1056       return TypeSize::isKnownLT(getSizeInBits(), VT.getSizeInBits());
   1057     }
   1058 
   1059     /// Return true if we know at compile time this has fewer than or the same
   1060     /// bits as VT.
   1061     bool knownBitsLE(MVT VT) const {
   1062       return TypeSize::isKnownLE(getSizeInBits(), VT.getSizeInBits());
   1063     }
   1064 
   1065     /// Return true if this has more bits than VT.
   1066     bool bitsGT(MVT VT) const {
   1067       assert(isScalableVector() == VT.isScalableVector() &&
   1068              "Comparison between scalable and fixed types");
   1069       return knownBitsGT(VT);
   1070     }
   1071 
   1072     /// Return true if this has no less bits than VT.
   1073     bool bitsGE(MVT VT) const {
   1074       assert(isScalableVector() == VT.isScalableVector() &&
   1075              "Comparison between scalable and fixed types");
   1076       return knownBitsGE(VT);
   1077     }
   1078 
   1079     /// Return true if this has less bits than VT.
   1080     bool bitsLT(MVT VT) const {
   1081       assert(isScalableVector() == VT.isScalableVector() &&
   1082              "Comparison between scalable and fixed types");
   1083       return knownBitsLT(VT);
   1084     }
   1085 
   1086     /// Return true if this has no more bits than VT.
   1087     bool bitsLE(MVT VT) const {
   1088       assert(isScalableVector() == VT.isScalableVector() &&
   1089              "Comparison between scalable and fixed types");
   1090       return knownBitsLE(VT);
   1091     }
   1092 
   1093     static MVT getFloatingPointVT(unsigned BitWidth) {
   1094       switch (BitWidth) {
   1095       default:
   1096         llvm_unreachable("Bad bit width!");
   1097       case 16:
   1098         return MVT::f16;
   1099       case 32:
   1100         return MVT::f32;
   1101       case 64:
   1102         return MVT::f64;
   1103       case 80:
   1104         return MVT::f80;
   1105       case 128:
   1106         return MVT::f128;
   1107       }
   1108     }
   1109 
   1110     static MVT getIntegerVT(unsigned BitWidth) {
   1111       switch (BitWidth) {
   1112       default:
   1113         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
   1114       case 1:
   1115         return MVT::i1;
   1116       case 8:
   1117         return MVT::i8;
   1118       case 16:
   1119         return MVT::i16;
   1120       case 32:
   1121         return MVT::i32;
   1122       case 64:
   1123         return MVT::i64;
   1124       case 128:
   1125         return MVT::i128;
   1126       }
   1127     }
   1128 
   1129     static MVT getVectorVT(MVT VT, unsigned NumElements) {
   1130       switch (VT.SimpleTy) {
   1131       default:
   1132         break;
   1133       case MVT::i1:
   1134         if (NumElements == 1)    return MVT::v1i1;
   1135         if (NumElements == 2)    return MVT::v2i1;
   1136         if (NumElements == 4)    return MVT::v4i1;
   1137         if (NumElements == 8)    return MVT::v8i1;
   1138         if (NumElements == 16)   return MVT::v16i1;
   1139         if (NumElements == 32)   return MVT::v32i1;
   1140         if (NumElements == 64)   return MVT::v64i1;
   1141         if (NumElements == 128)  return MVT::v128i1;
   1142         if (NumElements == 256)  return MVT::v256i1;
   1143         if (NumElements == 512)  return MVT::v512i1;
   1144         if (NumElements == 1024) return MVT::v1024i1;
   1145         break;
   1146       case MVT::i8:
   1147         if (NumElements == 1)   return MVT::v1i8;
   1148         if (NumElements == 2)   return MVT::v2i8;
   1149         if (NumElements == 4)   return MVT::v4i8;
   1150         if (NumElements == 8)   return MVT::v8i8;
   1151         if (NumElements == 16)  return MVT::v16i8;
   1152         if (NumElements == 32)  return MVT::v32i8;
   1153         if (NumElements == 64)  return MVT::v64i8;
   1154         if (NumElements == 128) return MVT::v128i8;
   1155         if (NumElements == 256) return MVT::v256i8;
   1156         break;
   1157       case MVT::i16:
   1158         if (NumElements == 1)   return MVT::v1i16;
   1159         if (NumElements == 2)   return MVT::v2i16;
   1160         if (NumElements == 3)   return MVT::v3i16;
   1161         if (NumElements == 4)   return MVT::v4i16;
   1162         if (NumElements == 8)   return MVT::v8i16;
   1163         if (NumElements == 16)  return MVT::v16i16;
   1164         if (NumElements == 32)  return MVT::v32i16;
   1165         if (NumElements == 64)  return MVT::v64i16;
   1166         if (NumElements == 128) return MVT::v128i16;
   1167         if (NumElements == 256) return MVT::v256i16;
   1168         break;
   1169       case MVT::i32:
   1170         if (NumElements == 1)    return MVT::v1i32;
   1171         if (NumElements == 2)    return MVT::v2i32;
   1172         if (NumElements == 3)    return MVT::v3i32;
   1173         if (NumElements == 4)    return MVT::v4i32;
   1174         if (NumElements == 5)    return MVT::v5i32;
   1175         if (NumElements == 8)    return MVT::v8i32;
   1176         if (NumElements == 16)   return MVT::v16i32;
   1177         if (NumElements == 32)   return MVT::v32i32;
   1178         if (NumElements == 64)   return MVT::v64i32;
   1179         if (NumElements == 128)  return MVT::v128i32;
   1180         if (NumElements == 256)  return MVT::v256i32;
   1181         if (NumElements == 512)  return MVT::v512i32;
   1182         if (NumElements == 1024) return MVT::v1024i32;
   1183         if (NumElements == 2048) return MVT::v2048i32;
   1184         break;
   1185       case MVT::i64:
   1186         if (NumElements == 1)  return MVT::v1i64;
   1187         if (NumElements == 2)  return MVT::v2i64;
   1188         if (NumElements == 4)  return MVT::v4i64;
   1189         if (NumElements == 8)  return MVT::v8i64;
   1190         if (NumElements == 16) return MVT::v16i64;
   1191         if (NumElements == 32) return MVT::v32i64;
   1192         if (NumElements == 64) return MVT::v64i64;
   1193         if (NumElements == 128) return MVT::v128i64;
   1194         if (NumElements == 256) return MVT::v256i64;
   1195         break;
   1196       case MVT::i128:
   1197         if (NumElements == 1)  return MVT::v1i128;
   1198         break;
   1199       case MVT::f16:
   1200         if (NumElements == 1)   return MVT::v1f16;
   1201         if (NumElements == 2)   return MVT::v2f16;
   1202         if (NumElements == 3)   return MVT::v3f16;
   1203         if (NumElements == 4)   return MVT::v4f16;
   1204         if (NumElements == 8)   return MVT::v8f16;
   1205         if (NumElements == 16)  return MVT::v16f16;
   1206         if (NumElements == 32)  return MVT::v32f16;
   1207         if (NumElements == 64)  return MVT::v64f16;
   1208         if (NumElements == 128) return MVT::v128f16;
   1209         if (NumElements == 256) return MVT::v256f16;
   1210         break;
   1211       case MVT::bf16:
   1212         if (NumElements == 2)   return MVT::v2bf16;
   1213         if (NumElements == 3)   return MVT::v3bf16;
   1214         if (NumElements == 4)   return MVT::v4bf16;
   1215         if (NumElements == 8)   return MVT::v8bf16;
   1216         if (NumElements == 16)  return MVT::v16bf16;
   1217         if (NumElements == 32)  return MVT::v32bf16;
   1218         if (NumElements == 64)  return MVT::v64bf16;
   1219         if (NumElements == 128) return MVT::v128bf16;
   1220         break;
   1221       case MVT::f32:
   1222         if (NumElements == 1)    return MVT::v1f32;
   1223         if (NumElements == 2)    return MVT::v2f32;
   1224         if (NumElements == 3)    return MVT::v3f32;
   1225         if (NumElements == 4)    return MVT::v4f32;
   1226         if (NumElements == 5)    return MVT::v5f32;
   1227         if (NumElements == 8)    return MVT::v8f32;
   1228         if (NumElements == 16)   return MVT::v16f32;
   1229         if (NumElements == 32)   return MVT::v32f32;
   1230         if (NumElements == 64)   return MVT::v64f32;
   1231         if (NumElements == 128)  return MVT::v128f32;
   1232         if (NumElements == 256)  return MVT::v256f32;
   1233         if (NumElements == 512)  return MVT::v512f32;
   1234         if (NumElements == 1024) return MVT::v1024f32;
   1235         if (NumElements == 2048) return MVT::v2048f32;
   1236         break;
   1237       case MVT::f64:
   1238         if (NumElements == 1)  return MVT::v1f64;
   1239         if (NumElements == 2)  return MVT::v2f64;
   1240         if (NumElements == 4)  return MVT::v4f64;
   1241         if (NumElements == 8)  return MVT::v8f64;
   1242         if (NumElements == 16) return MVT::v16f64;
   1243         if (NumElements == 32) return MVT::v32f64;
   1244         if (NumElements == 64) return MVT::v64f64;
   1245         if (NumElements == 128) return MVT::v128f64;
   1246         if (NumElements == 256) return MVT::v256f64;
   1247         break;
   1248       }
   1249       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
   1250     }
   1251 
   1252     static MVT getScalableVectorVT(MVT VT, unsigned NumElements) {
   1253       switch(VT.SimpleTy) {
   1254         default:
   1255           break;
   1256         case MVT::i1:
   1257           if (NumElements == 1)  return MVT::nxv1i1;
   1258           if (NumElements == 2)  return MVT::nxv2i1;
   1259           if (NumElements == 4)  return MVT::nxv4i1;
   1260           if (NumElements == 8)  return MVT::nxv8i1;
   1261           if (NumElements == 16) return MVT::nxv16i1;
   1262           if (NumElements == 32) return MVT::nxv32i1;
   1263           if (NumElements == 64) return MVT::nxv64i1;
   1264           break;
   1265         case MVT::i8:
   1266           if (NumElements == 1)  return MVT::nxv1i8;
   1267           if (NumElements == 2)  return MVT::nxv2i8;
   1268           if (NumElements == 4)  return MVT::nxv4i8;
   1269           if (NumElements == 8)  return MVT::nxv8i8;
   1270           if (NumElements == 16) return MVT::nxv16i8;
   1271           if (NumElements == 32) return MVT::nxv32i8;
   1272           if (NumElements == 64) return MVT::nxv64i8;
   1273           break;
   1274         case MVT::i16:
   1275           if (NumElements == 1)  return MVT::nxv1i16;
   1276           if (NumElements == 2)  return MVT::nxv2i16;
   1277           if (NumElements == 4)  return MVT::nxv4i16;
   1278           if (NumElements == 8)  return MVT::nxv8i16;
   1279           if (NumElements == 16) return MVT::nxv16i16;
   1280           if (NumElements == 32) return MVT::nxv32i16;
   1281           break;
   1282         case MVT::i32:
   1283           if (NumElements == 1)  return MVT::nxv1i32;
   1284           if (NumElements == 2)  return MVT::nxv2i32;
   1285           if (NumElements == 4)  return MVT::nxv4i32;
   1286           if (NumElements == 8)  return MVT::nxv8i32;
   1287           if (NumElements == 16) return MVT::nxv16i32;
   1288           if (NumElements == 32) return MVT::nxv32i32;
   1289           break;
   1290         case MVT::i64:
   1291           if (NumElements == 1)  return MVT::nxv1i64;
   1292           if (NumElements == 2)  return MVT::nxv2i64;
   1293           if (NumElements == 4)  return MVT::nxv4i64;
   1294           if (NumElements == 8)  return MVT::nxv8i64;
   1295           if (NumElements == 16) return MVT::nxv16i64;
   1296           if (NumElements == 32) return MVT::nxv32i64;
   1297           break;
   1298         case MVT::f16:
   1299           if (NumElements == 1)  return MVT::nxv1f16;
   1300           if (NumElements == 2)  return MVT::nxv2f16;
   1301           if (NumElements == 4)  return MVT::nxv4f16;
   1302           if (NumElements == 8)  return MVT::nxv8f16;
   1303           if (NumElements == 16)  return MVT::nxv16f16;
   1304           if (NumElements == 32)  return MVT::nxv32f16;
   1305           break;
   1306         case MVT::bf16:
   1307           if (NumElements == 1)  return MVT::nxv1bf16;
   1308           if (NumElements == 2)  return MVT::nxv2bf16;
   1309           if (NumElements == 4)  return MVT::nxv4bf16;
   1310           if (NumElements == 8)  return MVT::nxv8bf16;
   1311           break;
   1312         case MVT::f32:
   1313           if (NumElements == 1)  return MVT::nxv1f32;
   1314           if (NumElements == 2)  return MVT::nxv2f32;
   1315           if (NumElements == 4)  return MVT::nxv4f32;
   1316           if (NumElements == 8)  return MVT::nxv8f32;
   1317           if (NumElements == 16) return MVT::nxv16f32;
   1318           break;
   1319         case MVT::f64:
   1320           if (NumElements == 1)  return MVT::nxv1f64;
   1321           if (NumElements == 2)  return MVT::nxv2f64;
   1322           if (NumElements == 4)  return MVT::nxv4f64;
   1323           if (NumElements == 8)  return MVT::nxv8f64;
   1324           break;
   1325       }
   1326       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
   1327     }
   1328 
   1329     static MVT getVectorVT(MVT VT, unsigned NumElements, bool IsScalable) {
   1330       if (IsScalable)
   1331         return getScalableVectorVT(VT, NumElements);
   1332       return getVectorVT(VT, NumElements);
   1333     }
   1334 
   1335     static MVT getVectorVT(MVT VT, ElementCount EC) {
   1336       if (EC.isScalable())
   1337         return getScalableVectorVT(VT, EC.getKnownMinValue());
   1338       return getVectorVT(VT, EC.getKnownMinValue());
   1339     }
   1340 
   1341     /// Return the value type corresponding to the specified type.  This returns
   1342     /// all pointers as iPTR.  If HandleUnknown is true, unknown types are
   1343     /// returned as Other, otherwise they are invalid.
   1344     static MVT getVT(Type *Ty, bool HandleUnknown = false);
   1345 
   1346   private:
   1347     /// A simple iterator over the MVT::SimpleValueType enum.
   1348     struct mvt_iterator {
   1349       SimpleValueType VT;
   1350 
   1351       mvt_iterator(SimpleValueType VT) : VT(VT) {}
   1352 
   1353       MVT operator*() const { return VT; }
   1354       bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
   1355 
   1356       mvt_iterator& operator++() {
   1357         VT = (MVT::SimpleValueType)((int)VT + 1);
   1358         assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
   1359                "MVT iterator overflowed.");
   1360         return *this;
   1361       }
   1362     };
   1363 
   1364     /// A range of the MVT::SimpleValueType enum.
   1365     using mvt_range = iterator_range<mvt_iterator>;
   1366 
   1367   public:
   1368     /// SimpleValueType Iteration
   1369     /// @{
   1370     static mvt_range all_valuetypes() {
   1371       return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
   1372     }
   1373 
   1374     static mvt_range integer_valuetypes() {
   1375       return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
   1376                        (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
   1377     }
   1378 
   1379     static mvt_range fp_valuetypes() {
   1380       return mvt_range(MVT::FIRST_FP_VALUETYPE,
   1381                        (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
   1382     }
   1383 
   1384     static mvt_range vector_valuetypes() {
   1385       return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
   1386                        (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
   1387     }
   1388 
   1389     static mvt_range fixedlen_vector_valuetypes() {
   1390       return mvt_range(
   1391                MVT::FIRST_FIXEDLEN_VECTOR_VALUETYPE,
   1392                (MVT::SimpleValueType)(MVT::LAST_FIXEDLEN_VECTOR_VALUETYPE + 1));
   1393     }
   1394 
   1395     static mvt_range scalable_vector_valuetypes() {
   1396       return mvt_range(
   1397                MVT::FIRST_SCALABLE_VECTOR_VALUETYPE,
   1398                (MVT::SimpleValueType)(MVT::LAST_SCALABLE_VECTOR_VALUETYPE + 1));
   1399     }
   1400 
   1401     static mvt_range integer_fixedlen_vector_valuetypes() {
   1402       return mvt_range(
   1403        MVT::FIRST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE,
   1404        (MVT::SimpleValueType)(MVT::LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE + 1));
   1405     }
   1406 
   1407     static mvt_range fp_fixedlen_vector_valuetypes() {
   1408       return mvt_range(
   1409           MVT::FIRST_FP_FIXEDLEN_VECTOR_VALUETYPE,
   1410           (MVT::SimpleValueType)(MVT::LAST_FP_FIXEDLEN_VECTOR_VALUETYPE + 1));
   1411     }
   1412 
   1413     static mvt_range integer_scalable_vector_valuetypes() {
   1414       return mvt_range(
   1415        MVT::FIRST_INTEGER_SCALABLE_VECTOR_VALUETYPE,
   1416        (MVT::SimpleValueType)(MVT::LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE + 1));
   1417     }
   1418 
   1419     static mvt_range fp_scalable_vector_valuetypes() {
   1420       return mvt_range(
   1421             MVT::FIRST_FP_SCALABLE_VECTOR_VALUETYPE,
   1422             (MVT::SimpleValueType)(MVT::LAST_FP_SCALABLE_VECTOR_VALUETYPE + 1));
   1423     }
   1424     /// @}
   1425   };
   1426 
   1427 } // end namespace llvm
   1428 
   1429 #endif // LLVM_SUPPORT_MACHINEVALUETYPE_H
   1430