This is an archive of the discontinued LLVM Phabricator instance.

[mlir][llvm] Support pointer entries in data layout translation
ClosedPublic

Authored by rkayaith on Sep 7 2022, 9:46 AM.

Details

Summary

This adds support for pointer DLTI entries in LLVMIR export, e.g.

// translated to: p0:32:64:128
#dlti.dl_entry<!llvm.ptr, dense<[32,64,128]> : vector<3xi32>>
// translated to: p1:32:32:32:64
#dlti.dl_entry<!llvm.ptr<1>, dense<[32,32,32,64]> : vector<4xi32>>

Diff Detail

Event Timeline

rkayaith created this revision.Sep 7 2022, 9:46 AM
Herald added a project: Restricted Project. · View Herald Transcript
rkayaith edited the summary of this revision. (Show Details)Sep 7 2022, 9:47 AM
rkayaith published this revision for review.Sep 7 2022, 10:06 AM
rkayaith added inline comments.
mlir/test/Target/LLVMIR/data-layout.mlir
7

This ignores the idx field of the pointer spec. I'm not sure how to handle that, since we don't support per-addrspace index widths in MLIR. Would it be correct to just set all address spaces to use the type size of index? And how should that work on the import side, when translating datalayout -> DLTI?

rkayaith added inline comments.Sep 12 2022, 8:31 PM
mlir/test/Target/LLVMIR/data-layout.mlir
7

@ftynse any thoughts here?

Could we also add a test with non-default address space to see how it looks in DLTI?

mlir/test/Target/LLVMIR/data-layout.mlir
7

I think we can support the field, at least for roundtripping. At the LLVM dialect level, there is no index type anymore. Any pointer address manipulation that treats them as integers is better off using whatever LLVM expects it to use rather than the converted index type.

rkayaith updated this revision to Diff 459737.Sep 13 2022, 6:36 AM

add test using non-default address space

rkayaith updated this revision to Diff 459860.Sep 13 2022, 1:18 PM

Support translating the (optional) 'idx' layout value as well

rkayaith marked an inline comment as done.Sep 13 2022, 1:22 PM
rkayaith added inline comments.Sep 15 2022, 10:52 AM
mlir/test/Target/LLVMIR/data-layout.mlir
7

I've added support for exporting the 4th element of dense attribute as the idx field. Looks like the verifier already allowed an optional fourth element so it didn't need any updates, though I didn't see it being used anywhere until now.

I had to make extractPointerSpecValue public to be able to use it during translation.

ftynse accepted this revision.Sep 21 2022, 6:35 AM
ftynse added inline comments.
mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h
538

Nit: carry over the documentation comment from DLEntryPos here.

539
This revision is now accepted and ready to land.Sep 21 2022, 6:35 AM
rkayaith updated this revision to Diff 461895.Sep 21 2022, 7:42 AM
rkayaith marked 2 inline comments as done.
rkayaith edited the summary of this revision. (Show Details)

update comments

This revision was landed with ongoing or failed builds.Sep 21 2022, 8:16 AM
This revision was automatically updated to reflect the committed changes.