# Changeset View

Changeset View

# Standalone View

Standalone View

# llvm/trunk/include/llvm/IR/DerivedTypes.h

Show All 17 Lines | |||||

18 | #define LLVM_IR_DERIVEDTYPES_H | 18 | #define LLVM_IR_DERIVEDTYPES_H | ||

19 | 19 | | |||

20 | #include "llvm/ADT/ArrayRef.h" | 20 | #include "llvm/ADT/ArrayRef.h" | ||

21 | #include "llvm/ADT/STLExtras.h" | 21 | #include "llvm/ADT/STLExtras.h" | ||

22 | #include "llvm/ADT/StringRef.h" | 22 | #include "llvm/ADT/StringRef.h" | ||

23 | #include "llvm/IR/Type.h" | 23 | #include "llvm/IR/Type.h" | ||

24 | #include "llvm/Support/Casting.h" | 24 | #include "llvm/Support/Casting.h" | ||

25 | #include "llvm/Support/Compiler.h" | 25 | #include "llvm/Support/Compiler.h" | ||

26 | #include "llvm/Support/ScalableSize.h" | ||||

26 | #include <cassert> | 27 | #include <cassert> | ||

27 | #include <cstdint> | 28 | #include <cstdint> | ||

28 | 29 | | |||

29 | namespace llvm { | 30 | namespace llvm { | ||

30 | 31 | | |||

31 | class Value; | 32 | class Value; | ||

32 | class APInt; | 33 | class APInt; | ||

33 | class LLVMContext; | 34 | class LLVMContext; | ||

▲ Show 20 Lines • Show All 348 Lines • ▼ Show 20 Line(s) | 380 | SequentialType(TypeID TID, Type *ElType, uint64_t NumElements) | |||

382 | ContainedTys = &ContainedType; | 383 | ContainedTys = &ContainedType; | ||

383 | NumContainedTys = 1; | 384 | NumContainedTys = 1; | ||

384 | } | 385 | } | ||

385 | 386 | | |||

386 | public: | 387 | public: | ||

387 | SequentialType(const SequentialType &) = delete; | 388 | SequentialType(const SequentialType &) = delete; | ||

388 | SequentialType &operator=(const SequentialType &) = delete; | 389 | SequentialType &operator=(const SequentialType &) = delete; | ||

389 | 390 | | |||

391 | /// For scalable vectors, this will return the minimum number of elements | ||||

392 | /// in the vector. | ||||

390 | uint64_t getNumElements() const { return NumElements; } | 393 | uint64_t getNumElements() const { return NumElements; } | ||

391 | Type *getElementType() const { return ContainedType; } | 394 | Type *getElementType() const { return ContainedType; } | ||

392 | 395 | | |||

393 | /// Methods for support type inquiry through isa, cast, and dyn_cast. | 396 | /// Methods for support type inquiry through isa, cast, and dyn_cast. | ||

394 | static bool classof(const Type *T) { | 397 | static bool classof(const Type *T) { | ||

395 | return T->getTypeID() == ArrayTyID || T->getTypeID() == VectorTyID; | 398 | return T->getTypeID() == ArrayTyID || T->getTypeID() == VectorTyID; | ||

396 | } | 399 | } | ||

397 | }; | 400 | }; | ||

Show All 19 Lines | |||||

417 | }; | 420 | }; | ||

418 | 421 | | |||

419 | uint64_t Type::getArrayNumElements() const { | 422 | uint64_t Type::getArrayNumElements() const { | ||

420 | return cast<ArrayType>(this)->getNumElements(); | 423 | return cast<ArrayType>(this)->getNumElements(); | ||

421 | } | 424 | } | ||

422 | 425 | | |||

423 | /// Class to represent vector types. | 426 | /// Class to represent vector types. | ||

