Skip to content

[MLIR][Transform] apply_registered_pass op's options as a dict #143159

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

Merged
merged 8 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mlir/include/mlir/Dialect/Transform/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ mlir_tablegen(TransformDialectEnums.h.inc -gen-enum-decls)
mlir_tablegen(TransformDialectEnums.cpp.inc -gen-enum-defs)
add_public_tablegen_target(MLIRTransformDialectEnumIncGen)
add_dependencies(mlir-headers MLIRTransformDialectEnumIncGen)
mlir_tablegen(TransformAttrs.h.inc -gen-attrdef-decls)
mlir_tablegen(TransformAttrs.cpp.inc -gen-attrdef-defs)
add_public_tablegen_target(MLIRTransformDialectAttributesIncGen)
add_dependencies(mlir-headers MLIRTransformDialectAttributesIncGen)

add_mlir_dialect(TransformOps transform)
add_mlir_doc(TransformOps TransformOps Dialects/ -gen-op-doc -dialect=transform)
Expand Down
3 changes: 3 additions & 0 deletions mlir/include/mlir/Dialect/Transform/IR/TransformAttrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@

#include "mlir/Dialect/Transform/IR/TransformDialectEnums.h.inc"

#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/Transform/IR/TransformAttrs.h.inc"

#endif // MLIR_DIALECT_TRANSFORM_IR_TRANSFORMATTRS_H
19 changes: 19 additions & 0 deletions mlir/include/mlir/Dialect/Transform/IR/TransformAttrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
#define MLIR_DIALECT_TRANSFORM_IR_TRANSFORMATTRS

include "mlir/IR/EnumAttr.td"
include "mlir/Dialect/Transform/IR/TransformDialect.td"

class Transform_Attr<string name, string attrMnemonic,
list<Trait> traits = [],
string baseCppClass = "::mlir::Attribute">
: AttrDef<Transform_Dialect, name, traits, baseCppClass> {
let mnemonic = attrMnemonic;
}

def PropagateFailuresCase : I32EnumAttrCase<"Propagate", 1, "propagate">;
def SuppressFailuresCase : I32EnumAttrCase<"Suppress", 2, "suppress">;
Expand All @@ -33,4 +41,15 @@ def MatchCmpIPredicateAttr : I32EnumAttr<
let cppNamespace = "::mlir::transform";
}

def ParamOperandAttr : Transform_Attr<"ParamOperand", "param_operand"> {
let description = [{
Used to refer to a specific param-operand (via its index) from within an
attribute on a transform operation.
}];
let parameters = (ins
"IntegerAttr":$index
);
let assemblyFormat = "`<` `index` `=` $index `>`";
}

#endif // MLIR_DIALECT_TRANSFORM_IR_TRANSFORMATTRS
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/Transform/IR/TransformDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def Transform_Dialect : Dialect {
let cppNamespace = "::mlir::transform";

let hasOperationAttrVerify = 1;
let useDefaultAttributePrinterParser = 1;
let extraClassDeclaration = [{
/// Symbol name for the default entry point "named sequence".
constexpr const static ::llvm::StringLiteral
Expand Down
23 changes: 18 additions & 5 deletions mlir/include/mlir/Dialect/Transform/IR/TransformOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,23 @@ def ApplyRegisteredPassOp : TransformDialectOp<"apply_registered_pass",
let description = [{
This transform applies the specified pass or pass pipeline to the targeted
ops. The name of the pass/pipeline is specified as a string attribute, as
set during pass/pipeline registration. Optionally, pass options may be
specified as (space-separated) string attributes with the option to pass
these attributes via params. The pass options syntax is identical to the one
used with "mlir-opt".
set during pass/pipeline registration.

Optionally, pass options may be specified via a DictionaryAttr. This
dictionary is converted to a string -- formatted `key=value ...` -- which
is expected to be in the exact format used by the pass on the commandline.
Values are either attributes or (SSA-values of) Transform Dialect params.
For example:

```mlir
transform.apply_registered_pass "canonicalize"
with options = { "top-down" = false,
"max-iterations" = %max_iter,
"test-convergence" = true,
"max-num-rewrites" = %max_rewrites }
to %module
: (!transform.any_param, !transform.any_param, !transform.any_op) -> !transform.any_op
```

This op first looks for a pass pipeline with the specified name. If no such
pipeline exists, it looks for a pass with the specified name. If no such
Expand All @@ -422,7 +435,7 @@ def ApplyRegisteredPassOp : TransformDialectOp<"apply_registered_pass",
}];

let arguments = (ins StrAttr:$pass_name,
DefaultValuedAttr<ArrayAttr, "{}">:$options,
DefaultValuedAttr<DictionaryAttr, "{}">:$options,
Variadic<TransformParamTypeInterface>:$dynamic_options,
TransformHandleTypeInterface:$target);
let results = (outs TransformHandleTypeInterface:$result);
Expand Down
9 changes: 9 additions & 0 deletions mlir/lib/Dialect/Transform/IR/TransformDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@

#include "mlir/Dialect/Transform/IR/TransformDialect.h"
#include "mlir/Analysis/CallGraph.h"
#include "mlir/Dialect/Transform/IR/TransformAttrs.h"
#include "mlir/Dialect/Transform/IR/TransformOps.h"
#include "mlir/Dialect/Transform/IR/TransformTypes.h"
#include "mlir/Dialect/Transform/IR/Utils.h"
#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
#include "mlir/IR/DialectImplementation.h"
#include "llvm/ADT/SCCIterator.h"
#include "llvm/ADT/TypeSwitch.h"

using namespace mlir;

#include "mlir/Dialect/Transform/IR/TransformDialect.cpp.inc"

#define GET_ATTRDEF_CLASSES
#include "mlir/Dialect/Transform/IR/TransformAttrs.cpp.inc"

#ifndef NDEBUG
void transform::detail::checkImplementsTransformOpInterface(
StringRef name, MLIRContext *context) {
Expand Down Expand Up @@ -66,6 +71,10 @@ void transform::TransformDialect::initialize() {
#include "mlir/Dialect/Transform/IR/TransformOps.cpp.inc"
>();
initializeTypes();
addAttributes<
#define GET_ATTRDEF_LIST
#include "mlir/Dialect/Transform/IR/TransformAttrs.cpp.inc"
>();
initializeLibraryModule();
}

Expand Down
Loading
Loading