@@ -386,7 +386,7 @@ uint64_t Type::getArrayNumElements() const {
386
386
return cast<ArrayType>(this )->getNumElements ();
387
387
}
388
388
389
- // / Class to represent vector types.
389
+ // / Base class of all SIMD vector types
390
390
class VectorType : public Type {
391
391
// / A fully specified VectorType is of the form <vscale x n x Ty>. 'n' is the
392
392
// / minimum number of elements of type Ty contained within the vector, and
@@ -403,24 +403,22 @@ class VectorType : public Type {
403
403
404
404
// / The element type of the vector.
405
405
Type *ContainedType;
406
- // / Minumum number of elements in the vector.
407
- uint64_t NumElements;
408
406
409
- VectorType (Type *ElType, unsigned NumEl, bool Scalable = false );
410
- VectorType (Type *ElType, ElementCount EC) ;
407
+ // / The element count of this vector
408
+ ElementCount EC;
411
409
412
- // If true, the total number of elements is an unknown multiple of the
413
- // minimum 'NumElements'. Otherwise the total number of elements is exactly
414
- // equal to 'NumElements'.
415
- bool Scalable;
410
+ protected:
411
+ VectorType (Type *ElType, ElementCount EC, Type::TypeID TID);
416
412
417
413
public:
418
414
VectorType (const VectorType &) = delete ;
419
415
VectorType &operator =(const VectorType &) = delete ;
420
416
421
- // / For scalable vectors, this will return the minimum number of elements
422
- // / in the vector.
423
- unsigned getNumElements () const { return NumElements; }
417
+ // / Get the number of elements in this vector. It does not make sense to call
418
+ // / this function on a scalable vector, and this will be moved into
419
+ // / FixedVectorType in a future commit
420
+ unsigned getNumElements () const { return EC.Min ; }
421
+
424
422
Type *getElementType () const { return ContainedType; }
425
423
426
424
// / This static method is the primary way to construct an VectorType.
@@ -430,6 +428,10 @@ class VectorType : public Type {
430
428
return VectorType::get (ElementType, {NumElements, Scalable});
431
429
}
432
430
431
+ static VectorType *get (Type *ElementType, const VectorType *Other) {
432
+ return VectorType::get (ElementType, Other->getElementCount ());
433
+ }
434
+
433
435
// / This static method gets a VectorType with the same number of elements as
434
436
// / the input type, and the element type is an integer type of the same width
435
437
// / as the input element type.
@@ -507,26 +509,53 @@ class VectorType : public Type {
507
509
508
510
// / Return an ElementCount instance to represent the (possibly scalable)
509
511
// / number of elements in the vector.
510
- ElementCount getElementCount () const {
511
- uint64_t MinimumEltCnt = getNumElements ();
512
- assert (MinimumEltCnt <= UINT_MAX && " Too many elements in vector" );
513
- return { (unsigned )MinimumEltCnt, Scalable };
514
- }
512
+ ElementCount getElementCount () const { return EC; }
515
513
516
514
// / Returns whether or not this is a scalable vector (meaning the total
517
515
// / element count is a multiple of the minimum).
518
- bool isScalable () const {
519
- return Scalable;
520
- }
516
+ bool isScalable () const { return EC.Scalable ; }
521
517
522
518
// / Methods for support type inquiry through isa, cast, and dyn_cast.
523
519
static bool classof (const Type *T) {
524
- return T->getTypeID () == VectorTyID;
520
+ return T->getTypeID () == FixedVectorTyID ||
521
+ T->getTypeID () == ScalableVectorTyID;
525
522
}
526
523
};
527
524
528
525
bool Type::isVectorTy () const { return isa<VectorType>(this ); }
529
526
527
+ // / Class to represent fixed width SIMD vectors
528
+ class FixedVectorType : public VectorType {
529
+ protected:
530
+ FixedVectorType (Type *ElTy, unsigned NumElts)
531
+ : VectorType(ElTy, {NumElts, false }, FixedVectorTyID) {}
532
+
533
+ public:
534
+ static FixedVectorType *get (Type *ElementType, unsigned NumElts);
535
+
536
+ static bool classof (const Type *T) {
537
+ return T->getTypeID () == FixedVectorTyID;
538
+ }
539
+ };
540
+
541
+ // / Class to represent scalable SIMD vectors
542
+ class ScalableVectorType : public VectorType {
543
+ protected:
544
+ ScalableVectorType (Type *ElTy, unsigned MinNumElts)
545
+ : VectorType(ElTy, {MinNumElts, true }, ScalableVectorTyID) {}
546
+
547
+ public:
548
+ static ScalableVectorType *get (Type *ElementType, unsigned MinNumElts);
549
+
550
+ // / Get the minimum number of elements in this vector. The actual number of
551
+ // / elements in the vector is an integer multiple of this value.
552
+ uint64_t getMinNumElements () const { return getElementCount ().Min ; }
553
+
554
+ static bool classof (const Type *T) {
555
+ return T->getTypeID () == ScalableVectorTyID;
556
+ }
557
+ };
558
+
530
559
// / Class to represent pointers.
531
560
class PointerType : public Type {
532
561
explicit PointerType (Type *ElType, unsigned AddrSpace);
0 commit comments