[clang] [CIR] Support builtin matrix type (PR #221773)

Amr Hesham via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 8 13:00:11 PDT 2026


================
@@ -1583,6 +1583,36 @@ void cir::VectorType::print(mlir::AsmPrinter &odsPrinter) const {
   odsPrinter << ">";
 }
 
+//===----------------------------------------------------------------------===//
+// MatrixType Definitions
+//===----------------------------------------------------------------------===//
+
+llvm::TypeSize cir::MatrixType::getTypeSizeInBits(
+    const ::mlir::DataLayout &dataLayout,
+    ::mlir::DataLayoutEntryListRef params) const {
+  return llvm::TypeSize::getFixed(
+      getRowNum() * getColumnNum() *
+      dataLayout.getTypeSizeInBits(getElementType()));
+}
+
+uint64_t
+cir::MatrixType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
+                                 ::mlir::DataLayoutEntryListRef params) const {
+  // This hook answers in bytes, not bits.
+  return llvm::PowerOf2Ceil(
+      llvm::divideCeil(dataLayout.getTypeSizeInBits(*this), 8u));
+}
+
+mlir::LogicalResult cir::MatrixType::verify(
+    llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
+    mlir::Type elementType, uint64_t row, uint64_t column) {
+  if (row == 0)
+    return emitError() << "the number of matrix rows must be non-zero";
----------------
AmrDeveloper wrote:

Test added :D

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


More information about the cfe-commits mailing list