[llvm] 867de15 - [SVE] Mark VectorType::getNumElements() deprecated

Christopher Tetreault via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 15:13:19 PDT 2020


Author: Christopher Tetreault
Date: 2020-08-31T15:13:04-07:00
New Revision: 867de151a52b6d0750485ac1cf9b3bc012ee51fd

URL: https://github.com/llvm/llvm-project/commit/867de151a52b6d0750485ac1cf9b3bc012ee51fd
DIFF: https://github.com/llvm/llvm-project/commit/867de151a52b6d0750485ac1cf9b3bc012ee51fd.diff

LOG: [SVE] Mark VectorType::getNumElements() deprecated

getNumElements() is being removed from base VectorType in
order to eliminate the class of bugs in which a scalable vector
is accidentally treated like a fixed length vector. Clients of
this function should either call getElementCount(), and handle
the case where getElementCount().isScalable() is true, or they can
cast to FixedVectorType and call getNumElements() if they are
sure that the vector has fixed width.

Deprecated VectorType functions will be removed after the LLVM
12 branch.

See: http://lists.llvm.org/pipermail/llvm-dev/2020-March/139811.html

Reviewed By: fpetrogalli

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

Added: 
    

Modified: 
    llvm/include/llvm/IR/DerivedTypes.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/DerivedTypes.h b/llvm/include/llvm/IR/DerivedTypes.h
index 25ece7a060fd..619c699c2b97 100644
--- a/llvm/include/llvm/IR/DerivedTypes.h
+++ b/llvm/include/llvm/IR/DerivedTypes.h
@@ -423,21 +423,11 @@ class VectorType : public Type {
   /// Get the number of elements in this vector. It does not make sense to call
   /// this function on a scalable vector, and this will be moved into
   /// FixedVectorType in a future commit
-  unsigned getNumElements() const {
-    ElementCount EC = getElementCount();
-#ifdef STRICT_FIXED_SIZE_VECTORS
-    assert(!EC.isScalable() &&
-           "Request for fixed number of elements from scalable vector");
-    return EC.getKnownMinValue();
-#else
-    if (EC.isScalable())
-      WithColor::warning()
-          << "The code that requested the fixed number of elements has made "
-             "the assumption that this vector is not scalable. This assumption "
-             "was not correct, and this may lead to broken code\n";
-    return EC.getKnownMinValue();
-#endif
-  }
+  LLVM_ATTRIBUTE_DEPRECATED(
+      inline unsigned getNumElements() const,
+      "Calling this function via a base VectorType is deprecated. Either call "
+      "getElementCount() and handle the case where Scalable is true or cast to "
+      "FixedVectorType.");
 
   Type *getElementType() const { return ContainedType; }
 
@@ -540,6 +530,21 @@ class VectorType : public Type {
   }
 };
 
+unsigned VectorType::getNumElements() const {
+  ElementCount EC = getElementCount();
+#ifdef STRICT_FIXED_SIZE_VECTORS
+  assert(!EC.isScalable() &&
+         "Request for fixed number of elements from scalable vector");
+#else
+  if (EC.isScalable())
+    WithColor::warning()
+        << "The code that requested the fixed number of elements has made the "
+           "assumption that this vector is not scalable. This assumption was "
+           "not correct, and this may lead to broken code\n";
+#endif
+  return EC.getKnownMinValue();
+}
+
 /// Class to represent fixed width SIMD vectors
 class FixedVectorType : public VectorType {
 protected:
@@ -583,6 +588,8 @@ class FixedVectorType : public VectorType {
   static bool classof(const Type *T) {
     return T->getTypeID() == FixedVectorTyID;
   }
+
+  unsigned getNumElements() const { return ElementQuantity; }
 };
 
 /// Class to represent scalable SIMD vectors


        


More information about the llvm-commits mailing list