diff --git a/mlir/docs/Tutorials/Toy/Ch-3.md b/mlir/docs/Tutorials/Toy/Ch-3.md --- a/mlir/docs/Tutorials/Toy/Ch-3.md +++ b/mlir/docs/Tutorials/Toy/Ch-3.md @@ -94,12 +94,13 @@ TransposeOp transposeInputOp = llvm::dyn_cast_or_null(transposeInput.getDefiningOp()); // If the input is defined by another Transpose, bingo! - if (!transposeInputOp) + if (transposeInputOp) { + // Use the rewriter to perform the replacement. + rewriter.replaceOp(op, {transposeInputOp.getOperand()}, {transposeInputOp}); + return matchSuccess(); + } else { return matchFailure(); - - // Use the rewriter to perform the replacement - rewriter.replaceOp(op, {transposeInputOp.getOperand()}, {transposeInputOp}); - return matchSuccess(); + } } }; ``` diff --git a/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp --- a/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch3/mlir/ToyCombine.cpp @@ -44,12 +44,13 @@ llvm::dyn_cast_or_null(transposeInput.getDefiningOp()); // If the input is defined by another Transpose, bingo! - if (!transposeInputOp) + if (transposeInputOp) { + // Use the rewriter to perform the replacement. + rewriter.replaceOp(op, {transposeInputOp.getOperand()}, {transposeInputOp}); + return matchSuccess(); + } else { return matchFailure(); - - // Use the rewriter to perform the replacement. - rewriter.replaceOp(op, {transposeInputOp.getOperand()}); - return matchSuccess(); + } } }; diff --git a/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp --- a/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch4/mlir/ToyCombine.cpp @@ -49,12 +49,13 @@ llvm::dyn_cast_or_null(transposeInput.getDefiningOp()); // If the input is defined by another Transpose, bingo! - if (!transposeInputOp) + if (transposeInputOp) { + // Use the rewriter to perform the replacement. + rewriter.replaceOp(op, {transposeInputOp.getOperand()}, {transposeInputOp}); + return matchSuccess(); + } else { return matchFailure(); - - // Use the rewriter to perform the replacement. - rewriter.replaceOp(op, {transposeInputOp.getOperand()}); - return matchSuccess(); + } } }; diff --git a/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp --- a/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch5/mlir/ToyCombine.cpp @@ -49,12 +49,13 @@ llvm::dyn_cast_or_null(transposeInput.getDefiningOp()); // If the input is defined by another Transpose, bingo! - if (!transposeInputOp) + if (transposeInputOp) { + // Use the rewriter to perform the replacement. + rewriter.replaceOp(op, {transposeInputOp.getOperand()}, {transposeInputOp}); + return matchSuccess(); + } else { return matchFailure(); - - // Use the rewriter to perform the replacement. - rewriter.replaceOp(op, {transposeInputOp.getOperand()}); - return matchSuccess(); + } } }; diff --git a/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp --- a/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch6/mlir/ToyCombine.cpp @@ -49,12 +49,13 @@ llvm::dyn_cast_or_null(transposeInput.getDefiningOp()); // If the input is defined by another Transpose, bingo! - if (!transposeInputOp) + if (transposeInputOp) { + // Use the rewriter to perform the replacement. + rewriter.replaceOp(op, {transposeInputOp.getOperand()}, {transposeInputOp}); + return matchSuccess(); + } else { return matchFailure(); - - // Use the rewriter to perform the replacement. - rewriter.replaceOp(op, {transposeInputOp.getOperand()}); - return matchSuccess(); + } } }; diff --git a/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp b/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp --- a/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp +++ b/mlir/examples/toy/Ch7/mlir/ToyCombine.cpp @@ -67,12 +67,13 @@ llvm::dyn_cast_or_null(transposeInput.getDefiningOp()); // If the input is defined by another Transpose, bingo! - if (!transposeInputOp) + if (transposeInputOp) { + // Use the rewriter to perform the replacement. + rewriter.replaceOp(op, {transposeInputOp.getOperand()}, {transposeInputOp}); + return matchSuccess(); + } else { return matchFailure(); - - // Use the rewriter to perform the replacement. - rewriter.replaceOp(op, {transposeInputOp.getOperand()}); - return matchSuccess(); + } } };