diff options
author | Twice <twice@apache.org> | 2025-10-11 11:28:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-10-11 11:28:45 +0800 |
commit | 7aec3f2864e8ea968e7d164e784f9d7038807a5d (patch) | |
tree | 2f21b4395641a39cb0b5734011660bc5f1fe0ba4 /llvm/unittests/Object/ELFObjectFileTest.cpp | |
parent | 0b462f6f8363cc09494d3df102bdd9c114d4558a (diff) | |
download | llvm-7aec3f2864e8ea968e7d164e784f9d7038807a5d.zip llvm-7aec3f2864e8ea968e7d164e784f9d7038807a5d.tar.gz llvm-7aec3f2864e8ea968e7d164e784f9d7038807a5d.tar.bz2 |
[MLIR][Python] Support Python-defined rewrite patterns (#162699)
This PR adds support for defining custom **`RewritePattern`**
implementations directly in the Python bindings.
Previously, users could define similar patterns using the PDL dialect’s
bindings. However, for more complex patterns, this often required
writing multiple Python callbacks as PDL native constraints or rewrite
functions, which made the overall logic less intuitive—though it could
be more performant than a pure Python implementation (especially for
simple patterns).
With this change, we introduce an additional, straightforward way to
define patterns purely in Python, complementing the existing PDL-based
approach.
### Example
```python
def to_muli(op, rewriter):
with rewriter.ip:
new_op = arith.muli(op.operands[0], op.operands[1], loc=op.location)
rewriter.replace_op(op, new_op.owner)
with Context():
patterns = RewritePatternSet()
patterns.add(arith.AddIOp, to_muli) # a pattern that rewrites arith.addi to arith.muli
frozen = patterns.freeze()
module = ...
apply_patterns_and_fold_greedily(module, frozen)
```
---------
Co-authored-by: Maksim Levental <maksim.levental@gmail.com>
Diffstat (limited to 'llvm/unittests/Object/ELFObjectFileTest.cpp')
0 files changed, 0 insertions, 0 deletions