summaryrefslogtreecommitdiff
path: root/mlir/test/python/dialects/transform.py
AgeCommit message (Collapse)Author
2025-11-07[MLIR][Transform][Python] Sync derived classes and their wrappers (#166871)Rolf Morel
Updates the derived Op-classes for the main transform ops to have all the arguments, etc, from the auto-generated classes. Additionally updates and adds missing snake_case wrappers for the derived classes which shadow the snake_case wrappers of the auto-generated classes, which were hitherto exposed alongside the derived classes.
2025-06-16[MLIR][Transform] apply_registered_pass: support ListOptions (#144026)Rolf Morel
Interpret an option value with multiple values, either in the form of an `ArrayAttr` (either static or passed through a param) or as the multiple attrs associated to a param, as a comma-separated list, i.e. as a ListOption on a pass.
2025-06-11[MLIR][Transform] apply_registered_op fixes: arg order & python options ↵Rolf Morel
auto-conversion (#143779)
2025-06-11[MLIR][Transform] apply_registered_pass op's options as a dict (#143159)Rolf Morel
Improve ApplyRegisteredPassOp's support for taking options by taking them as a dict (vs a list of string-valued key-value pairs). Values of options are provided as either static attributes or as params (which pass in attributes at interpreter runtime). In either case, the keys and value attributes are converted to strings and a single options-string, in the format used on the commandline, is constructed to pass to the `addToPipeline`-pass API.
2023-11-08[mlir][python] Add support for arg_attrs and other attrs to NamedSequenceOpNicolas Vasilache
2023-11-08[mlir][python] Reland - Add sugared builder for transform.named_sequenceNicolas Vasilache
Address issues with #71597 post-revert and and reland
2023-11-08Revert "[mlir][python]Add sugared buider for transform.named_sequence (#71597)"Nicolas Vasilache
This reverts commit 4f51b2bfe3ec11b597272be6caa00efb575bc59f.
2023-11-08Revert "[mlir][python] NFC - Lint fix"Nicolas Vasilache
This reverts commit 8c014e5949fdbecc31a82138361f8cdf886768a9.
2023-11-08[mlir][python] NFC - Lint fixNicolas Vasilache
Followup from #71597
2023-11-08[mlir][python]Add sugared buider for transform.named_sequence (#71597)Nicolas Vasilache
2023-10-31[mlir][SCF] Use `transform.get_parent_op` instead of ↵Matthias Springer
`transform.loop.get_parent_for` (#70757) Add a new attribute to `get_parent_op` to get the n-th parent. Remove `transform.loop.get_parent_for`, which is no longer needed.
2023-09-26[mlir][python] Expose transform param types (#67421)martin-luecke
This exposes the Transform dialect types `AnyParamType` and `ParamType` via the Python bindings.
2023-08-23[mlir][python bindings] generate all the enumsmax
This PR implements python enum bindings for *all* the enums - this includes `I*Attrs` (including positional/bit) and `Dialect/EnumAttr`. There are a few parts to this: 1. CMake: a small addition to `declare_mlir_dialect_python_bindings` and `declare_mlir_dialect_extension_python_bindings` to generate the enum, a boolean arg `GEN_ENUM_BINDINGS` to make it opt-in (even though it works for basically all of the dialects), and an optional `GEN_ENUM_BINDINGS_TD_FILE` for handling corner cases. 2. EnumPythonBindingGen.cpp: there are two weedy aspects here that took investigation: 1. If an enum attribute is not a `Dialect/EnumAttr` then the `EnumAttrInfo` record is canonical, as far as both the cases of the enum **and the `AttrDefName`**. On the otherhand, if an enum is a `Dialect/EnumAttr` then the `EnumAttr` record has the correct `AttrDefName` ("load bearing", i.e., populates `ods.ir.AttributeBuilder('<NAME>')`) but its `enum` field contains the cases, which is an instance of `EnumAttrInfo`. The solution is to generate an one enum class for both `Dialect/EnumAttr` and "independent" `EnumAttrInfo` but to make that class interopable with two builder registrations that both do the right thing (see next sub-bullet). 2. Because we don't have a good connection to cpp `EnumAttr`, i.e., only the `enum class` getters are exposed (like `DimensionAttr::get(Dimension value)`), we have to resort to parsing e.g., `Attribute.parse(f'#gpu<dim {x}>')`. This means that the set of supported `assemblyFormat`s (for the enum) is fixed at compile of MLIR (currently 2, the only 2 I saw). There might be some things that could be done here but they would require quite a bit more C API work to support generically (e.g., casting ints to enum cases and binding all the getters or going generically through the `symbolize*` methods, like `symbolizeDimension(uint32_t)` or `symbolizeDimension(StringRef)`). A few small changes: 1. In addition, since this patch registers default builders for attributes where people might've had their own builders already written, I added a `replace` param to `AttributeBuilder.insert` (`False` by default). 2. `makePythonEnumCaseName` can't handle all the different ways in which people write their enum cases, e.g., `llvm.CConv.Intel_OCL_BI`, which gets turned into `INTEL_O_C_L_B_I` (because `llvm::convertToSnakeFromCamelCase` doesn't look for runs of caps). So I dropped it. On the otherhand regularization does need to done because some enums have `None` as a case (and others might have other python keywords). 3. I turned on `llvm` dialect generation here in order to test `nvvm.WGMMAScaleIn`, which is an enum with [[ https://github.com/llvm/llvm-project/blob/d7e26b56207cbd8995296c5bb7c11ce676b649da/mlir/include/mlir/IR/EnumAttr.td#L22-L25 | no explicit discriminator ]] for the `neg` case. Note, dialects that didn't get a `GEN_ENUM_BINDINGS` don't have any enums to generate. Let me know if I should add more tests (the three trivial ones I added exercise both the supported `assemblyFormat`s and `replace=True`). Reviewed By: stellaraccident Differential Revision: https://reviews.llvm.org/D157934
2023-08-16[mlir][transform][python] Add test for AnyValueType binding.Ingo Müller
I had forgotten to commit that test as part of https://reviews.llvm.org/D157638. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D158074
2023-07-20[mlir][transform][python] Add extended ApplyPatternsOp.Ingo Müller
This patch adds a mixin for ApplyPatternsOp to _transform_ops_ext.py with syntactic sugar for construction such ops. Curiously, the op did not have any constructors yet, probably because its tablegen definition said to skip the default builders. The new constructor is thus quite straightforward. The commit also adds a refined `region` property which returns the first block of the single region. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D155435
2023-07-04[mlir][transform] Improve transform.get_closest_isolated_parentMatthias Springer
* Rename op to `transform.get_parent_op` * Match parents by "is isolated from above" and/or op name, or just the direct parent. * Deduplication of result payload ops is optional. Differential Revision: https://reviews.llvm.org/D154071
2023-05-26[NFC][Py Reformat] Reformat python files in mlir subdirTobias Hieta
This is an ongoing series of commits that are reformatting our Python code. Reformatting is done with `black`. If you end up having problems merging this commit because you have made changes to a python file, the best way to handle that is to run git checkout --ours <yourfile> and then reformat it with black. If you run into any problems, post to discourse about it and we will try to help. RFC Thread below: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style Differential Revision: https://reviews.llvm.org/D150782
2023-05-24[mlir] move PDL-related transform ops into an extensionAlex Zinenko
The initial bring-up of the Transform dialect relied on PDL to provide the default handle type (`!pdl.operation`) and the matching capability. Both are now provided natively by the Transform dialect removing the reason to have a hard dependency on the PDL dialect and its interpreter. Move PDL-related transform operations into a separate extension. This requires us to introduce a dialect state extension mechanism into the Transform dialect so it no longer needs to know about PDL constraint functions that may be injected by extensions similarly to operations and types. This mechanism will be reused to connect pattern application drivers and the Transform dialect. This completes the restructuring of the Transform dialect to remove overrilance on PDL. Note to downstreams: flow that are using `!pdl.operation` with Transform dialect operations will now require `transform::PDLExtension` to be applied to the transform dialect in order to provide the transform handle type interface for `!pdl.operation`. Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D151104
2023-05-22[mlir] NFC: use !transform.any_op in relevant testsAlex Zinenko
Update various tests using Transform dialect extensions to pervasively use `!transform.any_op` instead of `!pdl.operation`. Tests are sometimes used as source of knowledge for best practices and these were doing the opposite of what is considered best practices per https://discourse.llvm.org/t/rfc-type-system-for-the-transform-dialect/65702. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D150785
2023-01-31[mlir] multi-argument binding for top-level transform opsAlex Zinenko
`applyTransforms` now takes an optional mapping to be associated with trailing block arguments of the top-level transform op, in addition to the payload root. This allows for more advanced forms of communication between C++ code and the transform dialect interpreter, in particular supplying operations without having to re-match them during interpretation. Reviewed By: shabalin Differential Revision: https://reviews.llvm.org/D142559
2022-10-11[mlir] add OperationType to the Transform dialectAlex Zinenko
Add a new OperationType handle type to the Transform dialect. This transform type is parameterized by the name of the payload operation it can point to. It is intended as a constraint on transformations that are only applicable to a specific kind of payload operations. If a transformation is applicable to a small set of operation classes, it can be wrapped into a transform op by using a disjunctive constraint, such as `Type<Or<[Transform_ConcreteOperation<"foo">.predicate, Transform_ConcreteOperation<"bar">.predicate]>>` for its operand without modifying this type. Broader sets of accepted operations should be modeled as specific types. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D135586
2022-10-11[mlir] switch transform dialect ops to use TransformTypeInterfaceAlex Zinenko
Use the recently introduced TransformTypeInterface instead of hardcoding the PDLOperationType. This will allow the operations to use more specific transform types to express pre/post-conditions in the future. It requires the syntax and Python op construction API to be updated. Dialect extensions will be switched separately. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D135584
2022-08-12[mlir][transform] failure propagation mode in sequenceAlex Zinenko
Introduce two different failure propagation mode in the Transform dialect's Sequence operation. These modes specify whether silenceable errors produced by nested ops are immediately propagated, thus stopping the sequence, or suppressed. The latter is useful in end-to-end transform application scenarios where the user cannot correct the transformation, but it is robust enough to silenceable failures. It can be combined with the "alternatives" operation. There is intentionally no default value to avoid favoring one mode over the other. Downstreams can update their tests using: S='s/sequence \(%.*\) {/sequence \1 failures(propagate) {/' T='s/sequence {/sequence failures(propagate) {/' git grep -l transform.sequence | xargs sed -i -e "$S" git grep -l transform.sequence | xargs sed -i -e "$T" Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D131774
2022-07-12[mlir] Add ReplicateOp to the Transform dialectAlex Zinenko
This handle manipulation operation allows one to define a new handle that is associated with a the same payload IR operations N times, where N can be driven by the size of payload IR operation list associated with another handle. This can be seen as a sort of broadcast that can be used to ensure the lists associated with two handles have equal numbers of payload IR ops as expected by many pairwise transform operations. Introduce an additional "expensive" check that guards against consuming a handle that is assocaited with the same payload IR operation more than once as this is likely to lead to double-free or other undesired effects. Depends On D129110 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D129216
2022-07-07[mlir] Transform dialect: introduce merge_handles opAlex Zinenko
This Transform dialect op allows one to merge the lists of Payload IR operations pointed to by several handles into a single list associated with one handle. This is an important Transform dialect usability improvement for cases where transformations may temporarily diverge for different groups of Payload IR ops before converging back to the same script. Without this op, several copies of the trailing transformations would have to be present in the transformation script. Depends On D129090 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D129110
2022-05-30[mlir] provide Python bindings for the Transform dialectAlex Zinenko
Python bindings for extensions of the Transform dialect are defined in separate Python source files that can be imported on-demand, i.e., that are not imported with the "main" transform dialect. This requires a minor addition to the ODS-based bindings generator. This approach is consistent with the current model for downstream projects that are expected to bundle MLIR Python bindings: such projects can include their custom extensions into the bundle similarly to how they include their dialects. Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D126208