Index: mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp =================================================================== --- mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp +++ mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp @@ -261,6 +261,8 @@ // For other memory spaces, use the size of the pointer to the default memory // space. + if (isOpaque()) + return dataLayout.getTypeSizeInBits(get(getContext())); return dataLayout.getTypeSizeInBits(get(getElementType())); } @@ -270,6 +272,8 @@ getPointerDataLayoutEntry(params, *this, DLEntryPos::Abi)) return *alignment; + if (isOpaque()) + return dataLayout.getTypeABIAlignment(get(getContext())); return dataLayout.getTypeABIAlignment(get(getElementType())); } @@ -280,6 +284,8 @@ getPointerDataLayoutEntry(params, *this, DLEntryPos::Preferred)) return *alignment; + if (isOpaque()) + return dataLayout.getTypePreferredAlignment(get(getContext())); return dataLayout.getTypePreferredAlignment(get(getElementType())); } Index: mlir/test/Dialect/LLVMIR/layout.mlir =================================================================== --- mlir/test/Dialect/LLVMIR/layout.mlir +++ mlir/test/Dialect/LLVMIR/layout.mlir @@ -33,6 +33,11 @@ // CHECK: preferred = 8 // CHECK: size = 8 "test.data_layout_query"() : () -> !llvm.ptr + // CHECK: alignment = 8 + // CHECK: bitsize = 64 + // CHECK: preferred = 8 + // CHECK: size = 8 + "test.data_layout_query"() : () -> !llvm.ptr<5> return } } @@ -75,6 +80,11 @@ // CHECK: preferred = 8 // CHECK: size = 8 "test.data_layout_query"() : () -> !llvm.ptr + // CHECK: alignment = 4 + // CHECK: bitsize = 32 + // CHECK: preferred = 8 + // CHECK: size = 4 + "test.data_layout_query"() : () -> !llvm.ptr<3> return } }