[SAOC 2026] MLIR support Weekly Update #2

Asadbek aosindarov at gmail.com
Tue Sep 29 12:35:42 UTC 2026


Hello everyone,

Here is my progress for `Week 2`. This week I have actually 
something to show. I have configured MLIR integration to LDC 
compiler using CMake and added parsing logic just as done for 
`LDC_inline_ir` but for `LDC_inline_mlir`.

In ldc `druntime` there is a module with name `ldc.llvmasm` [1]. 
It contains functions that allows us to write inlined llvm IR and 
asm code. Well, I have added a new function that allows us to 
inline mlir ir. It is as simple as:

```
pragma(LDC_inline_mlir)
     R __mlir(string s, R, P ...)(P params) @trusted nothrow @nogc;

```

It could be used as follows:
```
int add(int a, int b) {
     return __mlir!(`
         %res = arith.addi %arg0, %arg1 : i32
         return %res : i32
     `, int, int, int)(a, b);
}
```

Currently the names of the variables or so called virtual 
registers within mlir ir code should follow the SSA value naming 
as `%arg0`, `%arg1` and so on for function arguments, as with the 
llvm ir.

I have created draft PR [2] with simple initial test cases and I 
plan to add more soon.

The plan for the coming week is to split this PR into smaller 
reviewable parts and upstream them and continue following the 
plans in the milestones.

Thank you for reading this, if you have come this far!

[1] 
https://github.com/ldc-developers/ldc/blob/master/runtime/druntime/src/ldc/llvmasm.di
[2] https://github.com/ldc-developers/ldc/pull/5295


More information about the Digitalmars-d mailing list