From 97c05062afdc6be334137c5450b9492af75d2610 Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Mon, 2 Jan 2023 13:58:53 +0000 Subject: [PATCH] [mlir] NFC: rename TransformTypeInterface to TransformHandleTypeInterface This makes it more consistent with the recently added TransformParamTypeInterface. Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D140977 --- mlir/docs/Dialects/Transform.md | 4 +- .../Dialect/SCF/TransformOps/SCFTransformOps.td | 14 +++---- .../mlir/Dialect/Transform/IR/TransformDialect.h | 13 +++--- .../Dialect/Transform/IR/TransformInterfaces.h | 4 +- .../Dialect/Transform/IR/TransformInterfaces.td | 4 +- .../mlir/Dialect/Transform/IR/TransformOps.td | 48 +++++++++++----------- .../mlir/Dialect/Transform/IR/TransformTypes.td | 4 +- mlir/lib/Dialect/Transform/IR/TransformDialect.cpp | 14 ++++--- .../Dialect/Transform/IR/TransformInterfaces.cpp | 13 +++--- mlir/lib/Dialect/Transform/IR/TransformOps.cpp | 9 ++-- mlir/test/Dialect/Transform/ops-invalid.mlir | 4 +- .../Transform/TestTransformDialectExtension.td | 6 +-- 12 files changed, 71 insertions(+), 66 deletions(-) diff --git a/mlir/docs/Dialects/Transform.md b/mlir/docs/Dialects/Transform.md index a74ae5d..eb86bdc 100644 --- a/mlir/docs/Dialects/Transform.md +++ b/mlir/docs/Dialects/Transform.md @@ -73,7 +73,7 @@ transformation for every mapped op ("batched execution"). Deviations from this convention are described in the documentation of Transform IR ops. The transform IR values have transform IR types, which implement either -[TransformTypeInterface](Transform.md#transformtypeinterface-transformtypeinterface) +[TransformHandleTypeInterface](Transform.md#transformhandletypeinterface-transformhandletypeinterface) or [TransformParamTypeInterface](Transform.md##transformparamtypeinterface-transformparamtypeinterface). The former interface verifiers properties of payload IR operations associated @@ -156,7 +156,7 @@ separate dialect extensions if desired. Similarly to operations, additional types can be injected into the dialect using the same extension mechanism. The types must: - * Implement exactly one of `TransformTypeInterface`, + * Implement exactly one of `TransformHandleTypeInterface`, `TransformParamTypeInterface`. ## Side Effects diff --git a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td index 59d25da..0bdd581 100644 --- a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td +++ b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td @@ -32,11 +32,11 @@ def GetParentForOp : Op, "1">:$num_loops, DefaultValuedAttr:$affine); - let results = (outs TransformTypeInterface : $parent); + let results = (outs TransformHandleTypeInterface : $parent); let assemblyFormat = "$target attr-dict `:` functional-type(operands, results)"; @@ -62,9 +62,9 @@ def LoopOutlineOp : Op:$fail_if_already_divisible); // TODO: Return both the peeled loop and the remainder loop. - let results = (outs TransformTypeInterface:$transformed); + let results = (outs TransformHandleTypeInterface:$transformed); let assemblyFormat = "$target attr-dict `:` functional-type(operands, results)"; @@ -143,7 +143,7 @@ def LoopPipelineOp : Op:$iteration_interval, DefaultValuedAttr:$read_latency); - let results = (outs TransformTypeInterface:$transformed); + let results = (outs TransformHandleTypeInterface:$transformed); let assemblyFormat = "$target attr-dict `:` functional-type(operands, results)"; @@ -176,7 +176,7 @@ def LoopUnrollOp : Op:$factor); let assemblyFormat = "$target attr-dict `:` type($target)"; diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h b/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h index e386b35..05533b6 100644 --- a/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h +++ b/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h @@ -25,9 +25,10 @@ namespace detail { void checkImplementsTransformOpInterface(StringRef name, MLIRContext *context); /// Asserts that the type provided as template argument implements the -/// TransformTypeInterface. This must be a dynamic assertion since interface -/// implementations may be registered at runtime. -void checkImplementsTransformTypeInterface(TypeID typeID, MLIRContext *context); +/// TransformHandleTypeInterface. This must be a dynamic assertion since +/// interface implementations may be registered at runtime. +void checkImplementsTransformHandleTypeInterface(TypeID typeID, + MLIRContext *context); } // namespace detail #endif // NDEBUG } // namespace transform @@ -112,7 +113,7 @@ protected: } /// Injects the types into the Transform dialect. The types must implement - /// the TransformTypeInterface and the implementation must be already + /// the TransformHandleTypeInterface and the implementation must be already /// available when the type is injected. Furthermore, the types must provide /// a `getMnemonic` static method returning an object convertible to /// `StringRef` that is unique across all injected types. @@ -225,8 +226,8 @@ void TransformDialect::addTypeIfNotRegistered() { addTypes(); #ifndef NDEBUG - detail::checkImplementsTransformTypeInterface(TypeID::get(), - getContext()); + detail::checkImplementsTransformHandleTypeInterface(TypeID::get(), + getContext()); #endif // NDEBUG } diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.h b/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.h index bfb6879..4cfc2e4 100644 --- a/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.h +++ b/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.h @@ -608,7 +608,7 @@ private: /// /// Returns failure if the payload does not satisfy the conditions associated /// with the type of the handle value. The value is expected to have a type - /// implementing TransformTypeInterface. + /// implementing TransformHandleTypeInterface. LogicalResult setPayloadOps(Value value, ArrayRef targets); /// Sets the parameters associated with the given transform IR value. Returns @@ -686,7 +686,7 @@ public: /// Indicates that the result of the transform IR op at the given position /// corresponds to the given list of payload IR ops. Each result must be set /// by the transformation exactly once. The value must have a type - /// implementing TransformTypeInterface. + /// implementing TransformHandleTypeInterface. void set(OpResult value, ArrayRef ops); /// Indicates that the result of the transform IR op at the given position diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.td b/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.td index 319af25..b0b92da 100644 --- a/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.td +++ b/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.td @@ -129,8 +129,8 @@ class TransformTypeInterfaceBase }]; } -def TransformTypeInterface - : TransformTypeInterfaceBase<"TransformTypeInterface", +def TransformHandleTypeInterface + : TransformTypeInterfaceBase<"TransformHandleTypeInterface", "::mlir::Operation *"> { let description = [{ Types that can be used for the Transform dialect handle values. Such types diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformOps.td b/mlir/include/mlir/Dialect/Transform/IR/TransformOps.td index c813a64..b656bce 100644 --- a/mlir/include/mlir/Dialect/Transform/IR/TransformOps.td +++ b/mlir/include/mlir/Dialect/Transform/IR/TransformOps.td @@ -88,8 +88,8 @@ def AlternativesOp : TransformDialectOp<"alternatives", ``` }]; - let arguments = (ins Optional:$scope); - let results = (outs Variadic:$results); + let arguments = (ins Optional:$scope); + let results = (outs Variadic:$results); let regions = (region VariadicRegion>:$alternatives); let assemblyFormat = @@ -102,8 +102,8 @@ def CastOp : TransformDialectOp<"cast", [TransformOpInterface, TransformEachOpTrait, DeclareOpInterfaceMethods, DeclareOpInterfaceMethods]> { - let arguments = (ins TransformTypeInterface:$input); - let results = (outs TransformTypeInterface:$output); + let arguments = (ins TransformHandleTypeInterface:$input); + let results = (outs TransformHandleTypeInterface:$output); let assemblyFormat = "$input attr-dict `:` type($input) `to` type($output)"; let extraClassDeclaration = [{ @@ -143,8 +143,8 @@ def ForeachOp : TransformDialectOp<"foreach", merged and mapped to the same resulting handle. }]; - let arguments = (ins TransformTypeInterface:$target); - let results = (outs Variadic:$results); + let arguments = (ins TransformHandleTypeInterface:$target); + let results = (outs Variadic:$results); let regions = (region SizedRegion<1>:$body); let assemblyFormat = "$target `:` type($target) (`->` type($results)^)? $body attr-dict"; @@ -183,8 +183,8 @@ def GetClosestIsolatedParentOp : TransformDialectOp<"get_closest_isolated_parent on the further transformation applied to the handle produced here. }]; - let arguments = (ins TransformTypeInterface:$target); - let results = (outs TransformTypeInterface:$parent); + let arguments = (ins TransformHandleTypeInterface:$target); + let results = (outs TransformHandleTypeInterface:$parent); let assemblyFormat = "$target attr-dict `:` functional-type(operands, results)"; } @@ -202,9 +202,9 @@ def GetProducerOfOperand : TransformDialectOp<"get_producer_of_operand", computational operations, which can be empty. }]; - let arguments = (ins TransformTypeInterface:$target, + let arguments = (ins TransformHandleTypeInterface:$target, I64Attr:$operand_number); - let results = (outs TransformTypeInterface:$parent); + let results = (outs TransformHandleTypeInterface:$parent); let assemblyFormat = "$target `[` $operand_number `]` attr-dict `:` " "functional-type(operands, results)"; } @@ -225,9 +225,9 @@ def MergeHandlesOp : TransformDialectOp<"merge_handles", same or different handles. Consumes the operands and produces a new handle. }]; - let arguments = (ins Variadic:$handles, + let arguments = (ins Variadic:$handles, UnitAttr:$deduplicate); - let results = (outs TransformTypeInterface:$result); + let results = (outs TransformHandleTypeInterface:$result); let assemblyFormat = "($deduplicate^)? $handles attr-dict `:` type($result)"; let hasFolder = 1; } @@ -250,9 +250,9 @@ def SplitHandlesOp : TransformDialectOp<"split_handles", operations contained in the source `handle`. Otherwise it silently fails. }]; - let arguments = (ins TransformTypeInterface:$handle, + let arguments = (ins TransformHandleTypeInterface:$handle, I64Attr:$num_result_handles); - let results = (outs Variadic:$results); + let results = (outs Variadic:$results); let builders = [ OpBuilder<(ins "Value":$handle, "int64_t":$numResultHandles)> @@ -286,10 +286,10 @@ def PDLMatchOp : TransformDialectOp<"pdl_match", }]; let arguments = (ins - Arg:$root, + Arg:$root, SymbolRefAttr:$pattern_name); let results = (outs - Res:$matched); + Res:$matched); let assemblyFormat = "$pattern_name `in` $root attr-dict `:` " "functional-type(operands, results)"; @@ -307,7 +307,7 @@ def PrintOp : TransformDialectOp<"print", This op is useful for printf-style debugging. }]; - let arguments = (ins Optional:$target, + let arguments = (ins Optional:$target, OptionalAttr:$name); let results = (outs); @@ -349,9 +349,9 @@ def ReplicateOp : TransformDialectOp<"replicate", MergeHandlesOp can be used to construct arbitrary lists with repetitions. }]; - let arguments = (ins TransformTypeInterface:$pattern, - Variadic:$handles); - let results = (outs Variadic:$replicated); + let arguments = (ins TransformHandleTypeInterface:$pattern, + Variadic:$handles); + let results = (outs Variadic:$replicated); let assemblyFormat = "`num` `(` $pattern `)` $handles attr-dict `:` " "type($pattern) `,` type($handles)"; } @@ -396,8 +396,8 @@ def SequenceOp : TransformDialectOp<"sequence", }]; let arguments = (ins FailurePropagationMode:$failure_propagation_mode, - Optional:$root); - let results = (outs Variadic:$results); + Optional:$root); + let results = (outs Variadic:$results); let regions = (region SizedRegion<1>:$body); let assemblyFormat = @@ -467,7 +467,7 @@ def WithPDLPatternsOp : TransformDialectOp<"with_pdl_patterns", }]; let arguments = (ins - Arg, "Root operation of the Payload IR", + Arg, "Root operation of the Payload IR", [TransformMappingRead]>:$root); let regions = (region SizedRegion<1>:$body); let assemblyFormat = "($root^ `:` type($root))? attr-dict-with-keyword regions"; @@ -489,7 +489,7 @@ def YieldOp : TransformDialectOp<"yield", [Terminator]> { }]; let arguments = (ins - Arg, "Operation handles yielded back to the parent", + Arg, "Operation handles yielded back to the parent", [TransformMappingRead]>:$operands); let assemblyFormat = "operands attr-dict (`:` type($operands)^)?"; diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td b/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td index b7f39fa..ebaf576 100644 --- a/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td +++ b/mlir/include/mlir/Dialect/Transform/IR/TransformTypes.td @@ -14,7 +14,7 @@ include "mlir/Dialect/Transform/IR/TransformInterfaces.td" include "mlir/Dialect/Transform/IR/TransformDialect.td" def Transform_AnyOpType : TypeDef]> { + [DeclareTypeInterfaceMethods]> { let description = [{ Transform IR handle that can be associated with a list of arbitrary Payload IR operations. @@ -24,7 +24,7 @@ def Transform_AnyOpType : TypeDef]> { + [DeclareTypeInterfaceMethods]> { let description = [{ Transform IR handle that can be associated with a list of Payload IR operations with the specified operation name. diff --git a/mlir/lib/Dialect/Transform/IR/TransformDialect.cpp b/mlir/lib/Dialect/Transform/IR/TransformDialect.cpp index e7a0899..fdf3c74 100644 --- a/mlir/lib/Dialect/Transform/IR/TransformDialect.cpp +++ b/mlir/lib/Dialect/Transform/IR/TransformDialect.cpp @@ -35,11 +35,12 @@ void transform::detail::checkImplementsTransformOpInterface( "MemoryEffectsOpInterface"); } -void transform::detail::checkImplementsTransformTypeInterface( +void transform::detail::checkImplementsTransformHandleTypeInterface( TypeID typeID, MLIRContext *context) { const auto &abstractType = AbstractType::lookup(typeID, context); assert( - (abstractType.hasInterface(TransformTypeInterface::getInterfaceID()) || + (abstractType.hasInterface( + TransformHandleTypeInterface::getInterfaceID()) || abstractType.hasInterface( TransformParamTypeInterface::getInterfaceID())) && "expected Transform dialect type to implement one of the two interfaces"); @@ -47,9 +48,10 @@ void transform::detail::checkImplementsTransformTypeInterface( #endif // NDEBUG namespace { -struct PDLOperationTypeTransformTypeInterfaceImpl - : public transform::TransformTypeInterface::ExternalModel< - PDLOperationTypeTransformTypeInterfaceImpl, pdl::OperationType> { +struct PDLOperationTypeTransformHandleTypeInterfaceImpl + : public transform::TransformHandleTypeInterface::ExternalModel< + PDLOperationTypeTransformHandleTypeInterfaceImpl, + pdl::OperationType> { DiagnosedSilenceableFailure checkPayload(Type type, Location loc, ArrayRef payload) const { return DiagnosedSilenceableFailure::success(); @@ -67,7 +69,7 @@ void transform::TransformDialect::initialize() { initializeTypes(); pdl::OperationType::attachInterface< - PDLOperationTypeTransformTypeInterfaceImpl>(*getContext()); + PDLOperationTypeTransformHandleTypeInterfaceImpl>(*getContext()); } void transform::TransformDialect::mergeInPDLMatchHooks( diff --git a/mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp b/mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp index 5a178f3..46dc2ae 100644 --- a/mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp +++ b/mlir/lib/Dialect/Transform/IR/TransformInterfaces.cpp @@ -79,7 +79,7 @@ transform::TransformState::setPayloadOps(Value value, assert(!value.getType().isa() && "cannot associate payload ops with a value of parameter type"); - auto iface = value.getType().cast(); + auto iface = value.getType().cast(); DiagnosedSilenceableFailure result = iface.checkPayload(value.getLoc(), targets); if (failed(result.checkAndReport())) @@ -155,7 +155,7 @@ LogicalResult transform::TransformState::updatePayloadOps( } } - auto iface = value.getType().cast(); + auto iface = value.getType().cast(); DiagnosedSilenceableFailure result = iface.checkPayload(value.getLoc(), updated); if (failed(result.checkAndReport())) @@ -439,9 +439,10 @@ transform::detail::verifyPossibleTopLevelTransformOpTrait(Operation *op) { Block *body = &bodyRegion->front(); if (body->getNumArguments() != 1 || - !body->getArgumentTypes()[0].isa()) { - return op->emitOpError() << "expects the entry block to have one argument " - "of type implementing TransformTypeInterface"; + !body->getArgumentTypes()[0].isa()) { + return op->emitOpError() + << "expects the entry block to have one argument " + "of type implementing TransformHandleTypeInterface"; } if (auto *parent = @@ -469,7 +470,7 @@ void transform::detail::getParamProducerTransformOpTraitEffects( bool hasPayloadOperands = false; for (Value operand : op->getOperands()) { onlyReadsHandle(operand, effects); - if (operand.getType().isa()) + if (operand.getType().isa()) hasPayloadOperands = true; } if (hasPayloadOperands) diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp index 629b1f6..f7522fa 100644 --- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp +++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp @@ -281,7 +281,8 @@ bool transform::CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) { return llvm::all_of( std::initializer_list{inputs.front(), outputs.front()}, [](Type ty) { - return ty.isa(); + return ty + .isa(); }); } @@ -370,9 +371,9 @@ LogicalResult transform::ForeachOp::verify() { return emitOpError() << "expects the same number of results as the " "terminator has operands"; for (Value v : yieldOp.getOperands()) - if (!v.getType().isa()) - return yieldOp->emitOpError( - "expects operands to have types implementing TransformTypeInterface"); + if (!v.getType().isa()) + return yieldOp->emitOpError("expects operands to have types implementing " + "TransformHandleTypeInterface"); return success(); } diff --git a/mlir/test/Dialect/Transform/ops-invalid.mlir b/mlir/test/Dialect/Transform/ops-invalid.mlir index 369be21..ec3f553 100644 --- a/mlir/test/Dialect/Transform/ops-invalid.mlir +++ b/mlir/test/Dialect/Transform/ops-invalid.mlir @@ -1,6 +1,6 @@ // RUN: mlir-opt %s -split-input-file -verify-diagnostics -// expected-error @below {{expects the entry block to have one argument of type implementing TransformTypeInterface}} +// expected-error @below {{expects the entry block to have one argument of type implementing TransformHandleTypeInterface}} transform.sequence failures(propagate) { } @@ -190,7 +190,7 @@ transform.sequence failures(propagate) { // ----- -// expected-error @below {{expects the entry block to have one argument of type implementing TransformTypeInterface}} +// expected-error @below {{expects the entry block to have one argument of type implementing TransformHandleTypeInterface}} transform.alternatives { ^bb0: transform.yield diff --git a/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td b/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td index 59ad044..c9740d1 100644 --- a/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td +++ b/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td @@ -23,7 +23,7 @@ include "mlir/Dialect/PDL/IR/PDLTypes.td" def TestTransformTestDialectHandleType : TypeDef]> { + [DeclareTypeInterfaceMethods]> { let description = [{Handle pointing to an op from the Test dialect.}]; let mnemonic = "test_dialect_op"; let assemblyFormat = ""; @@ -79,7 +79,7 @@ def TestPrintRemarkAtOperandOp : Op]> { let arguments = (ins - Arg:$operand, StrAttr:$message); let assemblyFormat = @@ -296,7 +296,7 @@ def TestProduceParamWithNumberOfTestOps : Op]> { - let arguments = (ins TransformTypeInterface:$handle); + let arguments = (ins TransformHandleTypeInterface:$handle); let results = (outs TestTransformTestDialectParamType:$result); let assemblyFormat = "$handle attr-dict `:` type($handle)"; let cppNamespace = "::mlir::test"; -- 2.7.4