[Mlir-commits] [mlir] [mlir][emitc] Restrict types in EmitC (PR #88391)

Javier Setoain llvmlistbot at llvm.org
Fri May 3 04:27:17 PDT 2024


jsetoain wrote:

> Assuming you would expect a bfloat16 represented as follows in your C code:
> 
> ```
> reprOfYourBf16Type myVar; // Variable declaration of myVar with the bfloat16 type
> ```
> 
> When you convert from some dialect that uses bfloat16 to EmitC, you can add a [type converter](https://mlir.llvm.org/docs/DialectConversion/#type-conversion) that describes what your type will look like in EmitC. Converting bfloat16 could look similar to this:
> 
> ```
> TypeConverter typeConverter;
> typeConverter.addConversion([this](Type type) -> std::optional<Type> {
>   // Convert bfloat16 to emitc.opaque
>   if (type.isBF16()) {
>     return emitc::OpaqueType::get(this->getContext(), "reprOfYourBf16Type");
>   }
>   // ...possibly more conversions....
>   return type;  // default for all types which are allowed in EmitC
> });
> ```

I see. I did understand, then. I believe we're indeed abusing the dialect because we don't convert everything to emitc before translating, we end up with a mix of dialects before translation so we end up with unreconciled unrealized casts. I will work around this the best I can, thank you both for your clarifications!

https://github.com/llvm/llvm-project/pull/88391


More information about the Mlir-commits mailing list