-
Notifications
You must be signed in to change notification settings - Fork 737
Redefine ApplyRegisteredPass in the Transform dialect #7956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
c602a54
eb94a67
ebade75
966a678
c3905c6
2e21cb8
0d1f4fa
9ecadb7
8c62649
6b83c17
25dd616
3397df1
701f80b
c0fda72
6f3e1ad
0b7b631
58a4a0f
9f51c7b
b0a3120
262b32b
28c98e8
8558383
6e94592
d3b9139
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| # Copyright 2025 Xanadu Quantum Technologies Inc. | ||
|
|
||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
|
|
||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
| This file contains an updated version of the transform dialect. | ||
| As of the time of writing, xDSL uses the MLIR released with LLVM's | ||
| version 20.1.7. However, https://github.com/PennyLaneAI/catalyst/pull/1916 | ||
| will be updating MLIR where the transform dialect has the | ||
| `apply_registered_pass` operation re-defined. | ||
|
|
||
| See the following changelog on the above PR | ||
|
|
||
| Things related to transform.apply_registered_pass op: | ||
|
|
||
| It now takes in a dynamic_options | ||
|
|
||
| [MLIR][Transform] Allow ApplyRegisteredPassOp to take options as | ||
| a param llvm/llvm-project#142683. We don't need to use this as all our pass options are static. | ||
| https://github.com/llvm/llvm-project/pull/142683 | ||
|
|
||
| The options it takes in are now dictionaries instead of strings | ||
| [MLIR][Transform] apply_registered_pass op's options as a dict llvm/llvm-project#143159 | ||
| https://github.com/llvm/llvm-project/pull/143159 | ||
|
|
||
| This file will re-define the apply_registered_pass operation in xDSL | ||
| and the transform dialect. | ||
|
|
||
| Once xDSL moves to a newer version of MLIR, these changes should | ||
| be contributed upstream. | ||
| """ | ||
|
|
||
| from xdsl.dialects.builtin import DictionaryAttr | ||
|
|
||
| # pylint: disable=unused-wildcard-import,wildcard-import | ||
| from xdsl.dialects.transform import * | ||
mehrdad2m marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @irdl_op_definition | ||
| # pylint: disable=function-redefined | ||
| class ApplyRegisteredPassOp(IRDLOperation): | ||
|
Check notice on line 50 in pennylane/compiler/python_compiler/dialects/transform.py
|
||
| """ | ||
| See external [documentation](https://mlir.llvm.org/docs/Dialects/Transform/#transformapply_registered_pass-transformapplyregisteredpassop). | ||
| """ | ||
|
|
||
| name = "transform.apply_registered_pass" | ||
|
|
||
| options = prop_def(DictionaryAttr, default_value=DictionaryAttr({})) | ||
| pass_name = prop_def(StringAttr) | ||
|
Check notice on line 58 in pennylane/compiler/python_compiler/dialects/transform.py
|
||
| target = operand_def(TransformHandleType) | ||
|
Check notice on line 59 in pennylane/compiler/python_compiler/dialects/transform.py
|
||
| result = result_def(TransformHandleType) | ||
|
Check notice on line 60 in pennylane/compiler/python_compiler/dialects/transform.py
|
||
| # While this assembly format doesn't match | ||
| # the one in upstream MLIR, | ||
| # this is because xDSL currently lacks CustomDirectives | ||
| # https://mlir.llvm.org/docs/DefiningDialects/Operations/#custom-directives | ||
| # https://github.com/xdslproject/xdsl/pull/4829 | ||
| # However, storing the property in the attribute should still work | ||
| # specially when parsing and printing in generic format. | ||
| # Which is how Catalyst and XDSL currently communicate at the moment. | ||
| # TODO: Add test. | ||
| assembly_format = "$pass_name `to` $target attr-dict `:` functional-type(operands, results)" | ||
| irdl_options = [ParsePropInAttrDict()] | ||
|
|
||
| def __init__( | ||
| self, | ||
| pass_name: str | StringAttr, | ||
| target: SSAValue, | ||
| options: dict | DictionaryAttr | None = None, | ||
paul0403 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ): | ||
| if isinstance(pass_name, str): | ||
mehrdad2m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pass_name = StringAttr(pass_name) | ||
|
|
||
| if isinstance(options, dict): | ||
mehrdad2m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| options = DictionaryAttr(options) | ||
|
|
||
| super().__init__( | ||
| properties={ | ||
| "pass_name": pass_name, | ||
| "options": options, | ||
| }, | ||
| operands=[target], | ||
| result_types=[target.type], | ||
| ) | ||
|
|
||
|
|
||
| # Copied over from xDSL's sources | ||
| # the main difference will be the use | ||
| # of a different ApplyRegisteredPassOp | ||
| Transform = Dialect( | ||
| "transform", | ||
| [ | ||
| ApplyRegisteredPassOp, | ||
| GetConsumersOfResultOp, | ||
| GetDefiningOp, | ||
| GetParentOp, | ||
| GetProducerOfOperandOp, | ||
| GetResultOp, | ||
| GetTypeOp, | ||
| IncludeOp, | ||
| MatchOperationEmptyOp, | ||
| MatchOperationNameOp, | ||
| MatchParamCmpIOp, | ||
| MergeHandlesOp, | ||
| ParamConstantOp, | ||
| SplitHandleOp, | ||
| SequenceOp, | ||
| YieldOp, | ||
| TileOp, | ||
| TileToForallOp, | ||
| SelectOp, | ||
| NamedSequenceOp, | ||
| CastOp, | ||
| MatchOp, | ||
| ], | ||
| [ | ||
| # Types | ||
| AffineMapType, | ||
| AnyOpType, | ||
| AnyValueType, | ||
| AnyParamType, | ||
| OperationType, | ||
| ParamType, | ||
| TypeParamType, | ||
| # Attributes | ||
| FailurePropagationModeAttr, | ||
| ], | ||
| ) | ||
erick-xanadu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.