This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Support index and memref types in llvm.mlir.cast
ClosedPublic

Authored by ftynse on Dec 16 2020, 9:34 AM.

Details

Summary

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.

Diff Detail

Event Timeline

ftynse created this revision.Dec 16 2020, 9:34 AM
ftynse requested review of this revision.Dec 16 2020, 9:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2020, 9:34 AM
ezhulenev accepted this revision.Dec 16 2020, 9:58 AM

Thanks!

This revision is now accepted and ready to land.Dec 16 2020, 9:58 AM
silvas accepted this revision.Dec 16 2020, 2:26 PM

Awesome!

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

nit: I don't think "tensors" was inteded here.

ftynse marked an inline comment as done.Dec 17 2020, 12:20 AM
This revision was landed with ongoing or failed builds.Dec 17 2020, 12:21 AM
This revision was automatically updated to reflect the committed changes.