Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir][Transforms] Dialect conversion: Make materializations optional #107109

Merged

Commits on Sep 5, 2024

  1. [mlir][Transforms] Dialect conversion: Make materializations optional (

    …#104668)
    
    This commit makes source/target/argument materializations (via the
    `TypeConverter` API) optional.
    
    By default (`ConversionConfig::buildMaterializations = true`), the
    dialect conversion infrastructure tries to legalize all unresolved
    materializations right after the main transformation process has
    succeeded. If at least one unresolved materialization fails to resolve,
    the dialect conversion fails. (With an error message such as `failed to
    legalize unresolved materialization ...`.) Automatic materializations
    through the `TypeConverter` API can now be deactivated. In that case,
    every unresolved materialization will show up as a
    `builtin.unrealized_conversion_cast` op in the output IR.
    
    There used to be a complex and error-prone analysis in the dialect
    conversion that predicted the future uses of unresolved
    materializations. Based on that logic, some casts (that were deemed to
    unnecessary) were folded. This analysis was needed because folding
    happened at a point of time when some IR changes (e.g., op replacements)
    had not materialized yet.
    
    This commit removes that analysis. Any folding of cast ops now happens
    after all other IR changes have been materialized and the uses can
    directly be queried from the IR. This simplifies the analysis
    significantly. And certain helper data structures such as
    `inverseMapping` are no longer needed for the analysis. The folding
    itself is done by `reconcileUnrealizedCasts` (which also exists as a
    standalone pass).
    
    After casts have been folded, the remaining casts are materialized
    through the `TypeConverter`, as usual. This last step can be deactivated
    in the `ConversionConfig`.
    
    `ConversionConfig::buildMaterializations = false` can be used to debug
    error messages such as `failed to legalize unresolved materialization
    ...`. (It is also useful in case automatic materializations are not
    needed.) The materializations that failed to resolve can then be seen as
    `builtin.unrealized_conversion_cast` ops in the resulting IR. (This is
    better than running with `-debug`, because `-debug` shows IR where some
    IR changes have not been materialized yet.)
    
    Note: This is a reupload of #104668, but with correct handling of cyclic unrealized_conversion_casts that may be generated by the dialect conversion.
    matthias-springer committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    ecadaec View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2b887ee View commit details
    Browse the repository at this point in the history