[Mlir-commits] [mlir] [MLIR][Python] Add a DSL for defining dialects in Python bindings (PR #169045)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Jan 9 04:10:23 PST 2026
PragmaTwice wrote:
I'm happy to share that I finished a fairly large refactor incorporating many great suggestions from @rolfmorel. A simple dialect definition currently looks like this:
```python
class MyInt(ext.Dialect, name="myint"):
pass
i32 = IntegerType[32]
class ConstantOp(MyInt.Operation, name="constant"):
value: IntegerAttr
cst: OpResult[i32]
class AddOp(MyInt.Operation, name="add"):
lhs: OpOperand[i32]
rhs: OpOperand[i32]
res: OpResult[i32]
MyInt.load()
```
Type annotation | IRDL concept / mapping
-- | --
`x: OpOperand[T]` | `operands(x: T, ..)`
`x: OpResult[T]` | `results(x: T, ..)`
`x: XXXAttr` | `attributes(x: base(XXXAttr), ..)`
`x: Optional[...]` | optional operand/result
`x: Sequence[...]` | variadic operand/result
`XXXType` | `base(XXXType)`
`XXXType[args..]` | `is(TypeAttr.get(XXXType.get(args..)))`
`IntegerType[32]` | `is(TypeAttr.get(IntegerType.get(32)))`
`XXXAttr` | `base(XXXAttr)`
`XXXAttr[args..]` | `is(XXXAttr.get(args..))`
`T \| U` | `any_of(T, U)`
`TypeVar` or `Any` | `any()`
https://github.com/llvm/llvm-project/pull/169045
More information about the Mlir-commits
mailing list