[Mlir-commits] [mlir] [mlir][EmitC] Refactor MLIR Translate To Cpp (PR #84973)

Weizhe Chen llvmlistbot at llvm.org
Wed Mar 20 07:23:54 PDT 2024


weizchen wrote:

> I think it would be really valuable if you could post an IR snippet

Sure thing! Here is an IR snippet that has a similar idea with the Cache_Level example I talked about.

This TQue type comprises one enum attribute: TPosition (VECIN, VECOUT...) that represents hardware positions and a buffer number. 

``` mlir
// void type1(TQue<QuePosition::VECIN, 1> que1) {
func.func @type1(%arg0: !ascendc.TQue<VECIN, 1>) {
    return
}

// void type2(TQue<QuePosition::VECIN, 2> que1) {
func.func @type2(%arg0: !ascendc.TQue<VECIN, 2>) {
    return
}

// void type3(TQue<QuePosition::VECIN, 3> que1) {
func.func @type3(%arg0: !ascendc.TQue<VECIN, 3>) {
    return
}

// void type4(TQue<QuePosition::VECOUT, 2> que1) {
func.func @type4(%arg0: !ascendc.TQue<VECOUT, 2>) {
    return
}

// void type5(TQue<QuePosition::A1, 2> que1) {
func.func @type5(%arg0: !ascendc.TQue<A1, 2>) {
    return
}

// void type6(TQue<QuePosition::C1, 2> que1) {
func.func @type6(%arg0: !ascendc.TQue<C1, 2>) {
    return
}

```

Please correct me if I am missing anything, but in my understanding, if we want to lower this TQue type to EmitC Dialect, we have to lower it to opaque type one by one. So for the six types above, I would need six different conversions to opaque, while this number can greatly increase with different combinations of TPosition and buffer number.

But if we can support custom printing, for example like `os << "TQue<QuePosition::" << tque.getTposition() << ", " << tque.getBufNum() << ">";` this would easily solve the problem. I hope this brings more context to you and I am very open to your suggestions about EmitC Conversion.

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


More information about the Mlir-commits mailing list