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