@@ -386,7 +386,7 @@ uint64_t Type::getArrayNumElements() const {
386386 return cast<ArrayType>(this )->getNumElements ();
387387}
388388
389- // / Class to represent vector types.
389+ // / Base class of all SIMD vector types
390390class VectorType : public Type {
391391 // / A fully specified VectorType is of the form <vscale x n x Ty>. 'n' is the
392392 // / minimum number of elements of type Ty contained within the vector, and
@@ -403,24 +403,22 @@ class VectorType : public Type {
403403
404404 // / The element type of the vector.
405405 Type *ContainedType;
406- // / Minumum number of elements in the vector.
407- uint64_t NumElements;
408406
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;
411409
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);
416412
417413public:
418414 VectorType (const VectorType &) = delete ;
419415 VectorType &operator =(const VectorType &) = delete ;
420416
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+
424422 Type *getElementType () const { return ContainedType; }
425423
426424 // / This static method is the primary way to construct an VectorType.
@@ -430,6 +428,10 @@ class VectorType : public Type {
430428 return VectorType::get (ElementType, {NumElements, Scalable});
431429 }
432430
431+ static VectorType *get (Type *ElementType, const VectorType *Other) {
432+ return VectorType::get (ElementType, Other->getElementCount ());
433+ }
434+
433435 // / This static method gets a VectorType with the same number of elements as
434436 // / the input type, and the element type is an integer type of the same width
435437 // / as the input element type.
@@ -507,26 +509,53 @@ class VectorType : public Type {
507509
508510 // / Return an ElementCount instance to represent the (possibly scalable)
509511 // / 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; }
515513
516514 // / Returns whether or not this is a scalable vector (meaning the total
517515 // / element count is a multiple of the minimum).
518- bool isScalable () const {
519- return Scalable;
520- }
516+ bool isScalable () const { return EC.Scalable ; }
521517
522518 // / Methods for support type inquiry through isa, cast, and dyn_cast.
523519 static bool classof (const Type *T) {
524- return T->getTypeID () == VectorTyID;
520+ return T->getTypeID () == FixedVectorTyID ||
521+ T->getTypeID () == ScalableVectorTyID;
525522 }
526523};
527524
528525bool Type::isVectorTy () const { return isa<VectorType>(this ); }
529526
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+
530559// / Class to represent pointers.
531560class PointerType : public Type {
532561 explicit PointerType (Type *ElType, unsigned AddrSpace);
0 commit comments