424 | class VectorType : public SequentialType { | 427 | class VectorType : public SequentialType { | ||

425 | VectorType(Type *ElType, unsigned NumEl); | 428 | /// A fully specified VectorType is of the form <vscale x n x Ty>. 'n' is the | ||

429 | /// minimum number of elements of type Ty contained within the vector, and | ||||

430 | /// 'scalable' indicates that the total element count is an integer multiple | ||||

431 | /// of 'n', where the multiple is either guaranteed to be one, or is | ||||

432 | /// statically unknown at compile time. | ||||

433 | /// | ||||

434 | /// If the multiple is known to be 1, then the extra term is discarded in | ||||

435 | /// textual IR: | ||||

436 | /// | ||||

437 | /// <4 x i32> - a vector containing 4 i32s | ||||

438 | /// <vscale x 4 x i32> - a vector containing an unknown integer multiple | ||||

439 | /// of 4 i32s | ||||

440 | | ||||

441 | VectorType(Type *ElType, unsigned NumEl, bool Scalable = false); | ||||

442 | VectorType(Type *ElType, ElementCount EC); | ||||

443 | | ||||

444 | // If true, the total number of elements is an unknown multiple of the | ||||

445 | // minimum 'NumElements' from SequentialType. Otherwise the total number | ||||

446 | // of elements is exactly equal to 'NumElements'. | ||||

447 | bool Scalable; | ||||

426 | 448 | | |||

427 | public: | 449 | public: | ||

428 | VectorType(const VectorType &) = delete; | 450 | VectorType(const VectorType &) = delete; | ||

429 | VectorType &operator=(const VectorType &) = delete; | 451 | VectorType &operator=(const VectorType &) = delete; | ||

430 | 452 | | |||

431 | /// This static method is the primary way to construct an VectorType. | 453 | /// This static method is the primary way to construct an VectorType. | ||

432 | static VectorType *get(Type *ElementType, unsigned NumElements); | 454 | static VectorType *get(Type *ElementType, ElementCount EC); | ||

455 | static VectorType *get(Type *ElementType, unsigned NumElements, | ||||

456 | bool Scalable = false) { | ||||

457 | return VectorType::get(ElementType, {NumElements, Scalable}); | ||||

458 | } | ||||

433 | 459 | | |||

434 | /// This static method gets a VectorType with the same number of elements as | 460 | /// This static method gets a VectorType with the same number of elements as | ||

435 | /// the input type, and the element type is an integer type of the same width | 461 | /// the input type, and the element type is an integer type of the same width | ||

436 | /// as the input element type. | 462 | /// as the input element type. | ||

437 | static VectorType *getInteger(VectorType *VTy) { | 463 | static VectorType *getInteger(VectorType *VTy) { | ||

438 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); | 464 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); | ||

439 | assert(EltBits && "Element size must be of a non-zero size"); | 465 | assert(EltBits && "Element size must be of a non-zero size"); | ||

440 | Type *EltTy = IntegerType::get(VTy->getContext(), EltBits); | 466 | Type *EltTy = IntegerType::get(VTy->getContext(), EltBits); | ||

441 | return VectorType::get(EltTy, VTy->getNumElements()); | 467 | return VectorType::get(EltTy, VTy->getElementCount()); | ||

442 | } | 468 | } | ||

443 | 469 | | |||

444 | /// This static method is like getInteger except that the element types are | 470 | /// This static method is like getInteger except that the element types are | ||

445 | /// twice as wide as the elements in the input type. | 471 | /// twice as wide as the elements in the input type. | ||

446 | static VectorType *getExtendedElementVectorType(VectorType *VTy) { | 472 | static VectorType *getExtendedElementVectorType(VectorType *VTy) { | ||

447 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); | 473 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); | ||

448 | Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2); | 474 | Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2); | ||

449 | return VectorType::get(EltTy, VTy->getNumElements()); | 475 | return VectorType::get(EltTy, VTy->getElementCount()); | ||

450 | } | 476 | } | ||

451 | 477 | | |||

452 | /// This static method is like getInteger except that the element types are | 478 | /// This static method is like getInteger except that the element types are | ||

453 | /// half as wide as the elements in the input type. | 479 | /// half as wide as the elements in the input type. | ||

454 | static VectorType *getTruncatedElementVectorType(VectorType *VTy) { | 480 | static VectorType *getTruncatedElementVectorType(VectorType *VTy) { | ||

455 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); | 481 | unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits(); | ||

456 | assert((EltBits & 1) == 0 && | 482 | assert((EltBits & 1) == 0 && | ||

457 | "Cannot truncate vector element with odd bit-width"); | 483 | "Cannot truncate vector element with odd bit-width"); | ||

458 | Type *EltTy = IntegerType::get(VTy->getContext(), EltBits / 2); | 484 | Type *EltTy = IntegerType::get(VTy->getContext(), EltBits / 2); | ||

459 | return VectorType::get(EltTy, VTy->getNumElements()); | 485 | return VectorType::get(EltTy, VTy->getElementCount()); | ||

460 | } | 486 | } | ||

461 | 487 | | |||

462 | /// This static method returns a VectorType with half as many elements as the | 488 | /// This static method returns a VectorType with half as many elements as the | ||

463 | /// input type and the same element type. | 489 | /// input type and the same element type. | ||

