From 5ce37bf28f344e37ffb403dee2f6f4165225a600 Mon Sep 17 00:00:00 2001 From: Mogball Date: Tue, 25 Feb 2025 10:17:34 -0800 Subject: [PATCH] [mlir][DLTI] Make `getPreferredAlignment` default to `getABIAlignment` Many types don't have a preferred alignment, but often specifying an ABI alignment is required to implement APIs on top of data layouts. Default the preferred alignment to `getABIAlignment` to simplify things. --- mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td | 8 +++++--- mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td | 3 ++- mlir/include/mlir/Interfaces/DataLayoutInterfaces.td | 6 +++++- mlir/test/lib/Dialect/Test/TestTypeDefs.td | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td index 0b9e4b9c55738..2ecbf8f50c50c 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td @@ -25,7 +25,8 @@ class LLVMType traits = []> //===----------------------------------------------------------------------===// def LLVMArrayType : LLVMType<"LLVMArray", "array", [ - DeclareTypeInterfaceMethods, + DeclareTypeInterfaceMethods, DeclareTypeInterfaceMethods]> { let summary = "LLVM array type"; let description = [{ @@ -124,7 +125,7 @@ def LLVMFunctionType : LLVMType<"LLVMFunction", "func"> { def LLVMStructType : LLVMType<"LLVMStruct", "struct", [ MutableType, DeclareTypeInterfaceMethods, + ["areCompatible", "verifyEntries", "getPreferredAlignment"]>, DeclareTypeInterfaceMethods ]> { @@ -257,7 +258,8 @@ def LLVMStructType : LLVMType<"LLVMStruct", "struct", [ def LLVMPointerType : LLVMType<"LLVMPointer", "ptr", [ DeclareTypeInterfaceMethods]> { + "getIndexBitwidth", "areCompatible", "verifyEntries", + "getPreferredAlignment"]>]> { let summary = "LLVM pointer type"; let description = [{ The `!llvm.ptr` type is an LLVM pointer type. This type typically represents diff --git a/mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td b/mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td index 14d72c3001d91..bc377dcc72e48 100644 --- a/mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td +++ b/mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td @@ -38,7 +38,8 @@ class Ptr_Type traits = []> def Ptr_PtrType : Ptr_Type<"Ptr", "ptr", [ MemRefElementTypeInterface, DeclareTypeInterfaceMethods + "areCompatible", "getIndexBitwidth", "verifyEntries", + "getPreferredAlignment"]> ]> { let summary = "pointer type"; let description = [{ diff --git a/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td b/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td index 0d09b92928fe3..3e4733d252015 100644 --- a/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td +++ b/mlir/include/mlir/Interfaces/DataLayoutInterfaces.td @@ -598,7 +598,11 @@ def DataLayoutTypeInterface : TypeInterface<"DataLayoutTypeInterface"> { /*retTy=*/"uint64_t", /*methodName=*/"getPreferredAlignment", /*args=*/(ins "const ::mlir::DataLayout &":$dataLayout, - "::mlir::DataLayoutEntryListRef":$params) + "::mlir::DataLayoutEntryListRef":$params), + /*methodBody=*/"", + /*defaultImplementation=*/[{ + return $_type.getABIAlignment(dataLayout, params); + }] >, InterfaceMethod< /*description=*/"Returns the bitwidth that should be used when " diff --git a/mlir/test/lib/Dialect/Test/TestTypeDefs.td b/mlir/test/lib/Dialect/Test/TestTypeDefs.td index 6335701786ecc..079ffb22e02c2 100644 --- a/mlir/test/lib/Dialect/Test/TestTypeDefs.td +++ b/mlir/test/lib/Dialect/Test/TestTypeDefs.td @@ -148,8 +148,8 @@ def TestType : Test_Type<"Test", [ } def TestTypeWithLayoutType : Test_Type<"TestTypeWithLayout", [ - DeclareTypeInterfaceMethods + DeclareTypeInterfaceMethods ]> { let mnemonic = "test_type_with_layout"; let parameters = (ins "unsigned":$key);