llvm-project
e5114a20 - [MLIR][Python] Add python bindings for IRDL dialect (#158488)

Commit
157 days ago
[MLIR][Python] Add python bindings for IRDL dialect (#158488) In this PR we add basic python bindings for IRDL dialect, so that python users can create and load IRDL dialects in python. This allows users, to some extent, to define dialects in Python without having to modify MLIR’s CMake/TableGen/C++ code and rebuild, making prototyping more convenient. A basic example is shown below (and also in the added test case): ```python # create a module with IRDL dialects module = Module.create() with InsertionPoint(module.body): dialect = irdl.DialectOp("irdl_test") with InsertionPoint(dialect.body): op = irdl.OperationOp("test_op") with InsertionPoint(op.body): f32 = irdl.is_(TypeAttr.get(F32Type.get())) irdl.operands_([f32], ["input"], [irdl.Variadicity.single]) # load the module irdl.load_dialects(module) # use the op defined in IRDL m = Module.parse(""" module { %a = arith.constant 1.0 : f32 "irdl_test.test_op"(%a) : (f32) -> () } """) ```
Author
Parents
Loading