[clang] [CIR] Upstream initial support for fixed size VectorType (PR #136488)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 21 12:55:37 PDT 2025


================
@@ -637,6 +637,42 @@ ArrayType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
   return dataLayout.getTypeABIAlignment(getEltType());
 }
 
+//===----------------------------------------------------------------------===//
+// VectorType Definitions
+//===----------------------------------------------------------------------===//
+
+llvm::TypeSize cir::VectorType::getTypeSizeInBits(
+    const ::mlir::DataLayout &dataLayout,
+    ::mlir::DataLayoutEntryListRef params) const {
+  return llvm::TypeSize::getFixed(
+      getSize() * dataLayout.getTypeSizeInBits(getElementType()));
+}
+
+uint64_t
+cir::VectorType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
+                                 ::mlir::DataLayoutEntryListRef params) const {
+  return llvm::NextPowerOf2(dataLayout.getTypeSizeInBits(*this));
+}
+
+mlir::LogicalResult cir::VectorType::verify(
+    llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
+    mlir::Type elementType, uint64_t size) {
+  if (size == 0)
+    return emitError() << "the number of vector elements must be non-zero";
+
+  // Check if it a valid FixedVectorType
+  if (mlir::isa<cir::PointerType, cir::FP128Type>(elementType))
+    return success();
+
+  // Check if it a valid VectorType
+  if (mlir::isa<cir::IntType>(elementType) ||
+      isAnyFloatingPointType(elementType))
+    return success();
+
+  return emitError() << "expected LLVM-compatible fixed-vector type "
----------------
andykaylor wrote:

This error message seems wrong, but I'm not sure what it should say. We're expecting a vector of a CIR type, right? Maybe this should say, "unsupported element type for CIR vector"?

https://github.com/llvm/llvm-project/pull/136488


More information about the cfe-commits mailing list