[llvm] 947be4a - [SVE] Do not store a bool for Scalable in VectorType

Christopher Tetreault via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 24 10:36:43 PDT 2020


Author: Christopher Tetreault
Date: 2020-04-24T10:36:26-07:00
New Revision: 947be4a024b9701fcfd36656e01ba59bd7e2f486

URL: https://github.com/llvm/llvm-project/commit/947be4a024b9701fcfd36656e01ba59bd7e2f486
DIFF: https://github.com/llvm/llvm-project/commit/947be4a024b9701fcfd36656e01ba59bd7e2f486.diff

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

Summary:
- 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.

Reviewers: efriedma, fpetrogalli, kmclaughlin

Reviewed By: fpetrogalli

Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78601

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index 5dcecaef20e2..e7af4cf7fbc5 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -404,11 +404,17 @@ class VectorType : public Type {
   /// The element type of the vector.
   Type *ContainedType;
 
-  /// The element count of this vector
-  ElementCount EC;
-
 protected:
-  VectorType(Type *ElType, ElementCount EC, Type::TypeID TID);
+  /// The element quantity of this vector. The meaning of this value depends
+  /// on the type of vector:
+  /// - For FixedVectorType = <ElementQuantity x ty>, there are
+  ///   exactly ElementQuantity elements in this vector.
+  /// - For ScalableVectorType = <vscale x ElementQuantity x ty>,
+  ///   there are vscale * ElementQuantity elements in this vector, where
+  ///   vscale is a runtime-constant integer greater than 0.
+  const unsigned ElementQuantity;
+
+  VectorType(Type *ElType, unsigned EQ, Type::TypeID TID);
 
 public:
   VectorType(const VectorType &) = delete;
@@ -523,7 +529,7 @@ class VectorType : public Type {
 
   /// 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 +544,7 @@ bool Type::isVectorTy() const { return isa<VectorType>(this); }
 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 +558,24 @@ class FixedVectorType : public VectorType {
 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 ElementQuantity; }
 
   static bool classof(const Type *T) {
     return T->getTypeID() == ScalableVectorTyID;
   }
 };
 
+inline ElementCount VectorType::getElementCount() const {
+  return ElementCount(ElementQuantity, isa<ScalableVectorType>(this));
+}
+
 /// Class to represent pointers.
 class PointerType : public Type {
   explicit PointerType(Type *ElType, unsigned AddrSpace);

diff  --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index a86c09ebee26..8e5b03211132 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -580,8 +580,9 @@ bool ArrayType::isValidElementType(Type *ElemTy) {
 //                          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;
 }


        


More information about the llvm-commits mailing list