[PATCH] D78601: [SVE] Do not store a bool for Scalable in VectorType

Christopher Tetreault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 21 17:21:13 PDT 2020


ctetreau created this revision.
Herald added subscribers: llvm-commits, psnobl, rkruppe, hiraditya, tschuett.
Herald added a reviewer: efriedma.
Herald added a project: LLVM.
ctetreau added a parent revision: D77690: [SVE] Remove VectorType::isScalable().
ctetreau added reviewers: fpetrogalli, kmclaughlin.

- Whether or not a vector is scalable is a function of its type. Since

all instances of ScalableVectorType will have true for this value and
all instances of FixedVectorType will have false for this value, there
is no need to store it as a class member.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78601

Files:
  llvm/include/llvm/IR/DerivedTypes.h
  llvm/lib/IR/Type.cpp


Index: llvm/lib/IR/Type.cpp
===================================================================
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -584,8 +584,9 @@
 //                          VectorType Implementation
 //===----------------------------------------------------------------------===//
 
-VectorType::VectorType(Type *ElType, ElementCount EC, Type::TypeID TID)
-    : Type(ElType->getContext(), TID), ContainedType(ElType), EC(EC) {
+VectorType::VectorType(Type *ElType, unsigned EQ, Type::TypeID TID)
+    : Type(ElType->getContext(), TID), ContainedType(ElType),
+      ElementQuantity(EQ) {
   ContainedTys = &ContainedType;
   NumContainedTys = 1;
 }
Index: llvm/include/llvm/IR/DerivedTypes.h
===================================================================
--- llvm/include/llvm/IR/DerivedTypes.h
+++ llvm/include/llvm/IR/DerivedTypes.h
@@ -404,11 +404,14 @@
   /// The element type of the vector.
   Type *ContainedType;
 
-  /// The element count of this vector
-  ElementCount EC;
+  /// The element quantity of this vector. The meaning of this value depends
+  /// the type of vector
+  unsigned ElementQuantity;
 
 protected:
-  VectorType(Type *ElType, ElementCount EC, Type::TypeID TID);
+  VectorType(Type *ElType, unsigned EQ, Type::TypeID TID);
+
+  unsigned getElementQuantity() const { return ElementQuantity; }
 
 public:
   VectorType(const VectorType &) = delete;
@@ -523,7 +526,7 @@
 
   /// Return an ElementCount instance to represent the (possibly scalable)
   /// number of elements in the vector.
-  ElementCount getElementCount() const { return EC; }
+  inline ElementCount getElementCount() const;
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast.
   static bool classof(const Type *T) {
@@ -538,7 +541,7 @@
 class FixedVectorType : public VectorType {
 protected:
   FixedVectorType(Type *ElTy, unsigned NumElts)
-      : VectorType(ElTy, {NumElts, false}, FixedVectorTyID) {}
+      : VectorType(ElTy, NumElts, FixedVectorTyID) {}
 
 public:
   static FixedVectorType *get(Type *ElementType, unsigned NumElts);
@@ -552,20 +555,24 @@
 class ScalableVectorType : public VectorType {
 protected:
   ScalableVectorType(Type *ElTy, unsigned MinNumElts)
-      : VectorType(ElTy, {MinNumElts, true}, ScalableVectorTyID) {}
+      : VectorType(ElTy, MinNumElts, ScalableVectorTyID) {}
 
 public:
   static ScalableVectorType *get(Type *ElementType, unsigned MinNumElts);
 
   /// Get the minimum number of elements in this vector. The actual number of
   /// elements in the vector is an integer multiple of this value.
-  uint64_t getMinNumElements() const { return getElementCount().Min; }
+  uint64_t getMinNumElements() const { return getElementQuantity(); }
 
   static bool classof(const Type *T) {
     return T->getTypeID() == ScalableVectorTyID;
   }
 };
 
+inline ElementCount VectorType::getElementCount() const {
+  return ElementCount(getElementQuantity(), isa<ScalableVectorType>(this));
+}
+
 /// Class to represent pointers.
 class PointerType : public Type {
   explicit PointerType(Type *ElType, unsigned AddrSpace);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78601.259133.patch
Type: text/x-patch
Size: 3104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200422/94626415/attachment-0001.bin>


More information about the llvm-commits mailing list