[Mlir-commits] [mlir] 135e5bf - [mlir][transform] don't wrap a warning into silenceable failure
Alex Zinenko
llvmlistbot at llvm.org
Fri Jun 23 01:21:01 PDT 2023
Author: Alex Zinenko
Date: 2023-06-23T08:20:53Z
New Revision: 135e5bf8940f3d965c44e31eb4c94b8f8388a100
URL: https://github.com/llvm/llvm-project/commit/135e5bf8940f3d965c44e31eb4c94b8f8388a100
DIFF: https://github.com/llvm/llvm-project/commit/135e5bf8940f3d965c44e31eb4c94b8f8388a100.diff
LOG: [mlir][transform] don't wrap a warning into silenceable failure
Wrapping a warning into a silenceable failure will result in the warning
being interpreted as an error, which it is not.
Reviewed By: nicolasvasilache
Differential Revision: https://reviews.llvm.org/D153546
Added:
Modified:
mlir/lib/Dialect/Transform/IR/TransformOps.cpp
mlir/test/Dialect/Transform/ops-invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index 5b71bf895a626..874248993af03 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -646,7 +646,7 @@ static bool implementSameTransformInterface(Type t1, Type t2) {
/// consumption effect annotations. If `alsoVerifyInternal`, checks for
/// annotations being present even if they can be inferred from the body.
static DiagnosedSilenceableFailure
-verifyFunctionLikeConsumeAnnotations(FunctionOpInterface op,
+verifyFunctionLikeConsumeAnnotations(FunctionOpInterface op, bool emitWarnings,
bool alsoVerifyInternal = false) {
auto transformOp = cast<transform::TransformOpInterface>(op.getOperation());
llvm::SmallDenseSet<unsigned> consumedArguments;
@@ -678,12 +678,12 @@ verifyFunctionLikeConsumeAnnotations(FunctionOpInterface op,
<< "argument #" << i
<< " is consumed in the body but is not marked as such";
}
- if (!consumedArguments.contains(i) && isConsumed) {
- Diagnostic warning(op->getLoc(), DiagnosticSeverity::Warning);
- warning << "argument #" << i
- << " is not consumed in the body but is marked as consumed";
- return DiagnosedSilenceableFailure::silenceableFailure(
- std::move(warning));
+ if (emitWarnings && !consumedArguments.contains(i) && isConsumed) {
+ // Cannot use op.emitWarning() here as it would attempt to verify the op
+ // before printing, resulting in infinite recursion.
+ emitWarning(op->getLoc())
+ << "op argument #" << i
+ << " is not consumed in the body but is marked as consumed";
}
}
return DiagnosedSilenceableFailure::success();
@@ -710,11 +710,13 @@ LogicalResult transform::ForeachMatchOp::verifySymbolUses(
return emitError() << "unresolved action symbol " << action;
if (failed(verifyFunctionLikeConsumeAnnotations(matcherSymbol,
+ /*emitWarnings=*/false,
/*alsoVerifyInternal=*/true)
.checkAndReport())) {
return failure();
}
if (failed(verifyFunctionLikeConsumeAnnotations(actionSymbol,
+ /*emitWarnings=*/false,
/*alsoVerifyInternal=*/true)
.checkAndReport())) {
return failure();
@@ -1045,7 +1047,7 @@ transform::IncludeOp::apply(transform::TransformRewriter &rewriter,
}
static DiagnosedSilenceableFailure
-verifyNamedSequenceOp(transform::NamedSequenceOp op);
+verifyNamedSequenceOp(transform::NamedSequenceOp op, bool emitWarnings);
void transform::IncludeOp::getEffects(
SmallVectorImpl<MemoryEffects::EffectInstance> &effects) {
@@ -1075,7 +1077,7 @@ void transform::IncludeOp::getEffects(
if (!callee)
return defaultEffects();
DiagnosedSilenceableFailure earlyVerifierResult =
- verifyNamedSequenceOp(callee);
+ verifyNamedSequenceOp(callee, /*emitWarnings=*/false);
if (!earlyVerifierResult.succeeded()) {
(void)earlyVerifierResult.silence();
return defaultEffects();
@@ -1128,7 +1130,7 @@ transform::IncludeOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
}
return verifyFunctionLikeConsumeAnnotations(
- cast<FunctionOpInterface>(*target),
+ cast<FunctionOpInterface>(*target), /*emitWarnings=*/false,
/*alsoVerifyInternal=*/true)
.checkAndReport();
}
@@ -1414,7 +1416,7 @@ verifyYieldingSingleBlockOp(FunctionOpInterface op, bool allowExternal) {
/// immediately, so it can be used to check for op's well-formedness before the
/// verifier runs, e.g., during trait verification.
static DiagnosedSilenceableFailure
-verifyNamedSequenceOp(transform::NamedSequenceOp op) {
+verifyNamedSequenceOp(transform::NamedSequenceOp op, bool emitWarnings) {
if (Operation *parent = op->getParentWithTrait<OpTrait::SymbolTable>()) {
if (!parent->getAttr(
transform::TransformDialect::kWithNamedSequenceAttrName)) {
@@ -1437,7 +1439,8 @@ verifyNamedSequenceOp(transform::NamedSequenceOp op) {
}
if (op.isExternal() || op.getBody().empty())
- return verifyFunctionLikeConsumeAnnotations(cast<FunctionOpInterface>(*op));
+ return verifyFunctionLikeConsumeAnnotations(cast<FunctionOpInterface>(*op),
+ emitWarnings);
if (op.getBody().front().empty())
return emitSilenceableFailure(op) << "expected a non-empty body block";
@@ -1471,7 +1474,7 @@ verifyNamedSequenceOp(transform::NamedSequenceOp op) {
auto funcOp = cast<FunctionOpInterface>(*op);
DiagnosedSilenceableFailure diag =
- verifyFunctionLikeConsumeAnnotations(funcOp);
+ verifyFunctionLikeConsumeAnnotations(funcOp, emitWarnings);
if (!diag.succeeded())
return diag;
@@ -1481,7 +1484,7 @@ verifyNamedSequenceOp(transform::NamedSequenceOp op) {
LogicalResult transform::NamedSequenceOp::verify() {
// Actual verification happens in a separate function for reusability.
- return verifyNamedSequenceOp(*this).checkAndReport();
+ return verifyNamedSequenceOp(*this, /*emitWarnings=*/true).checkAndReport();
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/Transform/ops-invalid.mlir b/mlir/test/Dialect/Transform/ops-invalid.mlir
index 8aa76140ddcb4..c72af7363f67f 100644
--- a/mlir/test/Dialect/Transform/ops-invalid.mlir
+++ b/mlir/test/Dialect/Transform/ops-invalid.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -split-input-file -verify-diagnostics
+// RUN: mlir-opt %s -split-input-file -verify-diagnostics | FileCheck %s
// expected-error @below {{expects the entry block to have at least one argument}}
transform.sequence failures(propagate) {
@@ -517,15 +517,18 @@ module attributes { transform.with_named_sequence } {
// -----
module attributes { transform.with_named_sequence } {
+ // Note that printing a warning doesn't result in verification failures, so this
+ // also checks for the IR being printed back.
+ // CHECK-LABEL: transform.named_sequence @emit_warning_only
// expected-warning @below {{argument #0 is not consumed in the body but is marked as consume}}
- transform.named_sequence @foo(%op: !transform.any_op {transform.consumed}) {
+ transform.named_sequence @emit_warning_only(%op: !transform.any_op {transform.consumed}) {
transform.test_print_remark_at_operand %op, "message" : !transform.any_op
transform.yield
}
transform.sequence failures(propagate) {
^bb0(%arg0: !transform.any_op):
- transform.include @foo failures(propagate) (%arg0) : (!transform.any_op) -> ()
+ transform.include @emit_warning_only failures(propagate) (%arg0) : (!transform.any_op) -> ()
transform.yield
}
}
More information about the Mlir-commits
mailing list