This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Allow to specify target type in `convertType`
ClosedPublic

Authored by kuhar on Apr 19 2023, 9:14 AM.

Details

Summary

Add a new helper function for the type converter that takes care of
casting to the target type.

This is to avoid bugs where an incorrect cast function is used after
type conversion, e.g., dyn_cast or cast. These are not guaranteed to
work when type conversion fails, or when type conversion succeeds but
the provided type converted returned a type that a conversion pattern
did not expect.

I saw this being an issue in some SPIR-V passes and in mlir-hlo.

Exercise the new function in a couple of passes. As a side-effect, this
also made the code more concise.

Diff Detail

Event Timeline

kuhar created this revision.Apr 19 2023, 9:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2023, 9:14 AM
kuhar requested review of this revision.Apr 19 2023, 9:14 AM
kuhar edited the summary of this revision. (Show Details)Apr 19 2023, 9:14 AM
rriddle accepted this revision.Apr 19 2023, 10:16 AM
This revision is now accepted and ready to land.Apr 19 2023, 10:16 AM
mehdi_amini accepted this revision.Apr 19 2023, 10:30 AM

That makes the code quite nicer to read, thanks!

This revision was automatically updated to reflect the committed changes.