[Mlir-commits] [mlir] [mlir][emitc] Restrict types in EmitC (PR #88391)
Tina Jung
llvmlistbot at llvm.org
Thu May 2 23:56:10 PDT 2024
TinaAMD 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
});
```
https://github.com/llvm/llvm-project/pull/88391
More information about the Mlir-commits
mailing list