When converting to C code, the EmitC printer fails to handle builtin.unrealized_conversion_cast
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
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](https://github.com/user-attachments/files/22424795/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.
Contributor guide
Research direction
Reproduce the failure with input.mlir using the listed mlir-opt pass pipeline, then inspect the CppEmitter entry point for handling EmitC operations and builtin.unrealized_conversion_cast. Done means the produced EmitC IR translates to C++ without the unable-to-find-printer error for the shown cast.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100