From: Nicolas Vasilache Date: Fri, 8 Jul 2022 06:40:17 +0000 (-0700) Subject: [mlir][Transform] Fix isDefiniteFailure helper X-Git-Tag: upstream/15.0.7~2319 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69c8319e76307423ce960570ab6e0dd3768d2a45;p=platform%2Fupstream%2Fllvm.git [mlir][Transform] Fix isDefiniteFailure helper This newly added helper was returning definiteFailure even in the case of silenceableFailure. Differential Revision: https://reviews.llvm.org/D129347 --- diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.h b/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.h index 89be5ba..5589d93 100644 --- a/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.h +++ b/mlir/include/mlir/Dialect/Transform/IR/TransformInterfaces.h @@ -82,17 +82,19 @@ public: return result; } - /// Returns `true` if this is a silenceable failure. - bool isDefiniteFailure() const { return result.failed(); } - - /// Returns `true` if this is a silenceable failure. - bool isSilenceableFailure() const { return !diagnostics.empty(); } - /// Returns `true` if this is a success. bool succeeded() const { - return diagnostics.empty() && ::mlir::succeeded(result); + return ::mlir::succeeded(result) && diagnostics.empty(); } + /// Returns `true` if this is a definite failure. + bool isDefiniteFailure() const { + return ::mlir::failed(result) && diagnostics.empty(); + } + + /// Returns `true` if this is a silenceable failure. + bool isSilenceableFailure() const { return !diagnostics.empty(); } + /// Returns the diagnostic message without emitting it. Expects this object /// to be a silenceable failure. std::string getMessage() const { diff --git a/mlir/test/Dialect/Linalg/transform-op-pad.mlir b/mlir/test/Dialect/Linalg/transform-op-pad.mlir index 153a9f4..68664de 100644 --- a/mlir/test/Dialect/Linalg/transform-op-pad.mlir +++ b/mlir/test/Dialect/Linalg/transform-op-pad.mlir @@ -109,7 +109,8 @@ transform.with_pdl_patterns { func.func @pad(%arg0: tensor<24x12xf32>, %arg1: tensor<12x25xf32>, %arg2: tensor<24x25xf32>) -> tensor<24x25xf32> { - // expected-note @below {{when applied to this op}} + // This is attached to an error that is silenceable and is not reported by this transform + // {{when applied to this op}} %0 = linalg.matmul ins(%arg0, %arg1 : tensor<24x12xf32>, tensor<12x25xf32>) outs(%arg2 : tensor<24x25xf32>) -> tensor<24x25xf32> func.return %0 : tensor<24x25xf32> } @@ -127,7 +128,8 @@ transform.with_pdl_patterns { transform.sequence %arg0 { ^bb1(%arg1: !pdl.operation): %0 = pdl_match @pdl_target in %arg1 - // expected-error @below {{transform.structured.pad failed to apply}} + // This error is silenceable and is not reported by this transform + // {{transform.structured.pad failed to apply}} %1 = transform.structured.pad %0 {padding_values=[0.0 : f32, 0.0 : f32, 0.0 : f32], padding_dimensions=[0, 1, 2], pack_paddings=[1, 1, 0]} } } diff --git a/mlir/test/Dialect/Transform/test-interpreter.mlir b/mlir/test/Dialect/Transform/test-interpreter.mlir index 9d48ced..a470213 100644 --- a/mlir/test/Dialect/Transform/test-interpreter.mlir +++ b/mlir/test/Dialect/Transform/test-interpreter.mlir @@ -545,3 +545,27 @@ transform.with_pdl_patterns { test_print_remark_at_operand %2, "matched" } } + +// ----- + +func.func @foo() { + "op" () { target_me } : () -> () + "op" () : () -> () + return +} + +transform.with_pdl_patterns { +^bb0(%arg0: !pdl.operation): + pdl.pattern @some : benefit(1) { + %0 = pdl.operands + %1 = pdl.types + %2 = pdl.operation "op"(%0 : !pdl.range) -> (%1 : !pdl.range) + pdl.rewrite %2 with "transform.dialect" + } + + transform.sequence %arg0 { + ^bb0(%arg1: !pdl.operation): + %0 = pdl_match @some in %arg1 + transform.test_mixed_sucess_and_silenceable %0 + } +} diff --git a/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp b/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp index 1332b13..7930f39 100644 --- a/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp +++ b/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp @@ -266,6 +266,15 @@ mlir::test::TestMixedNullAndNonNullResultsOp::applyToOne( return DiagnosedSilenceableFailure::success(); } +DiagnosedSilenceableFailure +mlir::test::TestMixedSuccessAndSilenceableOp::applyToOne( + Operation *target, SmallVectorImpl &results, + transform::TransformState &state) { + if (target->hasAttr("target_me")) + return DiagnosedSilenceableFailure::success(); + return emitDefaultSilenceableFailure(target); +} + namespace { /// Test extension of the Transform dialect. Registers additional ops and /// declares PDL as dependent dialect since the additional ops are using PDL diff --git a/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td b/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td index 08149a2..4c144e7 100644 --- a/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td +++ b/mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.td @@ -196,4 +196,20 @@ def TestMixedNullAndNonNullResultsOp }]; } +def TestMixedSuccessAndSilenceableOp + : Op { + let arguments = (ins PDL_Operation:$target); + let results = (outs); + let assemblyFormat = "$target attr-dict"; + let cppNamespace = "::mlir::test"; + let extraClassDeclaration = [{ + ::mlir::DiagnosedSilenceableFailure applyToOne( + ::mlir::Operation * target, + ::llvm::SmallVectorImpl<::mlir::Operation *> &results, + ::mlir::transform::TransformState &state); + }]; +} + #endif // MLIR_TESTTRANSFORMDIALECTEXTENSION_TD