This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Allow dense array to be parsed with type elision
ClosedPublic

Authored by Mogball on Aug 30 2022, 12:15 PM.

Details

Summary

This patch makes parsing dense arrays with type elision work properly.
If a ranked tensor type is supplied to parseAttribute on a dense
array, the element type is skipped. Moreover, if type elision is set to
AttrTypeElision::Must, the element type is elided.

For example, this allows

memref.global @z : memref<3xi32> = array<1, 2, 3>

Fixes #57433

Depends on D132758

Diff Detail

Event Timeline

Mogball created this revision.Aug 30 2022, 12:15 PM
Mogball requested review of this revision.Aug 30 2022, 12:15 PM
rriddle accepted this revision.Aug 30 2022, 12:19 PM
rriddle added inline comments.
mlir/lib/IR/AsmPrinter.cpp
1869

Why is this printing through the os again? Why not print through the printer.

This revision is now accepted and ready to land.Aug 30 2022, 12:19 PM
Mogball updated this revision to Diff 456759.Aug 30 2022, 12:35 PM
Mogball marked an inline comment as done.

I added some tests. PTAL

Mogball added inline comments.Aug 30 2022, 12:35 PM
mlir/lib/IR/AsmPrinter.cpp
1869

Isn't this inside the printer already? Where stuff is being sent directly through the stream.

rriddle added inline comments.Aug 30 2022, 12:39 PM
mlir/lib/IR/AsmPrinter.cpp
1869

It's in the printer file, but calling operator<<(raw_ostream & is going to create a new nested AsmPrinter to print the type (i.e. it's going to call Type::print(os), which isn't what you want when you are already in the printer).

Mogball added inline comments.Aug 30 2022, 12:44 PM
mlir/lib/IR/AsmPrinter.cpp
1869

Right. I should be calling printType. Good catch

Thanks for the fix. Seems like this has a lot of asm forms now though, depending on how it gets printed (array<i8: 1, 2, 3>, array<1, 2, 3>, [1, 2, 3]).

Mogball updated this revision to Diff 456772.Aug 30 2022, 1:22 PM

use printType

Mogball marked an inline comment as done.Aug 30 2022, 1:22 PM
This revision was landed with ongoing or failed builds.Aug 30 2022, 1:29 PM
This revision was automatically updated to reflect the committed changes.