How to convert mix dialect into one dialect?

MLIR support coexistence of multiple dialects.

suppose that DialectA is the beginning dialect, DialectD is the ending dialect
DialectA will be partially lowered into DialectB and DialectC
my question is , how to convert DialectB & DialectC to DialectD?

one approach is to define a pass (DialectBAndDialectC2DialectD)
another approach is to define two passes seperately (DialectB2DialectD and DialectC2DialectD)
or is there other approach ?

how to handle this problem gracefully ?
thanks to your help :slight_smile:

Upstream MLIR uses this approach and relies on unrealized_conversion_cast builtin operation to handle temporary type mismatches. This allows us to avoid the combinatorial explosion of conversions, imagine what would happen if we had 10 different dialects rather than just 2 in your example.

Downstreams can chose another approach if that makes sense for their dialect subset. For example, I am aware of projects that convert a dozen of dialects to the LLVM dialect in a single pass.

1 Like

many thanks