This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Add llvm.mlir.cast op for semantic preserving cast between dialect types.
ClosedPublic

Authored by timshen on Feb 25 2020, 2:03 PM.

Diff Detail

Event Timeline

timshen created this revision.Feb 25 2020, 2:03 PM
timshen updated this revision to Diff 246570.Feb 25 2020, 2:17 PM

Add more tests.

timshen updated this revision to Diff 246573.Feb 25 2020, 2:25 PM

Error message.

ftynse requested changes to this revision.Feb 26 2020, 1:22 AM

Makes sense to me, mostly nits.

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
689

Nit: drop "MLIR" from the def name, we are not using it in other operations (constant, undef)

704

Nit: the implicit convention for cast operations is to use type($in) 'to' type($res), let's follow it here as well.

mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
1820

Nit: I'd say that the llvm.mlir.cast itself isn't legal, not the conversion.

Actually, I'm not convinced we want to report an error from the pattern at all. There may be cases where a partial conversion is sufficient and the caller will deal with the remaining casts properly, yet we would have reported the error to the user by that time....

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
898

Don't you also want to support memrefs?

This revision now requires changes to proceed.Feb 26 2020, 1:22 AM
timshen updated this revision to Diff 246876.Feb 26 2020, 8:27 PM
timshen marked 6 inline comments as done.

Update per comments.

timshen marked an inline comment as done.Feb 26 2020, 8:28 PM
timshen added inline comments.
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
689

Well it has to be named as "SomethingCast", as LLVM_CastOp already exists. Renamed to "DialectCast".

mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
1820

Good point. Removed the error reporting.

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
898

memref is complicated because of the descriptor. Do we allow the conversion between a memref and the aligned base pointer, or a memref and the descriptor? Neither seems trivial to implement to me, nor I really need it at the moment. Added a TODO.

timshen marked an inline comment as done.Feb 26 2020, 8:28 PM
ftynse accepted this revision.Feb 27 2020, 6:30 AM
ftynse added inline comments.
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
898

I'd say between memref and descriptor. But you are right that it adds a lot of complexity since the descriptor type depends on the parameters of the lowering.

This revision is now accepted and ready to land.Feb 27 2020, 6:30 AM
rriddle added inline comments.Feb 27 2020, 8:44 AM
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
704

nit: use "" for single line strings.

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
900

nit: Please drop all trivial braces.

914

nit: Please use early return instead. That allows for dropping the else.

timshen updated this revision to Diff 247071.Feb 27 2020, 12:39 PM
timshen marked 3 inline comments as done.

Stylistic change and add a comment on why not support memref at the moment.