464 | static VectorType *getHalfElementsVectorType(VectorType *VTy) { | 490 | static VectorType *getHalfElementsVectorType(VectorType *VTy) { | ||

465 | unsigned NumElts = VTy->getNumElements(); | 491 | auto EltCnt = VTy->getElementCount(); | ||

466 | assert ((NumElts & 1) == 0 && | 492 | assert ((EltCnt.Min & 1) == 0 && | ||

467 | "Cannot halve vector with odd number of elements."); | 493 | "Cannot halve vector with odd number of elements."); | ||

468 | return VectorType::get(VTy->getElementType(), NumElts/2); | 494 | return VectorType::get(VTy->getElementType(), EltCnt/2); | ||

469 | } | 495 | } | ||

470 | 496 | | |||

471 | /// This static method returns a VectorType with twice as many elements as the | 497 | /// This static method returns a VectorType with twice as many elements as the | ||

472 | /// input type and the same element type. | 498 | /// input type and the same element type. | ||

473 | static VectorType *getDoubleElementsVectorType(VectorType *VTy) { | 499 | static VectorType *getDoubleElementsVectorType(VectorType *VTy) { | ||

474 | unsigned NumElts = VTy->getNumElements(); | 500 | auto EltCnt = VTy->getElementCount(); | ||

475 | return VectorType::get(VTy->getElementType(), NumElts*2); | 501 | assert((VTy->getNumElements() * 2ull) <= UINT_MAX && | ||

502 | "Too many elements in vector"); | ||||

503 | return VectorType::get(VTy->getElementType(), EltCnt*2); | ||||

476 | } | 504 | } | ||

477 | 505 | | |||

478 | /// Return true if the specified type is valid as a element type. | 506 | /// Return true if the specified type is valid as a element type. | ||

479 | static bool isValidElementType(Type *ElemTy); | 507 | static bool isValidElementType(Type *ElemTy); | ||

480 | 508 | | |||

481 | /// Return the number of bits in the Vector type. | 509 | /// Return an ElementCount instance to represent the (possibly scalable) | ||

510 | /// number of elements in the vector. | ||||

511 | ElementCount getElementCount() const { | ||||

512 | uint64_t MinimumEltCnt = getNumElements(); | ||||

513 | assert(MinimumEltCnt <= UINT_MAX && "Too many elements in vector"); | ||||

514 | return { (unsigned)MinimumEltCnt, Scalable }; | ||||

515 | } | ||||

516 | | ||||

517 | /// Returns whether or not this is a scalable vector (meaning the total | ||||

518 | /// element count is a multiple of the minimum). | ||||

519 | bool isScalable() const { | ||||

520 | return Scalable; | ||||

521 | } | ||||

522 | | ||||

523 | /// Return the minimum number of bits in the Vector type. | ||||

482 | /// Returns zero when the vector is a vector of pointers. | 524 | /// Returns zero when the vector is a vector of pointers. | ||

483 | unsigned getBitWidth() const { | 525 | unsigned getBitWidth() const { | ||

484 | return getNumElements() * getElementType()->getPrimitiveSizeInBits(); | 526 | return getNumElements() * getElementType()->getPrimitiveSizeInBits(); | ||

485 | } | 527 | } | ||

486 | 528 | | |||

487 | /// Methods for support type inquiry through isa, cast, and dyn_cast. | 529 | /// Methods for support type inquiry through isa, cast, and dyn_cast. | ||

488 | static bool classof(const Type *T) { | 530 | static bool classof(const Type *T) { | ||

489 | return T->getTypeID() == VectorTyID; | 531 | return T->getTypeID() == VectorTyID; | ||

490 | } | 532 | } | ||

491 | }; | 533 | }; | ||

492 | 534 | | |||

493 | unsigned Type::getVectorNumElements() const { | 535 | unsigned Type::getVectorNumElements() const { | ||

494 | return cast<VectorType>(this)->getNumElements(); | 536 | return cast<VectorType>(this)->getNumElements(); | ||

495 | } | 537 | } | ||

496 | 538 | | |||

539 | bool Type::getVectorIsScalable() const { | ||||

540 | return cast<VectorType>(this)->isScalable(); | ||||

541 | } | ||||

542 | | ||||

497 | /// Class to represent pointers. | 543 | /// Class to represent pointers. | ||

498 | class PointerType : public Type { | 544 | class PointerType : public Type { | ||

499 | explicit PointerType(Type *ElType, unsigned AddrSpace); | 545 | explicit PointerType(Type *ElType, unsigned AddrSpace); | ||

500 | 546 | | |||

501 | Type *PointeeTy; | 547 | Type *PointeeTy; | ||

502 | 548 | | |||

503 | public: | 549 | public: | ||

504 | PointerType(const PointerType &) = delete; | 550 | PointerType(const PointerType &) = delete; | ||

Show All 36 Lines |