Skip to content

When converting to C code, the EmitC printer fails to handle builtin.unrealized_conversion_cast #159746

@LekkalaSravya3

Description

@LekkalaSravya3

When lowering to the EmitC dialect, MLIR inserts a builtin.unrealized_conversion_cast to connect types that do not have a direct conversion.
In this case, the lowering produces a cast from !emitc.ptr to !emitc.array<...xf32>.
When trying to emit C++ code, the CppEmitter fails

ERROR :

error: 'builtin.unrealized_conversion_cast' op unable to find printer for op
%9 = builtin.unrealized_conversion_cast %8 :
!emitc.ptr to !emitc.array<1x3x4x4xf32>

Input :

module {
    func.func @main(%arg0: tensor<1x3x4x4xf32>, %arg1: tensor<1x3x4x4xf32>)
        -> tensor<1x3x4x4xf32> {
      %3 = "tosa.add"(%arg0, %arg1)
           : (tensor<1x3x4x4xf32>, tensor<1x3x4x4xf32>)
           -> tensor<1x3x4x4xf32>
  
      %4 = "tosa.sub"(%3, %arg1)
           : (tensor<1x3x4x4xf32>, tensor<1x3x4x4xf32>)
           -> tensor<1x3x4x4xf32>
  
      return %4 : tensor<1x3x4x4xf32>
    }
  }

Run With :

  mlir-opt input.mlir -pass-pipeline="builtin.module(
    func.func(tosa-to-linalg),
    one-shot-bufferize{bufferize-function-boundaries function-boundary-type-conversion=identity-layout-map buffer-alignment=0},
    buffer-results-to-out-params{hoist-static-allocs=true},
    func.func(convert-linalg-to-loops),
    canonicalize,
    convert-to-emitc
  )" -o output.mlir

PRODUCED EMITC IR :

EMitcIR.txt

Steps to reproduce

Save the input MLIR program above.

Run the pipeline shown.

Attempt to translate the resulting EmitC IR to C++.

Observe that printing fails on the unrealized_conversion_cast.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions