[mlir] Support index and memref types in llvm.mlir.cast
authorAlex Zinenko <zinenko@google.com>
Wed, 16 Dec 2020 17:32:26 +0000 (18:32 +0100)
committerAlex Zinenko <zinenko@google.com>
Thu, 17 Dec 2020 08:21:42 +0000 (09:21 +0100)
commit96076a2edbd63e3e9d6ee0eca0c90d34579b7602
tree2d8f7af61ba55373b3b0c8bea4bc4af19cdb83e9
parentebdd20f430c408e200d5c60ef957e777841f0fa3
[mlir] Support index and memref types in llvm.mlir.cast

This operation is designed to support partial conversion, more specifically the
IR state in which some operations expect or produce built-in types and some
operations produce and expect LLVM dialect types. It is reasonable for it to
support cast between built-in types and any equivalent that could be produced
by the type conversion. (At the same time, we don't want the dialect to depend
on the type conversion as it could lead to a dependency cycle). Introduce
support for casting from index to any integer type and back, and from memref to
bare pointer or memref descriptor type and back.

Contrary to what the TODO in the code stated, there are no particular
precautions necessary to handle the bare pointer conversion for memerfs. This
conversion applies exclusively to statically-shaped memrefs, so we can always
recover the full descriptor contents from the type.

This patch simultaneously tightens the verification for other types to only
accept matching pairs of types, e.g., i64 and !llvm.i64, as opposed to the
previous implementation that only checked if the types were generally allowed
byt not for matching, e.g. i64 could be "casted" to !llvm.bfloat, which is not
the intended semantics.

Move the relevant test under test/Dialect/LLVMIR because it is not specific to
the conversion pass, but rather exercises an op in the dialect. If we decide
this op does not belong to the LLVM dialect, both the dialect and the op should
move together.

Reviewed By: silvas, ezhulenev

Differential Revision: https://reviews.llvm.org/D93405
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/test/Conversion/StandardToLLVM/invalid.mlir
mlir/test/Dialect/LLVMIR/dialect-cast.mlir [new file with mode: 0644]