Skip to content

Commit 4357a66

Browse files
authored
[mlir][DLTI] Make getPreferredAlignment default to getABIAlignment (llvm#128754)
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.
1 parent 00f02fe commit 4357a66

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.td

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class LLVMType<string typeName, string typeMnemonic, list<Trait> traits = []>
2525
//===----------------------------------------------------------------------===//
2626

2727
def LLVMArrayType : LLVMType<"LLVMArray", "array", [
28-
DeclareTypeInterfaceMethods<DataLayoutTypeInterface, ["getTypeSize"]>,
28+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface,
29+
["getTypeSize", "getPreferredAlignment"]>,
2930
DeclareTypeInterfaceMethods<DestructurableTypeInterface>]> {
3031
let summary = "LLVM array type";
3132
let description = [{
@@ -124,7 +125,7 @@ def LLVMFunctionType : LLVMType<"LLVMFunction", "func"> {
124125
def LLVMStructType : LLVMType<"LLVMStruct", "struct", [
125126
MutableType,
126127
DeclareTypeInterfaceMethods<DataLayoutTypeInterface,
127-
["areCompatible", "verifyEntries"]>,
128+
["areCompatible", "verifyEntries", "getPreferredAlignment"]>,
128129
DeclareTypeInterfaceMethods<DestructurableTypeInterface,
129130
["getSubelementIndexMap", "getTypeAtIndex"]>
130131
]> {
@@ -257,7 +258,8 @@ def LLVMStructType : LLVMType<"LLVMStruct", "struct", [
257258

258259
def LLVMPointerType : LLVMType<"LLVMPointer", "ptr", [
259260
DeclareTypeInterfaceMethods<DataLayoutTypeInterface, [
260-
"getIndexBitwidth", "areCompatible", "verifyEntries"]>]> {
261+
"getIndexBitwidth", "areCompatible", "verifyEntries",
262+
"getPreferredAlignment"]>]> {
261263
let summary = "LLVM pointer type";
262264
let description = [{
263265
The `!llvm.ptr` type is an LLVM pointer type. This type typically represents

mlir/include/mlir/Dialect/Ptr/IR/PtrDialect.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class Ptr_Type<string name, string typeMnemonic, list<Trait> traits = []>
3838
def Ptr_PtrType : Ptr_Type<"Ptr", "ptr", [
3939
MemRefElementTypeInterface,
4040
DeclareTypeInterfaceMethods<DataLayoutTypeInterface, [
41-
"areCompatible", "getIndexBitwidth", "verifyEntries"]>
41+
"areCompatible", "getIndexBitwidth", "verifyEntries",
42+
"getPreferredAlignment"]>
4243
]> {
4344
let summary = "pointer type";
4445
let description = [{

mlir/include/mlir/Interfaces/DataLayoutInterfaces.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,11 @@ def DataLayoutTypeInterface : TypeInterface<"DataLayoutTypeInterface"> {
598598
/*retTy=*/"uint64_t",
599599
/*methodName=*/"getPreferredAlignment",
600600
/*args=*/(ins "const ::mlir::DataLayout &":$dataLayout,
601-
"::mlir::DataLayoutEntryListRef":$params)
601+
"::mlir::DataLayoutEntryListRef":$params),
602+
/*methodBody=*/"",
603+
/*defaultImplementation=*/[{
604+
return $_type.getABIAlignment(dataLayout, params);
605+
}]
602606
>,
603607
InterfaceMethod<
604608
/*description=*/"Returns the bitwidth that should be used when "

mlir/test/lib/Dialect/Test/TestTypeDefs.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ def TestType : Test_Type<"Test", [
148148
}
149149

150150
def TestTypeWithLayoutType : Test_Type<"TestTypeWithLayout", [
151-
DeclareTypeInterfaceMethods<DataLayoutTypeInterface, ["getIndexBitwidth",
152-
"areCompatible"]>
151+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface,
152+
["getIndexBitwidth", "areCompatible", "getPreferredAlignment"]>
153153
]> {
154154
let mnemonic = "test_type_with_layout";
155155
let parameters = (ins "unsigned":$key);

0 commit comments

Comments
 (0)